diff options
author | Fangrui Song <i@maskray.me> | 2023-09-29 10:44:50 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2023-09-29 10:44:50 -0700 |
commit | 1a4b9b6f73391d94f4f96cc964cbf89cfdd59b5b (patch) | |
tree | 3558ba812e1c0f55fa7e76944187c1ceb9fdfcd1 /clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp | |
parent | cc9ba5600e540fd4e059d20591917962a6df043d (diff) | |
download | llvm-1a4b9b6f73391d94f4f96cc964cbf89cfdd59b5b.zip llvm-1a4b9b6f73391d94f4f96cc964cbf89cfdd59b5b.tar.gz llvm-1a4b9b6f73391d94f4f96cc964cbf89cfdd59b5b.tar.bz2 |
[asan] Ensure __asan_register_elf_globals is called in COMDAT asan.module_ctor (#67745)
On ELF platforms, when there is no global variable, 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.
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
```
Diffstat (limited to 'clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp')
0 files changed, 0 insertions, 0 deletions