This is an archive of the discontinued LLVM Phabricator instance.

[RFC] Print exact source locations of global variables in ASan error reports.
AbandonedPublic

Authored by samsonov on Jun 18 2014, 7:14 PM.

Details

Reviewers
kcc
glider
eugenis
Summary

This changes introduces llvm.asan.globals metadata, which can be
used by the frontend to provide additional information about the LLVM
global variables, namely:

  1. source location (file/line/column) of corresponding globals in the user code.

These locations will be available at runtime, and will be printed in the
error report if needed, even if the binary is built without debug info.

  1. whether global is dynamically initialized. This replaces

llvm.asan.dynamically_initialized_globals metadata used to detect init-order bugs.

  1. whether the global is blacklisted. This is a first step to move all blacklist

functionality to the frontend.

Note: This is an ABI-breaking change. All users of ASan runtime library will have
to emit new layout of __asan_global structure (now it has one more field).

If you're OK with this change, I will commit it with extra ASan output tests,
checking that we're actually reporting source locations for global variables,
function-static variables and simple string literals.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 10601.Jun 18 2014, 7:14 PM
samsonov retitled this revision from to [RFC] Print exact source locations of global variables in ASan error reports..
samsonov updated this object.
samsonov edited the test plan for this revision. (Show Details)
samsonov added reviewers: kcc, eugenis.
samsonov added subscribers: Unknown Object (MLST), Unknown Object (MLST).
kcc edited edge metadata.Jun 19 2014, 2:11 AM
kcc added a subscriber: glider.

seems reasonable, now let's see the tests.

+glider, who is looking around the same parts of code currently.

lib/Transforms/Instrumentation/AddressSanitizer.cpp
247

can this be done with a single lookup to SourceLocation and only if DN->getOperand(1) is non-zero?

Didn't look deep, but here's one note.

projects/compiler-rt/lib/asan/asan_interface_internal.h
54

If you store file and line/column location separately you can probably save some memory.

samsonov updated this revision to Diff 10663.Jun 19 2014, 3:29 PM
samsonov edited edge metadata.

Address kcc's comment. Add tests for the new functionality.

samsonov updated this revision to Diff 10664.Jun 19 2014, 3:30 PM

Upload the correct fileset.

lib/Transforms/Instrumentation/AddressSanitizer.cpp
247

Done.

projects/compiler-rt/lib/asan/asan_interface_internal.h
54

Maybe, but 8 byte per global is not a big deal (we spend a bunch of memory for redzones anyway). I'd like to keep source location in a struct. In future we may be able to share it between different sanitizers. E.g. UBSan already has it, and uses the same layout.

kcc added a comment.Jun 20 2014, 12:45 AM

looks good once you bump the version of __asan_init, but please also wait for glider's review.

projects/compiler-rt/lib/asan/asan_interface_internal.h
54

you need to bump the version of __asan_init_vN

AddressSanitizer.cpp LGTM

lib/Transforms/Instrumentation/AddressSanitizer.cpp
1069

nit: spare newline?

projects/compiler-rt/test/asan/TestCases/global-location.cc
12

"struct C", maybe?

18

Do you need the slash before global-location.cc? Isn't it possible that there's no directory prefix (maybe not in the current setup)?

samsonov updated this revision to Diff 10773.Jun 23 2014, 11:24 PM

Bumped __asan_init version to mark ABI change.
Addressed comments by glider.

lib/Transforms/Instrumentation/AddressSanitizer.cpp
1069

Done

projects/compiler-rt/lib/asan/asan_interface_internal.h
54

Done.

projects/compiler-rt/test/asan/TestCases/global-location.cc
12

Done

18

Done.

Any more comments on this?

samsonov updated this revision to Diff 11027.Jul 2 2014, 9:19 AM

Rebase to trunk.

In offline discussion glider confirmed that he's OK with instrumentation pass and is not familiar enough with Clang code. I've tested this change on a large codebase and found no regressions. Existing reports global-buffer-overflow bugs are extended with source location information as expected. I'm going to submit this now.

samsonov abandoned this revision.Jul 2 2014, 1:46 PM