Hi all,
I have what seems like a very simple issue for which I’ve found almost no useful information online after quite a lot of reading mailing list threads and etc.
I’ve built LLVM-11 from a git checkout llvmorg-11.0.0
using the following CMAKE options.
cmake -G Ninja ../llvm-project/llvm -DCMAKE_{C_COMPILER=clang,CXX_COMPILER=clang++,BUILD_TYPE="MinSizeRel",INSTALL_PREFIX=$(realpath ../llvm-root/)} -DLLVM_{TARGETS_TO_BUILD="X86;AArch64",INCLUDE_TOOLS=ON,INCLUDE_EXAMPLES=OFF,INCLUDE_TESTS=OFF,INCLUDE_BENCHMARKS=OFF,ENABLE_PROJECTS="clang;flang;compiler-rt;openmp",PARALLEL_COMPILE_JOBS=32,PARALLEL_LINK_JOBS=4,ENABLE_BINDINGS=OFF} -DBUILD_SHARED_LIBS=ON
When I try to compile a simple test program with the resulting clang
, I see something different from my system installation (clang 10).
[andrew@baltar ~]$ cat test.c
int main () {}
[andrew@baltar ~]$ clang --target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu test.c -o test
[andrew@baltar ~]$ /data/andrew/llvm-root/bin/clang --target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu test.c -o test
/usr/bin/aarch64-linux-gnu-ld: cannot find crtbegin.o: No such file or directory
/usr/bin/aarch64-linux-gnu-ld: cannot find -lgcc
/usr/bin/aarch64-linux-gnu-ld: cannot find -lgcc
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
Those objects are present in /usr/lib/gcc/aarch64-linux-gnu/10.2.0
. However, if I just add -L/usr/lib/gcc/aarch64-linux-gnu/10.2.0
or even --gcc-toolchain=/usr/lib/gcc/aarch64-linux-gnu/10.2.0/
, the problem persists. How do I actually tell the linker invoked by clang where to look for these objects, and how come they aren’t in the sysroot (/usr/<target>
), but rather in /usr/lib/gcc/<target>
?
I’ve been stumped by this and I can’t find a solution online, just other folks with similar-ish problems in dead mailing list threads. Would really appreciate some pointers if anyone notices anything wrong! I suspect I need to configure the linker (aarch64-linux-gnu-ld in this case) somehow, but I’m not sure how (and I’m not sure why the -L above doesn’t work because that directory has those objects in it!)
Since the system installation of clang picks up those objects with the same invocation, I suspect I might have missed some configuration option in my build. Is there more to building LLVM for multiple targets than just adding them to the LLVM_TARGETS_TO_BUILD=
option?