<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 - Binding not restored for wrapped symbols when using LTO"
   href="https://bugs.llvm.org/show_bug.cgi?id=52004">52004</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Binding not restored for wrapped symbols when using 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, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://reviews.llvm.org/D33621">https://reviews.llvm.org/D33621</a> changed LTO to mark linker wrapped symbols as
weak, to prevent IPO for them, but the intent was for the linker to restore the
original binding. This got dropped by various changes to the wrapping code, in
particular <a href="https://github.com/llvm/llvm-project/commit/99f9e1373ba9">https://github.com/llvm/llvm-project/commit/99f9e1373ba9</a> and
<a href="https://github.com/llvm/llvm-project/commit/b45c164fc252">https://github.com/llvm/llvm-project/commit/b45c164fc252</a>, so wrapped symbols
now retain the weak binding given by LTO. For example:

$ cat wrap.c
void foo() {}

$ clang -fuse-ld=lld -flto -shared -o libwrap.so -Wl,--wrap,foo wrap.c
$ llvm-readelf --dyn-syms libwrap.so
Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND __gmon_start__
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_deregisterTMCloneTable
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_registerTMCloneTable
     4: 0000000000000000     0 FUNC    WEAK   DEFAULT   UND
<a href="mailto:__cxa_finalize@GLIBC_2.2.5">__cxa_finalize@GLIBC_2.2.5</a>
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   UND __wrap_foo
     6: 00000000000015d0     6 FUNC    WEAK   DEFAULT    11 foo

While __wrap_foo is GLOBAL, the original foo has retained the weak binding
given by LTO. Contrast with the non-LTO case:

$ clang -fuse-ld=lld -shared -o libwrap.so -Wl,--wrap,foo wrap.c
$ llvm-readelf --dyn-syms libwrap.so
Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND __gmon_start__
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_deregisterTMCloneTable
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_registerTMCloneTable
     4: 0000000000000000     0 FUNC    WEAK   DEFAULT   UND
<a href="mailto:__cxa_finalize@GLIBC_2.2.5">__cxa_finalize@GLIBC_2.2.5</a>
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   UND __wrap_foo
     6: 00000000000015d0     6 FUNC    GLOBAL DEFAULT    11 foo</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>