<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 - Wrapping broken for symbols generated by LTO"
   href="https://bugs.llvm.org/show_bug.cgi?id=51333">51333</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrapping broken for symbols generated by LTO
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>smeenai@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>i@maskray.me, llvm-bugs@lists.llvm.org, nathan@lanza.io, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>unwind.s:

.globl _Unwind_Resume
.globl __wrap__Unwind_Resume
_Unwind_Resume:
__wrap__Unwind_Resume:
        retq

$ llvm-mc -triple x86_64-linux-gnu -filetype=obj -o unwind.o unwind.s
$ ld.lld -shared -o libunwind.so unwind.o

resume.ll:

target datalayout =
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define dso_local void @_Z1fv() optnone noinline personality i8* bitcast (void
()* @throw to i8*) {
  invoke void @throw()
          to label %unreachable unwind label %lpad
lpad:
  %1 = landingpad { i8*, i32 }
          cleanup
  resume { i8*, i32 } %1
unreachable:
  unreachable
}
declare void @throw()

$ llvm-as -o resume.bc resume.ll
$ ld.lld -shared -o libresume.so resume.bc libunwind.so --gc-sections --wrap
_Unwind_Resume

Before
<a href="https://github.com/llvm/llvm-project/commit/f96ff3c0f8ebd941b3f6b345164c3d858b781484">https://github.com/llvm/llvm-project/commit/f96ff3c0f8ebd941b3f6b345164c3d858b781484</a>,
__wrap__Unwind_Resume is present in the dynamic symbol table for libunwind.so
(as shown by running `nm -D libunwind.so`), as expected. After that commit,
it's no longer present in the dynamic symbol table, and we have an invalid PLT
entry instead.

`_Unwind_Resume` isn't present in the bitcode file's symbol table, since the
reference to it is only synthesized during LTO codegen, so I imagine the symbol
is considered unreferenced and the wrapper is incorrectly dead-stripped.

Linking against the DSO defining both `_Unwind_Resume` and
`__wrap__Unwind_Resume` was necessary for the wrapping to work correctly even
before that change, so there's possibly deeper underlying issues. We always
happen to link against such a DSO though, so this was working for us prior to
f96ff3c0f8eb.

Adding `-u _Unwind_Resume` works around the issue but is inelegant.</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>