<div>Hi, llvm-commits!</div><div><br></div><div><div>It looks like debug info generated for variables is incorrect in case the stack needs realignment. Consider:</div><div><div>$ cat test.cc </div><div>#include <stdio.h></div>
<div>void run() {</div><div>  int x __attribute__((aligned(32))); // enforce alignment</div><div>  printf("%p\n", &x);</div><div>}</div></div><div>$ clang++ -g -c test.cc</div><div>$ objdump -d test.o</div><div>
<...></div><div><div>   0:   55                      push   %rbp</div><div>   1:   48 89 e5                mov    %rsp,%rbp</div><div>   4:   48 81 e4 e0 ff ff ff    and    $0xffffffffffffffe0,%rsp   <----- stack gets aligned here</div>
<div><div>   b:   48 83 ec 40             sub    $0x40,%rsp</div><div>   f:   48 8d 3c 25 00 00 00    lea    0x0,%rdi</div><div>  16:   00 </div><div>  17:   48 8d 74 24 20          lea    0x20(%rsp),%rsi</div><div>  1c:   b0 00                   mov    $0x0,%al</div>
<div>  1e:   e8 00 00 00 00          callq  23 <_Z3runv+0x23></div></div><div><...></div><div>$ readelf -wi test.o</div></div><div><...></div><div><div> <3><55>: Abbrev Number: 4 (DW_TAG_variable)</div>
<div>    <56>   DW_AT_name        : (indirect string, offset: 0xa4): x       </div><div>    <5a>   DW_AT_decl_file   : 1        </div><div>    <5b>   DW_AT_decl_line   : 3        </div><div>    <5c>   DW_AT_type        : <0x65>   </div>
<div>    <60>   DW_AT_location    : 2 byte block: 91 20      (DW_OP_fbreg: 32)</div></div><div><br></div><div>That is, dwarf debug info says that "x" is located at offset 0x20 from frame register (%rbp), which is wrong:</div>
</div><div>1) the offset from %rbp should clearly be negative</div><div>2) we can't calculate it that easy, as stack is aligned (%rsp is changed) after old rsp value is assigned to rbp.</div><div>3) 0x20 is actually the offset from *%rsp*, not %rbp</div>
<div><br></div><div>I may be wrong, but X86FrameLowering::getFrameIndexOffset in case the stack needs realignment (<a href="http://llvm.org/docs/doxygen/html/X86FrameLowering_8cpp_source.html#l01144">http://llvm.org/docs/doxygen/html/X86FrameLowering_8cpp_source.html#l01144</a>)</div>
<div>seems to be calculating the offset from %rsp. If this is true, we should enforce the usage of rsp when calculating variable locations, even if we have frame pointers. This can be fixed by applying the patch.</div><div>
<br></div><div>Codereview link: <a href="http://codereview.appspot.com/6127054/">http://codereview.appspot.com/6127054/</a></div><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>