<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 - After r318497, --as-needed does not seem to work correctly anymore"
   href="https://bugs.llvm.org/show_bug.cgi?id=36029">36029</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>After r318497, --as-needed does not seem to work correctly anymore
          </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>release blocker
          </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>dimitry@andric.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using recent versions of lld 6.0.0 in FreeBSD, we've noticed that libgcc_s.so
always gets linked into executables and libraries, even if none of its
functions appear to be used.

E.g.:

$ cat main.c
int main(void) { return 0; }

$ cc -c main.c -o main.o

(The following is what cc normally runs to link a plain executable)

$ ld.lld  --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both
--enable-new-dtags -o main /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o
-L/usr/lib main.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

$ readelf -d main

Dynamic section at offset 0x3028 contains 19 entries:
  Tag                Type                  Name/Value
 0x0000000000000001 NEEDED               Shared library: [libgcc_s.so.1]
 0x0000000000000001 NEEDED               Shared library: [libc.so.7]
 0x0000000000000015 DEBUG                0x0
[...]

This appears to have regressed with <a href="https://reviews.llvm.org/rL318497">https://reviews.llvm.org/rL318497</a> ("Remove
IsLocal").  Linking with lld just before that avoids pulling in libgcc_s.so:

$ ~/obj/lld-318496/bin/ld.lld --eh-frame-hdr -dynamic-linker
/libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o main
/usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib main.o -lgcc
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/crtend.o /usr/lib/crtn.o

$ readelf -d main

Dynamic section at offset 0x3028 contains 18 entries:
  Tag                Type                  Name/Value
 0x0000000000000001 NEEDED               Shared library: [libc.so.7]
 0x0000000000000015 DEBUG                0x0
[...]</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>