[PATCH] D77182: [AddressSanitizer] Fix for wrong argument values appearing in backtraces

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 31 16:00:02 PDT 2020


vsk created this revision.
vsk added reviewers: aprantl, eugenis.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

In some cases, ASan may insert instrumentation before function arguments
have been stored into their allocas. This causes two issues:

1. The argument value must be spilled until it can be stored into the reserved alloca, wasting a stack slot.

2. Until the store occurs in a later basic block, the debug location will point to the wrong frame offset, and backtraces will show an uninitialized value.

The proposed solution is to move instructions which initialize allocas
for arguments up into the entry block, before the position where ASan
starts inserting its instrumentation.

For the motivating test case, before the patch we see:

  | 0033: movq %rdi, 0x68(%rbx)  |   | DW_TAG_formal_parameter     |
  | ...                          |   |   DW_AT_name ("a")          |
  | 00d1: movq 0x68(%rbx), %rsi  |   |   DW_AT_location (RBX+0x90) |
  | 00d5: movq %sdi, 0x90(%rbx)  |   |        ^ not correct ...    |

and after the patch we see:

  | 002f: movq %rdi, 0x70(%rbx)  |   | DW_TAG_formal_parameter     |
  |                              |   |   DW_AT_name ("a")          |
  |                              |   |   DW_AT_location (RBX+0x70) |

rdar://61122691


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77182

Files:
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/hoist-argument-init-insts.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77182.254026.patch
Type: text/x-patch
Size: 5902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200331/3967347d/attachment.bin>


More information about the llvm-commits mailing list