[ASAN] LLVM 17 does not detect ODR violations previously found using ASAN
Using ASAN with LLVM 17 fails to detect ODR violations that are detected with LLVM 16 and earlier.
I bisected to this commit: https://github.com/llvm/llvm-project/commit/a8d3ae712290d6f85db2deb9164181058f5c1307
I'm not sure if this is intended behavior (which would surprise me as the symbol is used) or an unintended consequence. Here's a reproducer:
// shared.c
int in_shared(void) { return 1; }
int (*fptr)(void) = in_shared;
// static.c
int in_static(void) { return 2; }
int (*fptr)(void) = in_static;
// main.c
extern int in_shared(void);
extern int in_static(void);
extern int (*fptr)(void);
int main() { return fptr() + in_static() + in_shared(); }
#!/bin/bash
CLANG=/path/to/clang
$CLANG --version | head -1 | cut -d " " -f1-3
$CLANG -fsanitize=address -fPIC -shared shared.c -o shared.so
$CLANG -fsanitize=address -c static.c
ar rs static.a static.o
$CLANG -fuse-ld=lld -fsanitize=address -Wl,-rpath,'$ORIGIN' shared.so static.a main.c
./a.out
Running it with LLVM 16:
$ ./build.sh
clang version 16.0.6
=================================================================
==28316==ERROR: AddressSanitizer: odr-violation (0x55e177c12b40):
[1] size=8 'fptr' static.c
[2] size=8 'fptr' shared.c
These globals were registered at these points:
[1]:
#0 0x55e177b4b217 in __asan_register_globals /[...]/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:356:3
#1 0x55e177c0d33b in asan.module_ctor static.c
[2]:
#0 0x55e177b4b217 in __asan_register_globals /[...]/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:356:3
#1 0x7fcfa36daf6b in asan.module_ctor shared.c
==28316==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'fptr' at static.c
==28316==ABORTING
$
Running it with LLVM 17:
$ ./build.sh
clang version 17.0.1
$
Flipping the default back by applying -fno-sanitize-address-globals-dead-stripping brings back the error with LLVM 17:
$ ./build.sh
clang version 17.0.1
=================================================================
==28382==ERROR: AddressSanitizer: odr-violation (0x557d7e463e20):
[1] size=8 'fptr' static.c
[2] size=8 'fptr' shared.c
[...]
But the default behavior appears to hide ODR violations, which seems like a bug to me.
cc @MaskRay
/cherry-pick 1a4b9b6f73391d94f4f96cc964cbf89cfdd59b5b
Would be nice to have this in 17.0.2
/branch llvm/llvm-project-release-prs/issue67677
/pull-request llvm/llvm-project-release-prs#714
https://github.com/llvm/llvm-project/commit/1a4b9b6f73391d94f4f96cc964cbf89cfdd59b5b had an issue and was reverted with a reland.
/cherry-pick 16eed8c906875e748c3cb610f3dc4b875f3882aa
/branch llvm/llvm-project-release-prs/issue67677