<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67677>67677</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[ASAN] LLVM 17 does not detect ODR violations previously found using ASAN
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
justincady
</td>
</tr>
</table>
<pre>
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:
```c
// shared.c
int in_shared(void) { return 1; }
int (*fptr)(void) = in_shared;
```
```c
// static.c
int in_static(void) { return 2; }
int (*fptr)(void) = in_static;
```
```c
// main.c
extern int in_shared(void);
extern int in_static(void);
extern int (*fptr)(void);
int main() { return fptr() + in_static() + in_shared(); }
```
```bash
#!/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:
```shell
$ ./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:
```shell
$ ./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:
```shell
$ ./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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV91y6jgSfhpx02WXLYENF1xAWM6k6iSZIpnd2itKttpYc4TkleRk2Kffko0JMGEqZ-rsX5UB0-5uff2jT27unNxpxDmZLMlkNeKtr42d_9o6L3XJxWFUGHGY_-Kk3sHiefEIb9LX8PXrXx8gzaHiUjnwBgR6LD08rTbwKo3iXhrtwNfcA7d4fIzi3DoDrgUgt0qijUmyIsmi_76HQrpe3xvwtXRQmv1eesIWUHvfOMIWhK4JXe-kr9siLs2e0LVSr8NP1FjzK5ae0PXRlK75VDCOeUrpLBFZNZ2IggosZmk2TqdpMplWkzJlSX4BhdB8D9p4cK1FkFUPJ1zaoxYooMCav0pjgdDpWy3LGt5Mq0QwaKx0CHsEHnKB4A77wqhg3ToUhM7AWOAaWn3yVhrt8B8t6hJj-AktEpo74GCxsUa0JdoQ-xlCkiX9VR7_d3kBV3OLIj4KpfYg9bYXEjp9NbJbnuRLsOhbqyElbAkkX70bEDoldFE13hI6OzdiqzNnbHmF4zPgPPeyvAbXCT8GR78bXO_sz4Dbc6kHaPibR6vhRvpO7q_UrgL5SO0G_JNq0AlAOr2LVPQ2vZQuL9Y7lw1Qe6fvufvjTBTc1UMyGKEpoesigFifPei-774uHr8QtiJ03XBfE7r2Juw1xfVucDDulCCKXtE6aTSQ_A5q5AKitLsvWw-RAEJp94mqNGLXxp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