llvm / llvm-project

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

Memory sanitizer on shared library issue #112430

Open VA-GS opened 5 days ago

VA-GS commented 5 days ago

Hello, is there a way to make a shared library built with Memory sanitizer that is importable from Python ? I tried with Pybind11 and I am getting either undefined symbols on the import or if I link libclang_rt.msan-x86_64.a explicitly, I get relocation R_X86_64_TPOFF32 against __msan::is_in_symbolizer_or_unwinder cannot be used with -shared.

To keep it simple, the example below does not add Pybind11 to the mix:

/*
clang++ -o msan_test.so -shared -fsanitize=memory msan_test.cpp -fuse-ld=lld -stdlib=libc++ -v -Wl,-v

python -c "import msan_test"
undefined symbol: __msan_init

clang++ -o msan_test.so -shared -fsanitize=memory msan_test.cpp -fuse-ld=lld -stdlib=libc++ -v -Wl,-v /usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.msan-x86_64.a
relocation R_X86_64_TPOFF32 against msan_expect_umr cannot be used with -shared
*/
int main() {
}
VA-GS commented 4 days ago

I get something similar with TSAN too.