Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Clang cross compile
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on ARM
View previous topic :: View next topic  
Author Message
[n00b@localhost]
Apprentice
Apprentice


Joined: 30 Aug 2004
Posts: 266
Location: London, UK

PostPosted: Sat Nov 19, 2016 6:07 pm    Post subject: Clang cross compile Reply with quote

I have crossdev installed and have used it to create GCC-based toolchains for arm-hardfloat-linux-gnueabi and aarch64-unknown-linux-gnu (RPi 2B and RPi 3, respectively). After reading about LLVM 3.9 with LLVM_TARGETS I thought I'd give clang a go at compiling code for my RPis.

Documentation on cross compiling with clang is sparse, but I managed to work out that to get it to cross-compile you need to run it passing the -target and -isysroot options, like so:
Code:
clang -target arm-hardfloat-linux-gnueabi -isysroot /usr/lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0 hello.c -o hello-clang


However, running this I get a linker error:
Code:
/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib/crt1.o: file not recognized: File format not recognized
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)


The full output (with -v) is as follows:
Code:
clang version 3.9.0 (tags/RELEASE_390/final)
Target: arm-hardfloat-linux-gnueabi
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0
Found candidate GCC installation: /usr/lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0
Selected GCC installation: /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0
Candidate multilib: .;@m32
Selected multilib: .;@m32
 "/usr/bin/clang-3.9" -cc1 -triple armv4t-hardfloat-linux-gnueabi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu arm7tdmi -target-feature +soft-float-abi -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi soft -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/3.9.0 -isysroot /usr/lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/ -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.9.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/gary/git -ferror-limit 19 -fmessage-length 88 -fallow-half-arguments-and-returns -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello-0ea72c.o -x c hello.c
clang -cc1 version 3.9.0 based upon LLVM 3.9.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/clang/3.9.0/include
 /usr/include
End of search list.
 "/usr/bin/arm-hardfloat-linux-gnueabi-ld" -X --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux.so.3 -o hello-clang /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib/crt1.o /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib/crti.o /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/crtbegin.o -L/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0 -L/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../arm-hardfloat-linux-gnueabi/lib/../lib -L/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib -L/usr/bin/../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../arm-hardfloat-linux-gnueabi/lib -L/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/hello-0ea72c.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/crtend.o /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib/crtn.o
/usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib/crt1.o: file not recognized: File format not recognized
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)


The error is correct, in that /usr/bin/../lib/gcc/arm-hardfloat-linux-gnueabi/6.2.0/../../../../lib/crt1.o (which resolves to /usr/lib/crt1.o) is compiled for x86_64, not ARM.

Has anyone got a successful cross-compile with clang? How do you get it to link the proper runtime libraries?

Code:
emerge -pv1 --nodeps llvm

These are the packages that would be merged, in order:

[ebuild   R   ~] sys-devel/llvm-3.9.0-r1:0/3.9.0::gentoo  USE="clang gold libffi ncurses python sanitize static-analyzer xml -debug -default-compiler-rt -default-libcxx -doc -libedit (-lldb) -multitarget -ocaml {-test}" ABI_X86="32 (64) (-x32)" LLVM_TARGETS="AArch64 ARM NVPTX (X86) -AMDGPU -BPF -Hexagon -MSP430 -Mips -PowerPC -Sparc -SystemZ -XCore" PYTHON_TARGETS="python2_7" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB
Back to top
View user's profile Send private message
iluxave
n00b
n00b


Joined: 17 Aug 2019
Posts: 1

PostPosted: Sat Aug 17, 2019 12:58 am    Post subject: Reply with quote

Well, I also have same problem.
sys-devel/clang-8.0.0

I'm trying to build arm or armbe (set up armeb-linux-gnueabi and arm-linux-gnueabi).

Error is pretty much the same:

Code:
$ clang --target=arm-linux-gnueabi -v test.c
clang version 8.0.0 (tags/RELEASE_800/final)
Target: arm-unknown-linux-gnueabi
Thread model: posix
InstalledDir: /usr/lib/llvm/8/bin
Selected GCC installation: /usr/lib/gcc/arm-linux-gnueabi/8.3.0
Candidate multilib: .;@m32
Selected multilib: .;@m32
Found CUDA installation: /opt/cuda, version 10.0
 "/usr/lib64/llvm/8/bin/clang-8" -cc1 -triple armv4t-unknown-linux-gnueabi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu arm7tdmi -target-feature +soft-float-abi -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi soft -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib64/llvm/8/bin/../../../../lib/clang/8.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/llvm/8/bin/../../../../lib/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length 158 -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-22f0eb.o -x c test.c
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib64/llvm/8/bin/../../../../lib/clang/8.0.0/include
 /usr/include
End of search list.
 "/usr/bin/arm-linux-gnueabi-ld" -EL -X --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux.so.3 -o a.out /usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../lib/crt1.o /usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../lib/crti.o /usr/lib/gcc/arm-linux-gnueabi/8.3.0/crtbegin.o -L/usr/lib/gcc/arm-linux-gnueabi/8.3.0 -L/usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../arm-linux-gnueabi/lib/../lib -L/usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../arm-linux-gnueabi/lib -L/usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../.. -L/lib -L/usr/lib /tmp/test-22f0eb.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/arm-linux-gnueabi/8.3.0/crtend.o /usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../lib/crtn.o
/usr/bin/arm-linux-gnueabi-ld: warning: library search path "/lib/../lib" is unsafe for cross-compilation
/usr/bin/arm-linux-gnueabi-ld: warning: library search path "/lib" is unsafe for cross-compilation
/usr/lib/gcc/arm-linux-gnueabi/8.3.0/../../../../lib/crt1.o: file not recognized: file format not recognized
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on ARM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum