[llvm-bugs] [Bug 36029] New: After r318497, --as-needed does not seem to work correctly anymore

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jan 20 13:06:18 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36029

            Bug ID: 36029
           Summary: After r318497, --as-needed does not seem to work
                    correctly anymore
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: dimitry at andric.com
                CC: llvm-bugs at lists.llvm.org

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 https://reviews.llvm.org/rL318497 ("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
[...]

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180120/a973f18e/attachment.html>


More information about the llvm-bugs mailing list