[cfe-dev] Cross compiling with clang (and sysroot support)
Stephen Kelly
steveire at gmail.com
Fri May 17 06:59:47 PDT 2013
Joerg Sonnenberger wrote:
> On Wed, Apr 24, 2013 at 05:08:51PM +0200, Stephen Kelly wrote:
>> Thanks for the information. I don't really know where to find an
>> appropriate assembler to point clang to. I have several gcc based
>> toolchains on this computer, so I guess I should point to the as
>> executable in one of those? How would I specify it?
>>
>> /usr/bin/arm-linux-gnueabi-gcc-4.7 main.c
>>
>> 'Just Works'. /usr/bin/arm-linux-gnueabi-as also exists. Should I use
>> that? All I need is some way to cross compile something for some
>> platform, so if I can invoke clang in a way that it will use that
>> cross-as, that would be great.
>
> clang looks for as and ld helper programs in the paths specified with -B
> followed by $PATH. It is first looking for an executable file named
> "${triple}-as" / "${triple-ld}" and then for "as" / "ld". So in your
> case, it should just work, if you invoke clang with -target
> arm-linux-gnueabi or as arm-linux-gnueabi-clang.
Thanks, your mail made me double-check my triples. In
http://thread.gmane.org/gmane.comp.compilers.clang.devel/28960/focus=29153
I was mixing ...hf with non-hf triples.
So, now I get a little further:
stephen at hal:/tmp$ clang -v -target arm-linux-gnueabihf --sysroot
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf main.c
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on
LLVM 3.2)
Target: arm--linux-gnueabihf
Thread model: posix
"/usr/bin/clang" -cc1 -triple armv4t--linux-gnueabihf -S -disable-free -
disable-llvm-verifier -main-file-name main.c -mrelocation-model static -
mdisable-fp-elim -fmath-errno -mconstructor-aliases -fuse-init-array -
target-abi aapcs-linux -target-cpu cortex-a8 -mfloat-abi hard -target-
feature +vfp3 -target-feature +d16 -target-feature -neon -target-linker-
version 2.23.2 -momit-leaf-frame-pointer -v -resource-dir
/usr/bin/../lib/clang/3.2 -isysroot /home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/usr/local/include -internal-
isystem /usr/bin/../lib/clang/3.2/include -internal-isystem
/usr/include/clang/3.2/include/ -internal-externc-isystem
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/usr/include/x86_64-linux-gnu
-internal-externc-isystem /home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/x86_64-linux-gnu -internal-externc-isystem
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/usr/include -fno-dwarf-
directory-asm -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length
211 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-
option -fcolor-diagnostics -o /tmp/main-ohNsrR.s -x c main.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-pc-
linux-gnu
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/local/include"
ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/clang/3.2/include
End of search list.
"/usr/bin/arm-linux-gnueabihf-as" -mfloat-abi=hard -o /tmp/main-m4RQDy.o
/tmp/main-ohNsrR.s
"/usr/bin/arm-linux-gnueabihf-ld" --sysroot=/home/stephen/rpi/gcc-4.7-
linaro-rpi-gnueabihf -z relro -X --hash-style=gnu --build-id --eh-frame-hdr
-m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o a.out
crt1.o crti.o /home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/lib/gcc/arm-
linux-gnueabihf/4.7.2/crtbegin.o -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2 -L/home/stephen/rpi/gcc-4.7-
linaro-rpi-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-
linux-gnueabihf/lib/../lib32 -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-
gnueabihf/lib -L/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/lib/gcc/arm-
linux-gnueabihf/4.7.2/../../.. -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib /tmp/main-m4RQDy.o -lgcc --as-needed -lgcc_s --no-as-needed -
lc -lgcc --as-needed -lgcc_s --no-as-needed /home/stephen/rpi/gcc-4.7-
linaro-rpi-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2/crtend.o crtn.o
/usr/bin/arm-linux-gnueabihf-ld: cannot find crt1.o: No such file or
directory
/usr/bin/arm-linux-gnueabihf-ld: cannot find crti.o: No such file or
directory
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
And if I specify the sysroot *and* the -B option, I can make it succeed:
stephen at hal:/tmp$ clang -v -target arm-linux-gnueabihf --sysroot
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf -B /usr/arm-linux-
gnueabihf/lib/ main.c
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on
LLVM 3.2)
Target: arm--linux-gnueabihf
Thread model: posix
"/usr/bin/clang" -cc1 -triple armv4t--linux-gnueabihf -S -disable-free -
disable-llvm-verifier -main-file-name main.c -mrelocation-model static -
mdisable-fp-elim -fmath-errno -mconstructor-aliases -fuse-init-array -
target-abi aapcs-linux -target-cpu cortex-a8 -mfloat-abi hard -target-
feature +vfp3 -target-feature +d16 -target-feature -neon -target-linker-
version 2.23.2 -momit-leaf-frame-pointer -v -resource-dir
/usr/bin/../lib/clang/3.2 -isysroot /home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/usr/local/include -internal-
isystem /usr/bin/../lib/clang/3.2/include -internal-isystem
/usr/include/clang/3.2/include/ -internal-externc-isystem
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/usr/include/x86_64-linux-gnu
-internal-externc-isystem /home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/x86_64-linux-gnu -internal-externc-isystem
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/usr/include -fno-dwarf-
directory-asm -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length
211 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-
option -fcolor-diagnostics -o /tmp/main-x95tmT.s -x c main.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-pc-
linux-gnu
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/local/include"
ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/x86_64-linux-gnu"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/clang/3.2/include
End of search list.
"/usr/bin/arm-linux-gnueabihf-as" -mfloat-abi=hard -o /tmp/main-duFLkY.o
/tmp/main-x95tmT.s
"/usr/bin/arm-linux-gnueabihf-ld" --sysroot=/home/stephen/rpi/gcc-4.7-
linaro-rpi-gnueabihf -z relro -X --hash-style=gnu --build-id --eh-frame-hdr
-m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o a.out
/usr/arm-linux-gnueabihf/lib/crt1.o /usr/arm-linux-gnueabihf/lib/crti.o
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/lib/gcc/arm-linux-
gnueabihf/4.7.2/crtbegin.o -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2 -L/home/stephen/rpi/gcc-4.7-
linaro-rpi-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-
linux-gnueabihf/lib/../lib32 -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-
gnueabihf/lib -L/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/lib/gcc/arm-
linux-gnueabihf/4.7.2/../../.. -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib /tmp/main-duFLkY.o -lgcc --as-needed -lgcc_s --no-as-needed -
lc -lgcc --as-needed -lgcc_s --no-as-needed /home/stephen/rpi/gcc-4.7-
linaro-rpi-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.7.2/crtend.o /usr/arm-
linux-gnueabihf/lib/crtn.o
With gcc it works with just the sysroot specified:
stephen at hal:/tmp$ /usr/bin/arm-linux-gnueabihf-gcc-4.7 -v --sysroot
/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf main.c
Using built-in specs.
COLLECT_GCC=/usr/bin/arm-linux-gnueabihf-gcc-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --
enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-
suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --with-gxx-include-
dir=/usr/arm-linux-gnueabihf/include/c++/4.7.3 --libdir=/usr/lib --enable-
nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-
libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --enable-
plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-
backend=ppl --disable-cloog-version-check --disable-ppl-version-check --
enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-
arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --
disable-werror --enable-checking=release --build=x86_64-linux-gnu --
host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-
linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
COLLECT_GCC_OPTIONS='-v' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-
d16' '-mthumb' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/cc1 -quiet -v -imultilib . -
imultiarch arm-linux-gnueabihf -isysroot /home/stephen/rpi/gcc-4.7-linaro-
rpi-gnueabihf main.c -quiet -dumpbase main.c -march=armv7-a -mfloat-abi=hard
-mfpu=vfpv3-d16 -mthumb -mtls-dialect=gnu -auxbase main -version -fstack-
protector -o /tmp/cczGygs4.s
GNU C (Ubuntu/Linaro 4.7.3-1ubuntu1) version 4.7.3 (arm-linux-gnueabihf)
compiled by GNU C version 4.7.3, GMP version 5.0.5, MPFR version
3.1.1-p2, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/include
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/include-fixed
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-
gnueabihf/include
End of search list.
GNU C (Ubuntu/Linaro 4.7.3-1ubuntu1) version 4.7.3 (arm-linux-gnueabihf)
compiled by GNU C version 4.7.3, GMP version 5.0.5, MPFR version
3.1.1-p2, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e45f40a8311fe21566e2c30ee2f2b3a6
COLLECT_GCC_OPTIONS='-v' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-
d16' '-mthumb' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-
gnueabihf/bin/as -v -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5
-o /tmp/cclqE2KN.o /tmp/cczGygs4.s
GNU assembler version 2.23.2 (arm-linux-gnueabihf) using BFD version (GNU
Binutils for Ubuntu) 2.23.2
COMPILER_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/:/usr/lib/gcc-
cross/arm-linux-gnueabihf/4.7/:/usr/lib/gcc-cross/arm-linux-
gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/:/usr/lib/gcc-
cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-
gnueabihf/4.7/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/:/usr/lib/gcc-
cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-
gnueabihf/lib/../lib/:/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib/../lib/:/usr/lib/gcc-cross/arm-linux-
gnueabihf/4.7/../../../../arm-linux-
gnueabihf/lib/:/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/lib/
COLLECT_GCC_OPTIONS='-v' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-
d16' '-mthumb' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/collect2 --
sysroot=/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf --build-id --eh-
frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=gnu --as-
needed -m armelf_linux_eabi -z relro /usr/lib/gcc-cross/arm-linux-
gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib/../lib/crt1.o
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-
gnueabihf/lib/../lib/crti.o /usr/lib/gcc-cross/arm-linux-
gnueabihf/4.7/crtbegin.o -L/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7 -
L/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-
gnueabihf/lib/../lib -L/home/stephen/rpi/gcc-4.7-linaro-rpi-
gnueabihf/lib/../lib -L/usr/lib/gcc-cross/arm-linux-
gnueabihf/4.7/../../../../arm-linux-gnueabihf/lib -
L/home/stephen/rpi/gcc-4.7-linaro-rpi-gnueabihf/lib /tmp/cclqE2KN.o -lgcc --
as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-
needed /usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/crtend.o /usr/lib/gcc-
cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-
gnueabihf/lib/../lib/crtn.o
Should clang be looking in more places for the crtX.o files?
Thanks,
Steve.
More information about the cfe-dev
mailing list