Ivan Medoedov via llvm-dev
2019-Apr-10 20:28 UTC
[llvm-dev] Cross compiling an empty program results in a segfault
Hello, I'm trying to cross compile an empty program on macOS for Linux: cat test.c int main() { int a = 2+3; return 0; } clang -o -c -target x86_64-linux-gnu test.c If I copy the resulting test.o to the Linux machine and run clang test.o, it works fine. However if I try to link it on macOS, I get a segfault when I launch ./a.out ld.lld --entry main test.o [copy a.out to Linux] ./a.out segmentation fault 0x00000000001 in ?? () Would really appreciate your help here! Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190410/d4acb188/attachment.html>
Eli Friedman via llvm-dev
2019-Apr-12 19:31 UTC
[llvm-dev] [EXT] Cross compiling an empty program results in a segfault
“--entry main” is not going to do what you want; the entry point for a Linux program is not equivalent to the C “main”. http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html has a description of how a C program normally starts on Linux. Generally, to build a C program, you don’t want to invoke the linker directly; instead, use clang to invoke the linker correctly. This will pass the appropriate flags and link against the appropriate libraries. When you’re cross compiling, to make this work, you have to actually have the appropriate libraries, so you’ll have to build or download them separately. Then you tell clang the path to those libraries using –sysroot. https://clang.llvm.org/docs/CrossCompilation.html has a general description of various issues with cross-compiling. -Eli From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Ivan Medoedov via llvm-dev Sent: Wednesday, April 10, 2019 1:28 PM To: llvm-dev at lists.llvm.org Subject: [EXT] [llvm-dev] Cross compiling an empty program results in a segfault Hello, I'm trying to cross compile an empty program on macOS for Linux: cat test.c int main() { int a = 2+3; return 0; } clang -o -c -target x86_64-linux-gnu test.c If I copy the resulting test.o to the Linux machine and run clang test.o, it works fine. However if I try to link it on macOS, I get a segfault when I launch ./a.out ld.lld --entry main test.o [copy a.out to Linux] ./a.out segmentation fault 0x00000000001 in ?? () Would really appreciate your help here! Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190412/576de9eb/attachment.html>
Ivan Medoedov via llvm-dev
2019-May-03 23:43 UTC
[llvm-dev] Cross compiling an empty program results in a segfault
Sorry for the late reply. Thanks, Eli. That was really helpful. On Fri, Apr 12, 2019 at 9:31 PM Eli Friedman <efriedma at quicinc.com> wrote:> “--entry main” is not going to do what you want; the entry point for a > Linux program is not equivalent to the C “main”. > http://dbp-consulting.com/tutorials/debugging/linuxProgramStartup.html > has a description of how a C program normally starts on Linux. > > > > Generally, to build a C program, you don’t want to invoke the linker > directly; instead, use clang to invoke the linker correctly. This will > pass the appropriate flags and link against the appropriate libraries. > When you’re cross compiling, to make this work, you have to actually have > the appropriate libraries, so you’ll have to build or download them > separately. Then you tell clang the path to those libraries using > –sysroot. https://clang.llvm.org/docs/CrossCompilation.html has a > general description of various issues with cross-compiling. > > > > -Eli > > > > *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> *On Behalf Of *Ivan > Medoedov via llvm-dev > *Sent:* Wednesday, April 10, 2019 1:28 PM > *To:* llvm-dev at lists.llvm.org > *Subject:* [EXT] [llvm-dev] Cross compiling an empty program results in a > segfault > > > > Hello, > > > > I'm trying to cross compile an empty program on macOS for Linux: > > > > cat test.c > > > > int main() { > > int a = 2+3; > > return 0; > > } > > > > clang -o -c -target x86_64-linux-gnu test.c > > > > If I copy the resulting test.o to the Linux machine and run clang test.o, > it works fine. > > > > However if I try to link it on macOS, I get a segfault when I launch > ./a.out > > > > ld.lld --entry main test.o > > > > [copy a.out to Linux] > > > > ./a.out > > segmentation fault 0x00000000001 in ?? () > > > > Would really appreciate your help here! > > > > Thanks >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190504/7c2117cf/attachment.html>
Reasonably Related Threads
- Cross compiling an empty program results in a segfault
- Locate Patients who have multiple high blood pressure readings
- ld.lld fails with "undefined symbol: _fopen" on macOS, while working as expected on Linux
- Finding the two most recent dates
- plotting box plots on same x