[ASan] Print exact source location of global variables in error reports.
authorAlexey Samsonov <vonosmas@gmail.com>
Wed, 2 Jul 2014 16:54:41 +0000 (16:54 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Wed, 2 Jul 2014 16:54:41 +0000 (16:54 +0000)
commit4f319cca42913b3eec7e658a07aa593fb4f9c2b1
treef94ffa140059c5ac16dc02d12dc8003f1fbb913c
parentaba845e835d749155c431c559a7fb19d80cb6b25
[ASan] Print exact source location of global variables in error reports.

See https://code.google.com/p/address-sanitizer/issues/detail?id=299 for the
original feature request.

Introduce llvm.asan.globals metadata, which Clang (or any other frontend)
may use to report extra information about global variables to ASan
instrumentation pass in the backend. This metadata replaces
llvm.asan.dynamically_initialized_globals that was used to detect init-order
bugs. llvm.asan.globals contains the following data for each global:
  1) source location (file/line/column info);
  2) whether it is dynamically initialized;
  3) whether it is blacklisted (shouldn't be instrumented).

Source location data is then emitted in the binary and can be picked up
by ASan runtime in case it needs to print error report involving some global.
For example:

  0x... is located 4 bytes to the right of global variable 'C::array' defined in '/path/to/file:17:8' (0x...) of size 40

These source locations are printed even if the binary doesn't have any
debug info.

This is an ABI-breaking change. ASan initialization is renamed to
__asan_init_v4(). Pre-built libraries compiled with older Clang will not work
with the fresh runtime.

llvm-svn: 212188
13 files changed:
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGen/asan-globals.cpp [new file with mode: 0644]
clang/test/CodeGen/sanitize-init-order.cpp
compiler-rt/lib/asan/asan_dll_thunk.cc
compiler-rt/lib/asan/asan_interface_internal.h
compiler-rt/lib/asan/asan_report.cc
compiler-rt/test/asan/TestCases/global-location.cc [new file with mode: 0644]
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll [new file with mode: 0644]
llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll