Journeyer J. Joh
2012-Jun-28 12:08 UTC
[LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
Hello list I think I really finally found a way to crossbuild a binary for ARM using Clang/llvm. This message would be a documentation for someone who may concern for the same issue with me. - Target : TOSHIBA AC100 / Ubuntu 12.04 (https://wiki.ubuntu.com/ARM/** TEGRA/AC100 <https://wiki.ubuntu.com/ARM/TEGRA/AC100>) - Host : i386 Desktop PC / Ubuntu 12.04 - Toolchain on host : sudo apt-get install gcc-arm-linux-gnueabi - Clang/llvm compile : http://clang.llvm.org/get_started.html - Command string for crossbuild : ./clang -v --save-temps -ccc-host-triple arm-linux-gnueabi --sysroot=/usr/arm-linux-gnueabi -gcc-toolchain /usr/ -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 hello.c -o hello During this testing I found something like a bug in Clang or llvm. Please note the Command string for crossbuild above. Problem occurs if "-ccc-host-triple" gets "arm-linux-gnueabihf" instead of "arm-linux-gnueabi". Problem is that ld is called with a incomplete or no path for libgcc, crtbegin.o and crtend.o "-gcc-toolchain" options doesn't seem to work. Workaroud for this problem is using a command string like below. ./clang -v --save-temps -ccc-host-triple arm-linux-gnueabihf -mfloat-abi=hard -mfpu=vfpv3-d16 --sysroot=/usr/arm-linux-gnueabihf -gcc-toolchain /usr/ -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 -L/usr/lib/gcc/arm-linux-gnueabihf/4.6 -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib/../lib -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib -L/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf -L/usr/lib -L/lib hello.c -o hello Note all library path have to be specified. And more importantly crtend.o and crtbegin.o have to be symbolic-linked!! I tested with a toolchain for arm-linux-gnueabihf for this test.(sudo apt-get install gcc-arm-linux-gnueabihf) Thank you everyone who answered for my questions. Journeyer J. Joh (ps. For Sid, The final binary "hello" prints "not a dynamic executable" when asked with "ldd". But it runs very well. ^^) 2012/6/27 Sid Manning <sidneym at codeaurora.org>> On 06/27/12 07:24, Journeyer J. Joh wrote: > >> Hello, >> >> With your kind concern and help, I now can make a binary for ARM target. >> >> ./clang -v --save-temps -ccc-host-triple arm-none-linux-gnueabi >> --sysroot=/home/hum/Documents/**Projects/arm_toolchain/arm-** >> 2010.09/arm-none-linux-**gnueabi/libc >> -gcc-toolchain /home/hum/Documents/Projects/**arm_toolchain/arm-2010.09 >> hello.c -o hello >> >> The build command is shown above. >> >> After that, I prepared an ARM laptop, AC100 - TOSHIBA. >> I installed Ubuntu 12.04 in the way guided from the link below. >> >> https://wiki.ubuntu.com/ARM/**TEGRA/AC100<https://wiki.ubuntu.com/ARM/TEGRA/AC100> >> >> So I moved the final binary from host PC to AC100 and executed. >> But the binary DIDN'T RUN. >> >> $./hello >> >> returns an error message below. >> >> bash: ./hello: No such file hello >> >> > You could try readelf -l hello and check the INTERP header. When I've > seen this message usually PT_INTERP points to something that the kernel > can't find. > > > > I need to understand why it doesn't run on ARM laptop. >> >> I compiled another sample program hi.c on the ARM laptop and compared >> both - the one cross compiled "hello" and the other self host compiled >> "hi". >> >> Output message of utility "file" is almost the same except Linux >> version, one is 2.6.16 and the other is 2.6.31. But the output of "ldd" >> shows something meaningful. >> > > This is curious based on the output from ldd below, does file report each > as, "dynamically linked". > > > >> ldd hi >> libc.so.6 => /lib/arm-linux-gnueabihf/libc.**so.6 (0xb6ecf000) >> /lib/ld-linux-armhf.so.3 (0xb6fc3000) >> >> ldd hello >> not a dynamic executable >> >> >>-- ---------------------------------------- Journeyer J. Joh o o s a p r o g r a m m e r a t g m a i l d o t c o m ---------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120628/d0862dc2/attachment.html>
tsukishiro
2012-Aug-29 05:18 UTC
[LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
Hi Journeyer First, thank you so much for your updates on your experiments. I am currently following your steps but have found myself stuck with the following error: /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: this linker was not configured to use sysroots clang: error: linker command failed with exit code 1 (use -v to see invocation) I used the command string you wrote : ./clang -v --save-temps -ccc-host-triple arm-linux-gnueabi --sysroot=/usr/arm-linux-gnueabi -gcc-toolchain /usr/ -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 hello.c -o hello Can you help me identify the problem? I'm also really interested in cross compiling ARM and x86. For the complete logs of the above command, please refer below : clang version 3.1 (branches/release_31) Target: arm--linux-gnueabi Thread model: posix "/home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/clang" -cc1 -triple armv4t--linux-gnueabi -E -disable-free -main-file-name hello.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft -target-feature +soft-float-abi -target-linker-version 2.20.1 -momit-leaf-frame-pointer -v -resource-dir /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1 -isysroot /usr/arm-linux-gnueabi -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/arm-linux-gnueabi/usr/local/include -internal-isystem /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1/include -internal-externc-isystem /usr/arm-linux-gnueabi/include -internal-externc-isystem /usr/arm-linux-gnueabi/usr/include -fno-dwarf-directory-asm -fdebug-compilation-dir /home/jedd10-04/TOOC/clang-samples -ferror-limit 19 -fmessage-length 132 -mstackrealign -fno-signed-char -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o hello.i -x c hello.c clang -cc1 version 3.1 based upon LLVM 3.1 default target x86_64-unknown-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: /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1/include /usr/arm-linux-gnueabi/include End of search list. "/home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/clang" -cc1 -triple armv4t--linux-gnueabi -S -disable-free -main-file-name hello.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft -target-feature +soft-float-abi -target-linker-version 2.20.1 -momit-leaf-frame-pointer -v -resource-dir /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1 -fno-dwarf-directory-asm -fdebug-compilation-dir /home/jedd10-04/TOOC/clang-samples -ferror-limit 19 -fmessage-length 132 -mstackrealign -fno-signed-char -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o hello.s -x cpp-output hello.i clang -cc1 version 3.1 based upon LLVM 3.1 default target x86_64-unknown-linux-gnu #include "..." search starts here: End of search list. "/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/as" -o hello.o hello.s "/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld" --sysroot=/usr/arm-linux-gnueabi -z relro -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux.so.3 -o hello /usr/arm-linux-gnueabi/lib/crt1.o /usr/arm-linux-gnueabi/lib/crti.o /usr/lib/gcc/arm-linux-gnueabi/4.6/crtbegin.o -L/usr/lib/gcc/arm-linux-gnueabi/4.6 -L/usr/arm-linux-gnueabi/lib -dynamic-linker /lib/ld-linux-armhf.so.3 hello.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/arm-linux-gnueabi/4.6/crtend.o /usr/arm-linux-gnueabi/lib/crtn.o /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: this linker was not configured to use sysroots clang: error: linker command failed with exit code 1 (use -v to see invocation) -- View this message in context: http://llvm.1065342.n5.nabble.com/Is-cross-compiling-for-ARM-on-x86-with-llvm-Clang-possible-tp46279p48471.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Journeyer J. Joh
2012-Aug-29 08:13 UTC
[LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
Hello Tsukishiro First of all, I am in a learning stage of LLVM and Clang. This means I am not an expert! ^^; The final trial I succeeded was under the environment below. - Target : TOSHIBA AC100 / Ubuntu 12.04 (https://wiki.ubuntu.com/ARM/** TEGRA/AC100 <https://wiki.ubuntu.com/ARM/TEGRA/AC100>) - Host : i386 Desktop PC / Ubuntu 12.04 - Toolchain on host : sudo apt-get install gcc-arm-linux-gnueabi - Clang/llvm compile : http://clang.llvm.org/get_started.html I wonder your environment. - Target : - Host : - Toolchain on host : How did you get your toolchain? - Clang/llvm compile : How did you compile Clang/llvm? I tested successfully with a command below. - Command string for crossbuild : ./clang -v --save-temps -ccc-host-triple arm-linux-gnueabi --sysroot=/usr/arm-linux-gnueabi -gcc-toolchain /usr/ -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 hello.c -o hello Important options are shown below. -ccc-host-triple : arm-linux-gnueabi --sysroot : /usr/arm-linux-gnueabi -gcc-toolchain : /usr/ -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 I want to know your command string not mine. Could you write it to me? I am afraid I could fail to help you.... I am not an expert.. Please consider this. Best regards Journeyer 2012/8/29 tsukishiro <tsukishiro88 at gmail.com>:> Hi Journeyer > > First, thank you so much for your updates on your experiments. > I am currently following your steps but have found myself stuck with the > following error: > > /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: > this linker was not configured to use sysroots > clang: error: linker command failed with exit code 1 (use -v to see > invocation) > > I used the command string you wrote : > ./clang -v --save-temps -ccc-host-triple arm-linux-gnueabi > --sysroot=/usr/arm-linux-gnueabi -gcc-toolchain /usr/ > -Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3 hello.c -o hello > > Can you help me identify the problem? > I'm also really interested in cross compiling ARM and x86. > > For the complete logs of the above command, please refer below : > > clang version 3.1 (branches/release_31) > Target: arm--linux-gnueabi > Thread model: posix > "/home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/clang" > -cc1 -triple armv4t--linux-gnueabi -E -disable-free -main-file-name hello.c > -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases > -target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft > -target-feature +soft-float-abi -target-linker-version 2.20.1 > -momit-leaf-frame-pointer -v -resource-dir > /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1 > -isysroot /usr/arm-linux-gnueabi -fmodule-cache-path > /var/tmp/clang-module-cache -internal-isystem > /usr/arm-linux-gnueabi/usr/local/include -internal-isystem > /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1/include > -internal-externc-isystem /usr/arm-linux-gnueabi/include > -internal-externc-isystem /usr/arm-linux-gnueabi/usr/include > -fno-dwarf-directory-asm -fdebug-compilation-dir > /home/jedd10-04/TOOC/clang-samples -ferror-limit 19 -fmessage-length 132 > -mstackrealign -fno-signed-char -fgnu-runtime -fobjc-runtime-has-arc > -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option > -fcolor-diagnostics -o hello.i -x c hello.c > clang -cc1 version 3.1 based upon LLVM 3.1 default target > x86_64-unknown-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: > > /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1/include > /usr/arm-linux-gnueabi/include > End of search list. > "/home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/clang" > -cc1 -triple armv4t--linux-gnueabi -S -disable-free -main-file-name hello.c > -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases > -target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft > -target-feature +soft-float-abi -target-linker-version 2.20.1 > -momit-leaf-frame-pointer -v -resource-dir > /home/jedd10-04/TOOC/LLVM-3.1/llvm-3.1.src/build/Debug+Asserts/bin/../lib/clang/3.1 > -fno-dwarf-directory-asm -fdebug-compilation-dir > /home/jedd10-04/TOOC/clang-samples -ferror-limit 19 -fmessage-length 132 > -mstackrealign -fno-signed-char -fgnu-runtime -fobjc-runtime-has-arc > -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option > -fcolor-diagnostics -o hello.s -x cpp-output hello.i > clang -cc1 version 3.1 based upon LLVM 3.1 default target > x86_64-unknown-linux-gnu > #include "..." search starts here: > End of search list. > "/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/as" > -o hello.o hello.s > "/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld" > --sysroot=/usr/arm-linux-gnueabi -z relro -X --hash-style=both --build-id > --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux.so.3 -o > hello /usr/arm-linux-gnueabi/lib/crt1.o /usr/arm-linux-gnueabi/lib/crti.o > /usr/lib/gcc/arm-linux-gnueabi/4.6/crtbegin.o > -L/usr/lib/gcc/arm-linux-gnueabi/4.6 -L/usr/arm-linux-gnueabi/lib > -dynamic-linker /lib/ld-linux-armhf.so.3 hello.o -lgcc --as-needed -lgcc_s > --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed > /usr/lib/gcc/arm-linux-gnueabi/4.6/crtend.o > /usr/arm-linux-gnueabi/lib/crtn.o > /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: > this linker was not configured to use sysroots > clang: error: linker command failed with exit code 1 (use -v to see > invocation) > > > > -- > View this message in context: http://llvm.1065342.n5.nabble.com/Is-cross-compiling-for-ARM-on-x86-with-llvm-Clang-possible-tp46279p48471.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- ---------------------------------------- Journeyer J. Joh o o s a p r o g r a m m e r a t g m a i l d o t c o m ----------------------------------------
Anton Korobeynikov
2012-Aug-29 08:55 UTC
[LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
> /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: > this linker was not configured to use sysroots > clang: error: linker command failed with exit code 1 (use -v to see > invocation)Well, the error is pretty clear - your linker does not support sysroot. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Possibly Parallel Threads
- [LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
- [LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
- [LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
- [LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?
- [LLVMdev] Is cross-compiling for ARM on x86 with llvm/Clang possible?