via llvm-dev
2016-Nov-02 07:49 UTC
[llvm-dev] Cross-compiling for ARM on x86 with llvm/Clang
Hello list I have some problems when using x86 cross-compile the arm progress. First I know a way to get aarch64 binary in x86 with llvm/clang. There need two things prepared for cross-compile. 1. GUN ARM toolchain → apt-get install gcc-arm-linux-gnueabi 2. Clang/llvm compile → http://clang.llvm.org/get_started.html clang -emit-llvm -target aarch64 helloworld.c -I /usr/aarch64-linux-gnu/include -c (can get helloworld.bc) llc helloworld.bc -o helloworld.s aarch64-linux-gnu-gcc helloworld.s -o helloworld>From the cmd above, I can get the aarch64 binary which is function well in aarch64 machine.But, Is there other way that I can get aarch64 without gcc. When I try to use below: clang -v -target arm-linux-gnueabi --sysroot=/usr/arm-linux-gnueabi/ helloworld.c -o hello I get: Obfuscator-LLVM clang version 3.6.1 (tags/RELEASE_361/final) (based on Obfuscator-LLVM 3.6.1) Target: arm--linux-gnueabi Thread model: posix "/usr/local/bin/clang-3.6" -cc1 -triple armv4t--linux-gnueabi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name arm.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu arm7tdmi -target-feature +soft-float-abi -target-abi aapcs-linux -mfloat-abi soft -v -dwarf-column-info -resource-dir /usr/local/bin/../lib/clang/3.6.1 -isysroot /usr/arm-linux-gnueabi/ -internal-isystem /usr/arm-linux-gnueabi//usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.6.1/include -internal-externc-isystem /usr/arm-linux-gnueabi//include -internal-externc-isystem /usr/arm-linux-gnueabi//usr/include -fdebug-compilation-dir /home/zyj/Desktop -ferror-limit 19 -fmessage-length 80 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/helloworld-6b36a6.o -x c helloworld.c clang -cc1 version 3.6.1 based upon Obfuscator-LLVM 3.6.1 default target i386-pc-linux-gnu ignoring nonexistent directory "/usr/arm-linux-gnueabi//usr/local/include" ignoring nonexistent directory "/usr/arm-linux-gnueabi//usr/include" #include "..." search starts here: #include <...> search starts here: /usr/local/bin/../lib/clang/3.6.1/include /usr/arm-linux-gnueabi//include End of search list. "/usr/local/bin/ld" --sysroot=/usr/arm-linux-gnueabi/ -z relro -X --hash-style=gnu --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux.so.3 -o hello /usr/arm-linux-gnueabi//lib/../lib/crt1.o /usr/arm-linux-gnueabi//lib/../lib/crti.o crtbegin.o -L/usr/arm-linux-gnueabi//lib/../lib -L/usr/arm-linux-gnueabi//lib /tmp/helloworld-6b36a6.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o /usr/arm-linux-gnueabi//lib/../lib/crtn.o /usr/local/bin/ld: unrecognised emulation mode: armelf_linux_eabi Supported emulations: elf_i386 i386linux elf32_x86_64 elf_x86_64 elf_l1om elf_k1om i386pep i386pe clang-3.6: error: linker command failed with exit code 1 (use -v to see invocation) This seems that linker is wrong, so I change the ld point to /usr/arm-linux-gnueabi/bin/ld (using: ln -s /usr/arm-linux-gnueabi/bin/ld ld) But I get anther question Obfuscator-LLVM clang version 3.6.1 (tags/RELEASE_361/final) (based on Obfuscator-LLVM 3.6.1) Target: arm--linux-gnueabi Thread model: posix "/usr/local/bin/clang-3.6" -cc1 -triple armv4t--linux-gnueabi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name arm.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu arm7tdmi -target-feature +soft-float-abi -target-abi aapcs-linux -mfloat-abi soft -v -dwarf-column-info -resource-dir /usr/local/bin/../lib/clang/3.6.1 -isysroot /usr/arm-linux-gnueabi/ -internal-isystem /usr/arm-linux-gnueabi//usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.6.1/include -internal-externc-isystem /usr/arm-linux-gnueabi//include -internal-externc-isystem /usr/arm-linux-gnueabi//usr/include -fdebug-compilation-dir /home/zyj/Desktop -ferror-limit 19 -fmessage-length 80 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/helloworld-fa5b7f.o -x c helloworld.c clang -cc1 version 3.6.1 based upon Obfuscator-LLVM 3.6.1 default target i386-pc-linux-gnu ignoring nonexistent directory "/usr/arm-linux-gnueabi//usr/local/include" ignoring nonexistent directory "/usr/arm-linux-gnueabi//usr/include" #include "..." search starts here: #include <...> search starts here: /usr/local/bin/../lib/clang/3.6.1/include /usr/arm-linux-gnueabi//include End of search list. "/usr/local/bin/ld" --sysroot=/usr/arm-linux-gnueabi/ -z relro -X --hash-style=gnu --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux.so.3 -o hello /usr/arm-linux-gnueabi//lib/../lib/crt1.o /usr/arm-linux-gnueabi//lib/../lib/crti.o crtbegin.o -L/usr/arm-linux-gnueabi//lib/../lib -L/usr/arm-linux-gnueabi//lib /tmp/helloworld-fa5b7f.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o /usr/arm-linux-gnueabi//lib/../lib/crtn.o /usr/local/bin/ld: cannot find crtbegin.o: No such file or directory /usr/local/bin/ld: cannot find -lgcc /usr/local/bin/ld: cannot find -lgcc_s /usr/local/bin/ld: cannot find /usr/arm-linux-gnueabi/lib/libc.so.6 inside /usr/arm-linux-gnueabi/ /usr/local/bin/ld: cannot find /usr/arm-linux-gnueabi/lib/libc_nonshared.a inside /usr/arm-linux-gnueabi/ /usr/local/bin/ld: cannot find /usr/arm-linux-gnueabi/lib/ld-linux.so.3 inside /usr/arm-linux-gnueabi/ clang-3.6: error: linker command failed with exit code 1 (use -v to see invocation)>From above message I am confused about the:/usr/local/bin/ld: cannot find crtbegin.o: No such file or directory /usr/local/bin/ld: cannot find -lgcc /usr/local/bin/ld: cannot find -lgcc_s /usr/local/bin/ld: cannot find /usr/arm-linux-gnueabi/lib/libc.so.6 inside /usr/arm-linux-gnueabi/ /usr/local/bin/ld: cannot find /usr/arm-linux-gnueabi/lib/libc_nonshared.a inside /usr/arm-linux-gnueabi/ /usr/local/bin/ld: cannot find /usr/arm-linux-gnueabi/lib/ld-linux.so.3 inside /usr/arm-linux-gnueabi/ While all these lib is at the right location, why error says ld cannot find them. If you need more imformation from me, please let me know. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161102/00eebd75/attachment.html>