Issue 145299
Summary Using the libc++ with ASan and UBSan from apt.llvm.org (issue in __ubsan_handle_dynamic_type_cache_miss? libc++ vs. libstdc++ clash?)
Labels libc++
Assignees
Reporter exoosh
    Hi,

we're building a DSO on Linux against libc++ with ASan and UBSan instrumentation turned on.

A simple program then loads the DSO and during static initialization the issue occurs:

```
AddressSanitizer:DEADLYSIGNAL
================================================================= 
#1 0x70f927eb9995 in __dynamic_cast /build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/libsupc++/../../../../src/libstdc++-v3/libsupc++/dyncast.cc:80:28
#2 0x70f9287260d5 (/usr/lib/llvm-20/lib/clang/20/lib/linux/libclang_rt.asan-x86_64.so+0x1260d5) (BuildId: 5f516f9b88bd4a4401541f629081b4f212f55ba4)
#3 0x70f928725432 (/usr/lib/llvm-20/lib/clang/20/lib/linux/libclang_rt.asan-x86_64.so+0x125432) (BuildId: 5f516f9b88bd4a4401541f629081b4f212f55ba4)
#4 0x70f928725407 in __ubsan_handle_dynamic_type_cache_miss (/usr/lib/llvm-20/lib/clang/20/lib/linux/libclang_rt.asan-x86_64.so+0x125407) (BuildId: 5f516f9b88bd4a4401541f629081b4f212f55ba4)
#5 0x6cf91aee84cb in std::__1::basic_ifstream<char, std::__1::char_traits<char>>::basic_ifstream(char const*, unsigned int) /usr/lib/llvm-20/bin/../include/c++/v1/fstream:1156:60
...
```

The call at position 5 is essentially this line: `std::ifstream cmdlineFile("/proc/self/cmdline");`.

It took me a while to realize, but as you can see my DSO linked against **libc++** as evidenced by the presence of `/usr/lib/llvm-20/bin/../include/c++/v1/fstream` at position 5.

However, at position 1 we can see `/build/gcc-14-ig5ci0/gcc-14-14.2.0/build/x86_64-linux-gnu/libstdc++-v3/libsupc++/../../../../src/libstdc++-v3/libsupc++/dyncast.cc` which is clearly related to **libstdc++**!

I think the issue here is that the ASan runtime library is linked against libstdc++, which can be confirmed by:

```
$ readelf -a /usr/lib/llvm-20/lib/clang/20/lib/linux/libclang_rt.asan-x86_64.so|grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
```

... so _seemingly_ UBSan attempts to validate an object with `dynamic_cast` from libstdc++, whereas the object got created with libc++?

Is there an extra set of sanitizer runtime libraries that comes with `libc++-dev` (`libc++-20-dev`) that I can use, or do I have to build my own?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to