Issue 101671
Summary [asan] False positive ODR violation error for global data (e.g. vtable)
Labels new issue
Assignees
Reporter glebov-andrey
    Hi!

This issue initially manifested itself as an ODR violation for `vtable for boost::filesystem::filesystem_error` when Boost.Filesystem is a static library linked into two shared libraries (built with Clang).
After some minimization it appears to be an issue common to all global non-weak data (symbol types `D` and `B` in `nm`'s output). On Clang this affects vtables while on GCC it does not because its vtables are weak symbols (or maybe they just aren't checked since they don't have associated `__odr_asan.` symbols?).

Here's the setup which reproduces the issue on both Clang and GCC:
- Static library `fs` includes an `extern int global_var`.
- Shared library `lib` uses `global_var` from `fs` somehow to avoid it being discarded.
- Executable `exe` uses `global_var` from `fs` somehow to avoid it being discarded, and also links to `lib`.

When running the executable we get the error:
```
=================================================================
==16997==ERROR: AddressSanitizer: odr-violation (0x7fb16f5bafc0):
  [1] size=4 'fs::global_var' fs_error.cpp in out/exe
  [2] size=4 'fs::global_var' fs_error.cpp in out/lib.so
These globals were registered at these points:
  [1]:
    #0 0x7fb16eadc752  (out/exe+0x41752)
    #1 0x7fb16eadd8f9  (out/exe+0x428f9)
    #2 0x7fb16e489eba (/lib/x86_64-linux-gnu/libc.so.6+0x29eba) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  [2]:
    #0 0x7fb16eadc752  (out/exe+0x41752)
    #1 0x7fb16eadd8f9 (out/exe+0x428f9)
    #2 0x7fb16ea5647d (/lib64/ld-linux-x86-64.so.2+0x647d) (BuildId: 4186944c50f8a32b47d74931e3f512b811813b64)

==16997==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'fs::global_var' at fs_error.cpp in out/exe
==16997==ABORTING
```
I've minimized the flags required and really the only one is `-fsanitize=address`:
```sh
cpp_flags=(-fPIC -O0 -fsanitize=address)
link_flags=("-Wl,-rpath,\$ORIGIN")
```
`-fvisibility=hidden` doesn't affect anything as long as the symbols of interest are marked `[[gnu::visibility("default")]]`.

I'm attaching a zip file with a full example: [asan-odr-repro.zip](https://github.com/user-attachments/files/16471014/asan-odr-repro.zip)

Tested on Linux x86_64.
Clang 16.0.6, 18.1.8 and `main` all exhibit the same behavior including for vtables.
GCC 11.4 and 12.3 only exhibit the behavior for global variables.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to