<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 doesn't handle --dynamic-list correctly for shared libraries"
   href="https://bugs.llvm.org/show_bug.cgi?id=34053">34053</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD doesn't handle --dynamic-list correctly for shared libraries
          </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>grimar@accesssoftek.com, llvm-bugs@lists.llvm.org, rafael.espindola@gmail.com, ruiu@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>According to the binutils documentation [1], --dynamic-list on a shared library
should mean that the symbols in the dynamic list are always preemptible. Some
experimentation shows that it also implies that other symbols shouldn't be
preemptible. An example, for clarity.

% cat dyn.c
void a() {}
void b() {}
void c() { a(); b(); }

% cat dyn.list
{ a; };

% clang -fPIC -c dyn.c
% ld.bfd -shared --dynamic-list dyn.list -o libdyn.so dyn.o
% objdump -d libdyn.so
00000000000002d0 <c>:
 2d0:   55                      push   %rbp
 2d1:   48 89 e5                mov    %rsp,%rbp
 2d4:   e8 c7 ff ff ff          callq  2a0 <a@plt>
 2d9:   e8 e2 ff ff ff          callq  2c0 <b>
 2de:   5d                      pop    %rbp
 2df:   c3                      retq

gold exhibits the same behavior. LLD, on the other hand, still calls both a and
b through the PLT.

The LLD source [2] appears to treat dynamic lists as equivalent to version
scripts with an implicit local: * at the end, except I can't see where it's
injecting the implicit local: *. Even if it were, however, I don't think that's
correct; the dynamic list for shared libraries only controls preemption,
whereas the version script controls visibility. For example, the dynamic symbol
table for libdyn.so linked with BFD above contains all three of a, b, and c,
even though only a was in the dynamic list. Similarly, I can pass BFD a version
script which explicitly marks b as global, but the call to b still won't be
preemptible.

Some further experimentation shows that when both -Bsymbolic and --dynamic-list
are specificied, BFD gives the last option precedence, whereas gold always
gives --dynamic-list precedence. I personally prefer gold's behavior here.

Additionally, gold appears to limit this behavior to --dynamic-list.
--export-dynamic-symbol doesn't change preemptibility, only dynamic symbol
table population. (BFD doesn't have the --export-dynamic-symbol option, so
that's not a consideration for it.)

[1] <a href="https://sourceware.org/binutils/docs/ld/Options.html">https://sourceware.org/binutils/docs/ld/Options.html</a>
[2]
<a href="https://reviews.llvm.org/diffusion/L/browse/lld/trunk/ELF/Driver.cpp;309980$755-757">https://reviews.llvm.org/diffusion/L/browse/lld/trunk/ELF/Driver.cpp;309980$755-757</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>