llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.82k stars 10.99k forks source link

linker error in a new llvm build #69056

Open mbelda opened 8 months ago

mbelda commented 8 months ago

I am installing llvm in a clean build and I got a linker error when building it.

I have configured it with the following options.

cmake -S llvm -B build -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;polly" -DCMAKE_BUILD_TYPE=Release

And then when building it executing cmake --build build the following error appears.

[ 52%] Building CXX object projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_value.cpp.o
[ 52%] Built target RTUbsan.x86_64
[ 52%] Building CXX object projects/compiler-rt/lib/ubsan/CMakeFiles/clang_rt.ubsan_standalone-x86_64.dir/ubsan_init_standalone_preinit.cpp.o
[ 52%] Linking CXX static library ../../../../lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.a
[ 52%] Built target clang_rt.ubsan_standalone-x86_64
[ 52%] Generating version list for clang_rt.ubsan_standalone-dynamic-x86_64
[ 52%] Building CXX object projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o
[ 52%] Built target RTUbsan_dynamic_version_script_dummy.x86_64
[ 52%] Linking CXX shared library ../../../../lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so
/usr/bin/ld: CMakeFiles/RTUbsan_cxx.x86_64.dir/ubsan_type_hash_itanium.cpp.o: in function `findBaseAtOffset(__cxxabiv1::__class_type_info const*, long)':
/home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:174: undefined reference to `typeinfo for __cxxabiv1::__si_class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:174: undefined reference to `typeinfo for __cxxabiv1::__class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:174: undefined reference to `__dynamic_cast'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:178: undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:178: undefined reference to `__dynamic_cast'
/usr/bin/ld: CMakeFiles/RTUbsan_cxx.x86_64.dir/ubsan_type_hash_itanium.cpp.o: in function `isDerivedFromAtOffset(__cxxabiv1::__class_type_info const*, __cxxabiv1::__class_type_info const*, long)':
/home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:137: undefined reference to `typeinfo for __cxxabiv1::__si_class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:137: undefined reference to `typeinfo for __cxxabiv1::__class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:137: undefined reference to `__dynamic_cast'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:141: undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:141: undefined reference to `typeinfo for __cxxabiv1::__class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:141: undefined reference to `__dynamic_cast'
/usr/bin/ld: CMakeFiles/RTUbsan_cxx.x86_64.dir/ubsan_type_hash_itanium.cpp.o: in function `__ubsan::checkDynamicType(void*, void*, unsigned long)':
/home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245: undefined reference to `typeinfo for __cxxabiv1::__class_type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245: undefined reference to `typeinfo for std::type_info'
/usr/bin/ld: /home/mbelda/epfl/llvm-project/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:245: undefined reference to `__dynamic_cast'
collect2: error: ld returned 1 exit status
make[2]: *** [projects/compiler-rt/lib/ubsan/CMakeFiles/clang_rt.ubsan_standalone-dynamic-x86_64.dir/build.make:257: lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:38979: projects/compiler-rt/lib/ubsan/CMakeFiles/clang_rt.ubsan_standalone-dynamic-x86_64.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
dtcxzyw commented 8 months ago

I guess that you can pass -DLLVM_ENABLE_RTTI=ON to cmake to address this problem. See also https://llvm.org/docs/CMake.html#llvm-related-variables.

mbelda commented 8 months ago

I still got the same error.

dtcxzyw commented 8 months ago

I am sorry I cannot reproduce the linker error on the trunk version.

mbelda commented 8 months ago

Probably I am missing some libraries or packages required because I have a fresh ubuntu 20.04. Do you know any library that is used by llvm that I should install?

mbelda commented 8 months ago

I also tried following the Quick Start of the guide https://llvm.org/docs/CMake.html#quick-start and it gives me this error. So it might not be because of the options I used.

[ 98%] Linking CXX executable ../../bin/opt
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
make[2]: *** [tools/opt/CMakeFiles/opt.dir/build.make:268: bin/opt] Error 1
make[2]: *** Deleting file 'bin/opt'
make[1]: *** [CMakeFiles/Makefile2:41476: tools/opt/CMakeFiles/opt.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
dtcxzyw commented 8 months ago

I also tried following the Quick Start of the guide https://llvm.org/docs/CMake.html#quick-start and it gives me this error. So it might not be because of the options I used.

[ 98%] Linking CXX executable ../../bin/opt
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
make[2]: *** [tools/opt/CMakeFiles/opt.dir/build.make:268: bin/opt] Error 1
make[2]: *** Deleting file 'bin/opt'
make[1]: *** [CMakeFiles/Makefile2:41476: tools/opt/CMakeFiles/opt.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

It seems that you ran out of memory during linking. -DLLVM_PARALLEL_LINK_JOBS=1 or setting up a swap space may help.

mbelda commented 8 months ago

It works with that flag.

I will try to figure out why with the project options it does not work.

mbelda commented 8 months ago

The build with only the clang and clang tools extra options works and also with the polly option. So it is the compiler-rt option the one causing the error.

dtcxzyw commented 8 months ago

I always build shared libraries for LLVM. Could you please try with -DBUILD_SHARED_LIBS=ON? If it still doesn't work, I am sorry I cannot be more help.

mbelda commented 8 months ago

I still get the same error. Thank you. I will post the solution when it works.

rnburn commented 8 months ago

I'm getting the same error when I try to build compiler-rt.

This is a nix flake with the build I'm using: https://github.com/spaceandtimelabs/blitzar/blob/980857697abe388d99c3a183817a0b133b48051c/nix/clang.nix

If I uncomment this line to include compiler-rt, it fails with the similar message

/nix/store/74y3751gsixaz9797ib0hp7c658sp1y5-binutils-2.40/bin/ld: /build/llvm-project-6768a3d/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:178: undefined reference to `typeinfo for __cxxabiv1::__vmi_class_type_info'
/nix/store/74y3751gsixaz9797ib0hp7c658sp1y5-binutils-2.40/bin/ld: /build/llvm-project-6768a3d/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp:178: undefined reference to `__dynamic_cast'

I tried some other options, but keep getting the same erorr. It looks like it's not linking libc++abi.