OSDN Git Service

hwasan: Add a tag_offset DWARF attribute to instrumented stack variables.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 17 Jun 2019 23:39:41 +0000 (23:39 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 17 Jun 2019 23:39:41 +0000 (23:39 +0000)
commitf159a1182eabe15e1f6dcd9512bf47be5c8a0c66
tree97e08161c74af0b260325d6d6803796acfc9d2e8
parentbca91c8cabcaa21851f4eb67d4fe6cb36055d468
hwasan: Add a tag_offset DWARF attribute to instrumented stack variables.

The goal is to improve hwasan's error reporting for stack use-after-return by
recording enough information to allow the specific variable that was accessed
to be identified based on the pointer's tag. Currently we record the PC and
lower bits of SP for each stack frame we create (which will eventually be
enough to derive the base tag used by the stack frame) but that's not enough
to determine the specific tag for each variable, which is the stack frame's
base tag XOR a value (the "tag offset") that is unique for each variable in
a function.

In IR, the tag offset is most naturally represented as part of a location
expression on the llvm.dbg.declare instruction. However, the presence of the
tag offset in the variable's actual location expression is likely to confuse
debuggers which won't know about tag offsets, and moreover the tag offset
is not required for a debugger to determine the location of the variable on
the stack, so at the DWARF level it is represented as an attribute so that
it will be ignored by debuggers that don't know about it.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363635 91177308-0d34-0410-b5e6-96231b3b80d8
12 files changed:
docs/LangRef.rst
include/llvm/BinaryFormat/Dwarf.def
include/llvm/BinaryFormat/Dwarf.h
lib/BinaryFormat/Dwarf.cpp
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
lib/CodeGen/AsmPrinter/DwarfExpression.cpp
lib/CodeGen/AsmPrinter/DwarfExpression.h
lib/IR/DebugInfoMetadata.cpp
lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
test/Assembler/diexpression.ll
test/CodeGen/AArch64/dbg-declare-tag-offset.ll [new file with mode: 0644]
test/Instrumentation/HWAddressSanitizer/dbg-declare-tag-offset.ll [new file with mode: 0644]