C Cross compile helloworld on a amd64 architecture for the RaspberryPI4 ie arm64.

What i tried :

Code:
export SYSROOT="/home/x/Dirs/arm64/sysroot"
curl   -LSs https://download.freebsd.org/ftp/releases/arm64/13.0-RELEASE/base.txz | tar Jxf - --include './usr/include/*' --include './usr/lib/*' --include './lib/*' -C ${SYSROOT}

Code:
export SYSROOT="/home/x/Dirs/arm64/sysroot"
export TARGET="arm64"
clang --target=${TARGET} --sysroot=${SYSROOT} -o foo foo.c

Results in :error: unable to create target: 'No available targets are compatible with triple "arm64"'

Should i use "arm-none-eabi" executables instead ? Which parameters to give ?

Or i need to install different flavors of llvm ?
 
Code:
export SYSROOT="/home/x/Dirs/arm64/sysroot" 
export TARGET="aarch64-unknown-freebsd"
clang --target=${TARGET} --sysroot=${SYSROOT} -o foo foo.c
error: unable to create target: 'No available targets are compatible with triple "aarch64-unknown-freebsd"'

Code:
cc -target aarch64-unknown-freebsd -o foo foo.c

error: unable to create target: 'No available targets are compatible with triple "aarch64-unknown-freebsd"'
1 error generated.
 
Code:
$uname -rms
FreeBSD 13.0-RELEASE-p6 amd64
$cc -target aarch64-unkown-freebsd -c -o b.o b.c
$file b.o
b.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (FreeBSD), not stripped
 
Ooh I seemed to have in /etc/src.conf:
Code:
WITHOUT_LLVM_TARGET_AARCH64=yes
WITHOUT_LLVM_TARGET_ALL=yes
WITHOUT_LLVM_TARGET_ARM=yes
WITHOUT_LLVM_TARGET_BPF=yes
WITHOUT_LLVM_TARGET_MIPS=yes
WITHOUT_LLVM_TARGET_POWERPC=yes
WITHOUT_LLVM_TARGET_RISCV=yes
WITHOUT_LLVM_TARGET_SPARC=yes
Will put
Code:
WITH_LLVM_TARGET_ALL=yes
And rebuild world.

PS, this compiled on my PC :
Code:
export SYSROOT="/home/x/Dirs/arm64/sysroot"
export  TARGET="arm64"
clang13 --target=${TARGET} --sysroot=${SYSROOT} -c -o foo.o foo.c
 
Compiling works but linking did not seem to work:
Code:
export SYSROOT="/home/x/Dirs/arm64/sysroot"
export  TARGET="arm64"
rm foo
rm foo.o
clang13      --target=${TARGET} --sysroot=${SYSROOT} -c -o foo.o foo.c
clang13 -v   --target=${TARGET} --sysroot=${SYSROOT} foo.o

Produces:
Code:
HOST:x: /home/x/Dirs/arm64 >./compile_foo
rm: foo: No such file or directory
clang version 13.0.1
Target: arm64
Thread model: posix
InstalledDir: /usr/local/llvm13/bin
 "/usr/local/bin/gcc" -o a.out foo.o
/usr/local/bin/ld: aarch64 architecture of input file `foo.o' is incompatible with i386:x86-64 output
/usr/local/bin/ld: final link failed: file in wrong format
collect2: error: ld returned 1 exit status
clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

This looks like the wrong linker is invoked.

And:
Code:
cc -v   --target=${TARGET} --sysroot=${SYSROOT} foo.o
Produces:
Code:
FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)
Target: arm64
Thread model: posix
InstalledDir: /usr/bin
 "/usr/local/bin/gcc" -v --sysroot=/home/x/Dirs/arm64/sysroot -o a.out foo.o
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/lto-wrapper
Target: x86_64-portbld-freebsd13.0
Configured with: /wrkdirs/usr/ports/lang/gcc11/work/gcc-11.2.0/configure --disable-multilib --with-build-config=bootstrap-debug --disable-nls --enable-gnu-indirect-function --enable-host-shared --enable-plugin --libdir=/usr/local/lib/gcc11 --libexecdir=/usr/local/libexec/gcc11 --program-suffix=11 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc11/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --without-zstd --with-isl=/usr/local --enable-languages=c,c++,objc,fortran,jit --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/share/info/gcc11 --build=x86_64-portbld-freebsd13.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (FreeBSD Ports Collection)
COMPILER_PATH=/usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/:/usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/:/usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/:/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/:/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/:/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/../../../../../x86_64-portbld-freebsd13.0/bin/
LIBRARY_PATH=/usr/local/lib/:/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/:/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/../../../../../x86_64-portbld-freebsd13.0/lib/:/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/../../../:/home/x/Dirs/arm64/sysroot/lib/:/home/x/Dirs/arm64/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'a.out' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
 /usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/collect2 -plugin /usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/liblto_plugin.so -plugin-opt=/usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/lto-wrapper -plugin-opt=-fresolution=/tmp//cco3aF61.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --sysroot=/home/x/Dirs/arm64/sysroot --eh-frame-hdr -m elf_x86_64_fbsd -V -dynamic-linker /libexec/ld-elf.so.1 -o a.out /home/x/Dirs/arm64/sysroot/usr/lib/crt1.o /home/x/Dirs/arm64/sysroot/usr/lib/crti.o /usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/crtbegin.o -L/usr/local/lib -L/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0 -L/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/../../../../../x86_64-portbld-freebsd13.0/lib -L/usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/../../.. -L/home/x/Dirs/arm64/sysroot/lib -L/home/x/Dirs/arm64/sysroot/usr/lib foo.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/local/lib/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/crtend.o /home/x/Dirs/arm64/sysroot/usr/lib/crtn.o
GNU ld (GNU Binutils) 2.37
  Supported emulations:
...
...
/usr/local/bin/ld: skipping incompatible /home/x/Dirs/arm64/sysroot/lib/libc.so.7 when searching for /lib/libc.so.7
/usr/local/bin/ld: cannot find /lib/libc.so.7 inside /home/x/Dirs/arm64/sysroot
/usr/local/bin/ld: skipping incompatible /home/x/Dirs/arm64/sysroot/lib/libc.so.7 when searching for /lib/libc.so.7
/usr/local/bin/ld: skipping incompatible /home/x/Dirs/arm64/sysroot/usr/lib/libc_nonshared.a when searching for /usr/lib/libc_nonshared.a
/usr/local/bin/ld: cannot find /usr/lib/libc_nonshared.a inside /home/x/Dirs/arm64/sysroot
/usr/local/bin/ld: skipping incompatible /home/x/Dirs/arm64/sysroot/usr/lib/libc_nonshared.a when searching for /usr/lib/libc_nonshared.a
collect2: error: ld returned 1 exit status
cc: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

Maybe i should pass additional paramters to gcc11 ? Maybe stuff like rpath ?
Cross-compiling, very poorly documented...
Can you cross-compile&link only using gcc or only using clang ?
 
Back
Top