[clang] Do not instrument relative vtables under hwasan
authorLeonard Chan <leonardchan@google.com>
Fri, 26 Aug 2022 18:20:34 +0000 (18:20 +0000)
committerLeonard Chan <leonardchan@google.com>
Fri, 26 Aug 2022 18:21:40 +0000 (18:21 +0000)
commit93e5cf6b9c08d99cf7cefc0adda346bd7ba56049
treed3796ab2773a585062d240c2dc09a00405eb0926
parentc58791c286e0b0feba04711e973bf7b4871d1dfb
[clang] Do not instrument relative vtables under hwasan

Full context in
https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=107017.

Instrumenting hwasan with globals results in a linker error under the
relative vtables abi:

```
ld.lld: error:
libunwind.cpp:(.rodata..L_ZTVN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_15Registers_arm64EEE.hwasan+0x8):
relocation R_AARCH64_PLT32 out of range: 6845471433603167792 is not in
[-21474836482147483647]; references
libunwind::AbstractUnwindCursor::~AbstractUnwindCursor()
>>> defined in
libunwind/src/CMakeFiles/unwind_shared.dir/libunwind.cpp.obj
```

This is because the tag is included in the vtable address when
calculating the offset between the vtable and virtual function. A
temporary solution until we can resolve this is to just disable hwasan
instrumentation on relative vtables specifically, which can be done in
the frontend.

Differential Revision: https://reviews.llvm.org/D132425
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CGVTables.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-hwasan.cpp [new file with mode: 0644]