<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Caller Frame Information in x86_64 XRay trampolines is invalid"
   href="https://bugs.llvm.org/show_bug.cgi?id=49060">49060</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Caller Frame Information in x86_64 XRay trampolines is invalid
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>XRay
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Runtime
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dberris@google.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>elia.f.geretto@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When attempting to unwind the stack from inside an XRay handler, both using
`libunwind` and `gdb`, the stack trace is corrupted.

As an example, this happens when using `backtrace` in GDB:
#0  xray_handler (function_id=<optimized out>, entry_type=ENTRY) at main.c:140
#1  0x000000000041ad5d in __xray_FunctionEntry ()
#2  0x000000000041d250 in .annobin__ZN6__xray18fdrLoggingFinalizeEv.end ()
#3  0x000000000041d1b0 in
.annobin__ZZN6__xrayL19fdrCommonHeaderInfoEvENUlvE_4_FUNEv.end ()
#4  0x000000000041ff60 in ?? ()
#5  0x0000000000000246 in ?? ()
#6  0x000000000041ff2b in print_message () at main.c:159
#7  0x000000000041ff51 in main (argc=0x1, argv=0x0) at main.c:162

The stack trace is correct up to frame 1, but then it gets corrupted. I
verified that this is due to the following ASM macro in which `rsp` is
manipulated without adding the appropriate CFI directives:
<a href="https://github.com/llvm/llvm-project/blob/af48d2bfc23fd188e5ae162b9f5b27de306ab38f/compiler-rt/lib/xray/xray_trampoline_x86_64.S#L83-L87">https://github.com/llvm/llvm-project/blob/af48d2bfc23fd188e5ae162b9f5b27de306ab38f/compiler-rt/lib/xray/xray_trampoline_x86_64.S#L83-L87</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>