<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 - Linking static library does not resolve symbols as gold/ld"
   href="https://bugs.llvm.org/show_bug.cgi?id=33383">33383</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Linking static library does not resolve symbols as gold/ld
          </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>clang@martinien.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18602" name="attach_18602" title="Repro">attachment 18602</a> <a href="attachment.cgi?id=18602&action=edit" title="Repro">[details]</a></span>
Repro

[ This is spawned from an earlier email thread, see here:
  <a href="http://lists.llvm.org/pipermail/llvm-dev/2017-April/112114.html">http://lists.llvm.org/pipermail/llvm-dev/2017-April/112114.html</a>
  and reply from Rui:
  <a href="http://lists.llvm.org/pipermail/llvm-dev/2017-April/112353.html">http://lists.llvm.org/pipermail/llvm-dev/2017-April/112353.html</a> ]


Hi Rui,

I finally managed to come up with a reduced example, please find it
attached. You need to have GOLDPATH and LLDPATH set to point to the
respective linkers.

What happens in build.sh is that an object file is partially linked ("-u")
with gold first, then this is linked with lld to another object file for
the final executable. The resulting executable 'repro' then crashes during
static initialization.

The following changes make it work:
1) Using ld instead of gold for the first step
2) Using ld or gold for the second step

2) makes me think there must be something those linkers are doing, but lld
is not, that makes the whole thing work. But note that the crash happens
in a constructor. I found this for the "-u" option in the ld manpage here:

<a href="https://linux.die.net/man/1/ld">https://linux.die.net/man/1/ld</a>

"When linking C++ programs, this option will not resolve references to
constructors; to do that, use -Ur."

However, gold does not know that option (and ld already works without it)

Any idea what is going wrong here?

Thanks and best regards
Martin</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>