[PATCH] D73526: [SafeStack][DebugInfo] Insert DW_OP_deref in correct location

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 09:17:28 PST 2020


bjope added a comment.

This broke some of our downstream tests using vla:s. Those are compiled from C and executed in gdb. What happens is that DW_OP_deref disappears and then the debugger prints the wrong value.
In those tests there is no other operations in the DIExpressions (so I can't really tell if prepend would be more correct than append, but with the patch that landed we get no DW_OP_deref at all).

Just giving a heads up that something seems weird with this patch.

One indication of that might be that if I run

  llc -O0 -mtriple=x86_64-unknown-linux-gnu -o -  test/DebugInfo/X86/safestack-deref.ll

we used to get things like

  .Ltmp1:
          #DEBUG_VALUE: func:value <- [DW_OP_constu 8, DW_OP_minus, DW_OP_deref] $rdx
  ...
          movq    %rdx, (%rsp)           # 8-byte Spill
  .Ltmp2:
          #DEBUG_VALUE: func:value <- [DW_OP_constu 8, DW_OP_minus, DW_OP_deref] [$rsp+0]
          #DEBUG_VALUE: func:value <- [DW_OP_constu 8, DW_OP_minus, DW_OP_deref] [$rsp+0]

So before the spill we say that func:value can be found by doing [$rdx-8],
and after the spill [[$rsp] - 8]   (where [] denotes dereference).

That seems consistent for the three DEBUG_VALUE comments.

But after this patch we get

  .Ltmp1:
          #DEBUG_VALUE: func:value <- [DW_OP_constu 8, DW_OP_minus] [$rdx+0]
  ...
          movq    %rdx, (%rsp)           # 8-byte Spill
  .Ltmp2:
          #DEBUG_VALUE: func:value <- [DW_OP_constu 8, DW_OP_minus] [$rsp+0]
          #DEBUG_VALUE: func:value <- [DW_OP_deref, DW_OP_constu 8, DW_OP_minus] [$rsp+0]

Before the spill we say that func:value is given by [$rdx]-8.
After the spill we got two different variants, either [$rsp]-8 or [[$rsp]]-8.

If I for example change the triple to i686 we get a different spill slot, so then we get

          movl    %edx, 4(%esp)           # 4-byte Spill
  .Ltmp1:
          #DEBUG_VALUE: func:value <- [DW_OP_plus_uconst 4, DW_OP_constu 8, DW_OP_minus] [$esp+0]
          #DEBUG_VALUE: func:value <- [DW_OP_plus_uconst 4, DW_OP_deref, DW_OP_constu 8, DW_OP_minus] [$esp+0]

and anything not starting with a deref of $esp+4 is ofcourse not making any sense. So that indicates some kind of improvement with this patch (since we used to get the deref at the end here).
So maybe my problem is related to the extra DBG_VALUE that is lacking DW_OP_deref. I haven't figured out where that comes from yet.

Btw, now we got a difference between the `if (SD->isIndirect())` handling at  line 708 and 756. Is that making sense? Or is that one wrong as well?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73526/new/

https://reviews.llvm.org/D73526





More information about the llvm-commits mailing list