Bug 14918 - linking with -flto always links in libgcc_s.so
Summary: linking with -flto always links in libgcc_s.so
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks: 17085
  Show dependency treegraph
 
Reported: 2012-12-05 04:58 UTC by Matthias Klose
Modified: 2017-09-28 16:03 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2012-12-05 04:58:26 UTC
checked with the 2.23 branch (and gcc-4.7), original report at http://gcc.gnu.org/PR55592

$ cat foo.c 
int main() { }
$ gcc foo.c && ldd a.out |grep libgcc_s
$ gcc -flto foo.c && ldd a.out |grep libgcc_s
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fb214381000)

works with gold:
$ gcc -B /usr/lib/gold-ld -flto foo.c && ldd a.out |grep libgcc_s
$ 

libgcc is linked as:
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
Comment 1 H.J. Lu 2012-12-05 16:25:29 UTC
I have this patch in the Linux binutils:

diff --git a/ld/plugin.c b/ld/plugin.c
index da99e77..2966f0f 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -217,6 +220,17 @@ plugin_opt_plugin_arg (const char *arg)
   if (!last_plugin)
     return set_plugin_error (_("<no plugin>"));
 
+  /* Ignore -pass-through= from GCC driver.  */
+  if (*arg == '-')
+    {
+      const char *p;
+      for (p = arg + 1; p; p++)
+	if (*p != '-')
+	  break;
+      if (strncmp (p, "pass-through=", 13) == 0)
+	return 0;
+    }
+
   newarg = xmalloc (sizeof *newarg);
   newarg->arg = arg;
   newarg->next = NULL;

However, I don't know how safe it is in the FSF binutils.
Comment 2 Alan Modra 2014-07-28 06:45:41 UTC
HJ, please install this patch.  I think the -pass-through hack is entirely redundant nowadays.
Comment 3 Alan Modra 2014-08-05 07:12:14 UTC
Tidier patch at https://sourceware.org/ml/binutils/2014-08/msg00025.html
Comment 4 Alan Modra 2014-08-06 10:48:29 UTC
Patch applied.  git commit 97964ab3
Comment 5 Sourceware Commits 2015-02-03 16:26:01 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9910b1c8f3b0821944303fbcb4ef4c8872cf4e08

commit 9910b1c8f3b0821944303fbcb4ef4c8872cf4e08
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Feb 3 08:24:50 2015 -0800

    Add a testcase for PR ld/14918
    
    	PR ld/14918
    	* ld-plugin/lto.exp (lto_link_elf_tests): Add PR ld/14918 test.
    
    	* ld-plugin/pr14918.c: New file.
    	* ld-plugin/pr14918.d: Likewise.
Comment 6 Sourceware Commits 2017-09-28 10:34:21 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=231ca753239211b72eb761593083a0ee859274e7

commit 231ca753239211b72eb761593083a0ee859274e7
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Sep 28 11:33:20 2017 +0100

    Skip the PR 14918 linker test for ARM targets.
    
     I am applying a patch that has been lying around in the Fedora
      binutils sources for a while.  It skips the PR14918 linker test for
      ARM based targets.  This test checks that libgcc is not included in a
      link of an empty executable.  This works for most targets, but on the
      ARM the crt1.o startup code calls __libc_csu_init which is in
      /usr/lib/libc_nonshared.a(elf-init.oS).  This in turn needs
      __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1,
      and so the test fails.