<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 - LLD emits corrupt version for weak symbol when using version script"
   href="https://bugs.llvm.org/show_bug.cgi?id=49915">49915</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD emits corrupt version for weak symbol when using version script
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>aaronpuchert@alice-dsl.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When linking against a lld-linked libLLVM.so with ld.bfd I got the following
error:

/usr/bin/ld: /usr/lib64/libLLVM.so: __morestack: invalid needed version 2
/usr/bin/ld: /usr/lib64/libLLVM.so: error adding symbols: bad value
clang-12.0: error: linker command failed with exit code 1 (use -v to see
invocation)

Indeed:

<span class="quote">> readelf --wide --dyn-syms /usr/lib64/libLLVM.so.12 | grep morestack</span >
332: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __morestack@@<corrupt>

This is coming from
llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp. I've managed to
build a small reproducer that should work with 12.0.0rc5:

<span class="quote">> cat morestack.cpp</span >
extern "C" __attribute__((__weak__)) void __morestack();

unsigned long f() {
  return (unsigned long)&__morestack;
}
<span class="quote">> cat script.map</span >
LLVM_13 { global: *; };
<span class="quote">> clang -c -fPIC -g morestack.cpp
> clang -fuse-ld=lld -shared -o test.so -Wl,--version-script,script.map morestack.o
> readelf --wide --dyn-syms test.so | grep __morestack</span >
     5: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND
__morestack@@<corrupt>

Without -fuse-ld=lld, i.e. with ld.bfd I get

     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __morestack

Now lld itself seems to fine with the corrupt version, so maybe binutils are
just overly sensitive? I don't know.</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>