diff options
author | Petr Hosek <phosek@chromium.org> | 2019-07-22 18:52:42 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2019-07-22 18:52:42 +0000 |
commit | f6cd6ffbc9f8bfa0bbe25dba6a9737607a684bab (patch) | |
tree | 1dba4a914b3bbcb71e7b91a1c000cd5cb84b1d97 /llvm/lib | |
parent | ef5cfc2dae0725226254561b42134308720e57ab (diff) | |
download | bcm5719-llvm-f6cd6ffbc9f8bfa0bbe25dba6a9737607a684bab.tar.gz bcm5719-llvm-f6cd6ffbc9f8bfa0bbe25dba6a9737607a684bab.zip |
[SafeStack] Insert the deref after the offset
While debugging code that uses SafeStack, we've noticed that LLVM
produces an invalid DWARF. Concretely, in the following example:
int main(int argc, char* argv[]) {
std::string value = "";
printf("%s\n", value.c_str());
return 0;
}
DWARF would describe the value variable as being located at:
DW_OP_breg14 R14+0, DW_OP_deref, DW_OP_constu 0x20, DW_OP_minus
The assembly to get this variable is:
leaq -32(%r14), %rbx
The order of operations in the DWARF symbols is incorrect in this case.
Specifically, the deref is incorrect; this appears to be incorrectly
re-inserted in repalceOneDbgValueForAlloca.
With this change which inserts the deref after the offset instead of
before it, LLVM produces correct DWARF:
DW_OP_breg14 R14-32
Differential Revision: https://reviews.llvm.org/D64971
llvm-svn: 366726
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index c2d4303ecb0..be160541117 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1597,13 +1597,13 @@ static void replaceOneDbgValueForAlloca(DbgValueInst *DVI, Value *NewAddress, DIExpr->getElement(0) != dwarf::DW_OP_deref) return; - // Insert the offset immediately after the first deref. + // Insert the offset before the first deref. // We could just change the offset argument of dbg.value, but it's unsigned... if (Offset) { SmallVector<uint64_t, 4> Ops; - Ops.push_back(dwarf::DW_OP_deref); DIExpression::appendOffset(Ops, Offset); Ops.append(DIExpr->elements_begin() + 1, DIExpr->elements_end()); + Ops.push_back(dwarf::DW_OP_deref); DIExpr = Builder.createExpression(Ops); } |