[ASan] Print exact source location of global variables in error reports.
commita69d4cc1b9d46e75a24ab008ef78b0d5073e3994
authorAlexey Samsonov <vonosmas@gmail.com>
Wed, 2 Jul 2014 16:54:41 +0000 (2 16:54 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Wed, 2 Jul 2014 16:54:41 +0000 (2 16:54 +0000)
treeab1b4fa5a4f27fff399464668b20ff304c74f65c
parentf0491ad97b31b2b3b8e954e6a6cc1d3b71676b69
[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.

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212188 91177308-0d34-0410-b5e6-96231b3b80d8
lib/asan/asan_dll_thunk.cc
lib/asan/asan_interface_internal.h
lib/asan/asan_report.cc
test/asan/TestCases/global-location.cc [new file with mode: 0644]