Commit 888437e
[asan] Ensure __asan_register_elf_globals is called in COMDAT asan.module_ctor (#67745)
On ELF platforms, when there is no global variable and the unique module ID is
non-empty, COMDAT asan.module_ctor is created with no
`__asan_register_elf_globals` calls. If this COMDAT is the prevailing copy
selected by the linker, the linkage unit will have no
`__asan_register_elf_globals` call: the redzone will not be poisoned and ODR
violation checker will not work (#67677).
This behavior is benign for -fno-sanitize-address-globals-dead-stripping because
asan.module_ctor functions that call `__asan_register_globals`
(`InstrumentGlobalsWithMetadataArray`) do not use COMDAT.
To fix #67677:
* Use COMDAT for -fsanitize-address-globals-dead-stripping on ELF platforms.
* Call `__asan_register_elf_globals` even if there is no global variable.
* If the unique module ID is empty, don't call SetComdatForGlobalMetadata:
placing `@.str` in a COMDAT would incorrectly discard internal COMDAT `@.str`
in other compile units.
Alternatively, when there is no global variable, asan.module_ctor is not COMDAT
and does not call `__asan_register_elf_globals`. However, the asan.module_ctor
function cannot be eliminated by the linker.
Tested the following script. Only ELF -fsanitize-address-globals-dead-stripping has changed behaviors.
```
echo > a.cc # no global variable, empty uniqueModuleId
echo 'void f() {}' > b.cc # with global variable, with uniqueModuleId
echo 'int g;' > c.cc # with global variable
for t in x86_64-linux-gnu arm64-apple-macosx x86_64-windows-msvc; do
for gc in -f{,no-}sanitize-address-globals-dead-stripping; do
for f in a.cc b.cc c.cc; do
echo /tmp/Rel/bin/clang -S --target=$t -fsanitize=address $gc $f -o -
/tmp/Rel/bin/clang -S --target=$t -fsanitize=address $gc $f -o - | sed -n '/asan.module_ctor/,/ret/p'
done
done
done
```
---
Identical to commit 16eed8c.
6420d33 is an incorrect revert for genuine
purely internal issues.1 parent 2e00f4c commit 888437e
File tree
4 files changed
+97
-37
lines changed- llvm
- lib/Transforms/Instrumentation
- test/Instrumentation/AddressSanitizer
4 files changed
+97
-37
lines changedLines changed: 32 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
819 | 819 | | |
820 | 820 | | |
821 | 821 | | |
822 | | - | |
| 822 | + | |
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
826 | | - | |
| 826 | + | |
827 | 827 | | |
828 | 828 | | |
829 | 829 | | |
| |||
2177 | 2177 | | |
2178 | 2178 | | |
2179 | 2179 | | |
2180 | | - | |
| 2180 | + | |
2181 | 2181 | | |
2182 | 2182 | | |
2183 | 2183 | | |
| |||
2187 | 2187 | | |
2188 | 2188 | | |
2189 | 2189 | | |
2190 | | - | |
| 2190 | + | |
2191 | 2191 | | |
2192 | 2192 | | |
2193 | 2193 | | |
| |||
2237 | 2237 | | |
2238 | 2238 | | |
2239 | 2239 | | |
2240 | | - | |
| 2240 | + | |
2241 | 2241 | | |
2242 | 2242 | | |
2243 | 2243 | | |
| |||
2343 | 2343 | | |
2344 | 2344 | | |
2345 | 2345 | | |
2346 | | - | |
| 2346 | + | |
2347 | 2347 | | |
2348 | | - | |
2349 | | - | |
2350 | 2348 | | |
2351 | 2349 | | |
2352 | 2350 | | |
| |||
2364 | 2362 | | |
2365 | 2363 | | |
2366 | 2364 | | |
2367 | | - | |
2368 | | - | |
2369 | | - | |
2370 | | - | |
2371 | | - | |
2372 | 2365 | | |
2373 | 2366 | | |
2374 | 2367 | | |
| |||
2391 | 2384 | | |
2392 | 2385 | | |
2393 | 2386 | | |
2394 | | - | |
2395 | | - | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
2396 | 2392 | | |
2397 | 2393 | | |
2398 | 2394 | | |
| |||
2517 | 2513 | | |
2518 | 2514 | | |
2519 | 2515 | | |
2520 | | - | |
2521 | | - | |
2522 | | - | |
2523 | | - | |
2524 | | - | |
2525 | | - | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
2526 | 2521 | | |
2527 | | - | |
2528 | | - | |
2529 | | - | |
2530 | | - | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
2531 | 2528 | | |
2532 | | - | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
2533 | 2537 | | |
2534 | 2538 | | |
2535 | 2539 | | |
2536 | 2540 | | |
2537 | 2541 | | |
2538 | 2542 | | |
2539 | 2543 | | |
2540 | | - | |
2541 | 2544 | | |
2542 | 2545 | | |
2543 | 2546 | | |
| |||
2601 | 2604 | | |
2602 | 2605 | | |
2603 | 2606 | | |
2604 | | - | |
| 2607 | + | |
2605 | 2608 | | |
2606 | 2609 | | |
2607 | | - | |
| 2610 | + | |
2608 | 2611 | | |
2609 | 2612 | | |
2610 | 2613 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
215 | 217 | | |
216 | 218 | | |
217 | 219 | | |
| |||
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| |||
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
Lines changed: 47 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
0 commit comments