llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

LLVM 17: link error with MSan on Ubuntu 16

Open ns-osmolsky opened this issue 3 years ago • 3 comments

Trying LLVM 17-rc3 and my application fails to link in the MSan mode with this error:

/usr/bin/ld: /opt/llvm/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.msan.a(msan.cpp.o): unable to initialize decompress status for section .debug_info

I think there are two issues here:

  1. It appears that ld on Ubuntu 16 does not handle libclang_rt.msan.a
  2. I have LD configured in my Autotools build system and that works well for GCC builds Yet, apparently, clang++ falls back to the system's ld.

ns-osmolsky avatar Aug 29 '23 15:08 ns-osmolsky

There's also a different, but similar issue: any linker fails when trying to compile using -rtlib=compiler-rt with a sanitizer (tried with at least with asan, ubsan and both).

It happens at least on Arch, and it seems like on RHEL-like distros as well.. (The library in their package doesn't provide all the necessary _Unwind symbols). Please see #29055 and its last comment.

figuld avatar Aug 29 '23 16:08 figuld

/usr/bin/ld: /opt/llvm/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.msan.a(msan.cpp.o): unable to initialize decompress status for section .debug_info

This is a binutils diagnostic before https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=758dd750bc6d752b290aefdd62048ca2ea5899d4 (Oct 2022). It looks like that you have compressed .debug_info that ld doesn't support.

llvm-project's CMake build system does not set default compression. If you use clang++ to build llvm-project, it may be that you specified -gz or similar options (https://maskray.me/blog/2022-01-23-compressed-debug-sections) but your GNU ld (/usr/bin/ld) doesn't support compression.

There's also a different, but similar issue: any linker fails when trying to compile using -rtlib=compiler-rt with a sanitizer (tried with at least with asan, ubsan and both).

The issue is unrelated to 65075 and should be reported separately.

MaskRay avatar Aug 29 '23 19:08 MaskRay

/usr/bin/ld: /opt/llvm/lib/clang/17/lib/x86_64-unknown-linux-gnu/libclang_rt.msan.a(msan.cpp.o): unable to initialize decompress status for section .debug_info

This is a binutils diagnostic before https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=758dd750bc6d752b290aefdd62048ca2ea5899d4 (Oct 2022). It looks like that you have compressed .debug_info that ld doesn't support.

Right, that makes sense. Thanks!

llvm-project's CMake build system does not set default compression. If you use clang++ to build llvm-project, it may be that you specified -gz or similar options (https://maskray.me/blog/2022-01-23-compressed-debug-sections) but your GNU ld (/usr/bin/ld) doesn't support compression.

LLVM was built with GCC-12 and then the bits of the MSan runtime were built with Clang:

export CC=$destination/bin/clang
export CXX=$destination/bin/clang++
cmake \
        -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
        -S runtimes -B llvm-build-msan \
        -DLLVM_USE_SANITIZER=Memory \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX:PATH=$wd/llvm-install \
        -DLLVM_TARGETS_TO_BUILD="X86"
make -C llvm-build-msan -j cxx cxxabi unwind
make -C llvm-build-msan -j install-cxx install-cxxabi

So, the new default must be coming from the CMake scripts... and there must have been a recent change (as my CI builds broke).

ns-osmolsky avatar Aug 29 '23 21:08 ns-osmolsky