hwasan: Instrument globals.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 6 Aug 2019 22:07:29 +0000 (22:07 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 6 Aug 2019 22:07:29 +0000 (22:07 +0000)
commit0930643ff6f1684bf234a97f6a3b76bf8e30b0a1
treee3f16c6f74310e4b9d31df5b9d90ecc66f4ce394
parentb3292a8469c398214e88d2dd56be6f4edb1d1728
hwasan: Instrument globals.

Globals are instrumented by adding a pointer tag to their symbol values
and emitting metadata into a special section that allows the runtime to tag
their memory when the library is loaded.

Due to order of initialization issues explained in more detail in the comments,
shadow initialization cannot happen during regular global initialization.
Instead, the location of the global section is marked using an ELF note,
and we require libc support for calling a function provided by the HWASAN
runtime when libraries are loaded and unloaded.

Based on ideas discussed with @evgeny777 in D56672.

Differential Revision: https://reviews.llvm.org/D65770

llvm-svn: 368102
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c
compiler-rt/lib/hwasan/hwasan.cpp
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_interface_internal.h
compiler-rt/lib/hwasan/hwasan_report.cpp
compiler-rt/test/hwasan/TestCases/global.c [new file with mode: 0644]
compiler-rt/test/hwasan/lit.cfg.py
llvm/include/llvm/BinaryFormat/ELF.h
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/test/Instrumentation/HWAddressSanitizer/globals.ll [new file with mode: 0644]