public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Quick --gc-sections question
@ 2011-11-07 19:25 Octoploid
  2011-11-07 20:14 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Octoploid @ 2011-11-07 19:25 UTC (permalink / raw)
  To: binutils

Please consider:

 % cat check.c
__attribute__((visibility("default"))) void fun () {}
int main () {  }

 % gcc -ffunction-sections -rdynamic
-Wl,--gc-sections,--print-gc-sections check.c 2>&1 | grep .text.fun
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
removing unused section from '.text.fun' in file '/tmp/cc22IotY.o'

 % gcc -rdynamic -Wl,--gc-sections,--print-gc-sections check.c 2>&1 |
grep .text.fun
 %

Is this the expected behavior? And if yes, how can one tell the
compiler and linker to always keep the fun() function with
"-ffunction-sections -rdynamic -Wl,--gc-sections"?

For a real world case, see this Mozilla bug:
 https://bugzilla.mozilla.org/show_bug.cgi?id=678977

(Sorry if this is a dup post. But gmane seemed to drop my previous message)
-- 
controlled by gamma light

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Quick --gc-sections question
  2011-11-07 19:25 Quick --gc-sections question Octoploid
@ 2011-11-07 20:14 ` Ian Lance Taylor
  2011-11-07 20:50   ` Octoploid
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2011-11-07 20:14 UTC (permalink / raw)
  To: Octoploid; +Cc: binutils

Octoploid <cryptooctoploid@gmail.com> writes:

> Please consider:
>
>  % cat check.c
> __attribute__((visibility("default"))) void fun () {}
> int main () {  }
>
>  % gcc -ffunction-sections -rdynamic
> -Wl,--gc-sections,--print-gc-sections check.c 2>&1 | grep .text.fun
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
> removing unused section from '.text.fun' in file '/tmp/cc22IotY.o'
>
>  % gcc -rdynamic -Wl,--gc-sections,--print-gc-sections check.c 2>&1 |
> grep .text.fun
>  %
>
> Is this the expected behavior? And if yes, how can one tell the
> compiler and linker to always keep the fun() function with
> "-ffunction-sections -rdynamic -Wl,--gc-sections"?
>
> For a real world case, see this Mozilla bug:
>  https://bugzilla.mozilla.org/show_bug.cgi?id=678977
>
> (Sorry if this is a dup post. But gmane seemed to drop my previous message)

I'll note that this was recently fixed in gold.  If --export-dynamic is
passed to the linker, I think we should not garbage collect globally
visible functions.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Quick --gc-sections question
  2011-11-07 20:14 ` Ian Lance Taylor
@ 2011-11-07 20:50   ` Octoploid
  2011-11-08  5:35     ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Octoploid @ 2011-11-07 20:50 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

On Mon, Nov 7, 2011 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
> Octoploid <cryptooctoploid@gmail.com> writes:
>
>> Please consider:
>>
>>  % cat check.c
>> __attribute__((visibility("default"))) void fun () {}
>> int main () {  }
>>
>>  % gcc -ffunction-sections -rdynamic
>> -Wl,--gc-sections,--print-gc-sections check.c 2>&1 | grep .text.fun
>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
>> removing unused section from '.text.fun' in file '/tmp/cc22IotY.o'
>>
>>  % gcc -rdynamic -Wl,--gc-sections,--print-gc-sections check.c 2>&1 |
>> grep .text.fun
>>  %
>>
>> Is this the expected behavior? And if yes, how can one tell the
>> compiler and linker to always keep the fun() function with
>> "-ffunction-sections -rdynamic -Wl,--gc-sections"?
>>

> I'll note that this was recently fixed in gold.  If --export-dynamic is
> passed to the linker, I think we should not garbage collect globally
> visible functions.

Thanks. I didn't notice the gold fix.

 % ld -v
GNU gold (GNU Binutils 2.22.51.20111107) 1.11
 % gcc -ffunction-sections -rdynamic
-Wl,--gc-sections,--print-gc-sections check.c 2>&1 | grep .text.fun
 % ld -v
GNU ld (GNU Binutils) 2.22.51.20111021
 % gcc -ffunction-sections -rdynamic
-Wl,--gc-sections,--print-gc-sections check.c 2>&1 | grep .text.fun
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
Removing unused section '.text.fun' in file '/tmp/cc7CLEIa.o'




-- 
controlled by gamma light

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Quick --gc-sections question
  2011-11-07 20:50   ` Octoploid
@ 2011-11-08  5:35     ` Alan Modra
  2011-11-08  7:36       ` Octoploid
  2014-01-29 22:36       ` H.J. Lu
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Modra @ 2011-11-08  5:35 UTC (permalink / raw)
  To: Octoploid; +Cc: binutils

On Mon, Nov 07, 2011 at 09:50:26PM +0100, Octoploid wrote:
> On Mon, Nov 7, 2011 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
> > I'll note that this was recently fixed in gold.  If --export-dynamic is
> > passed to the linker, I think we should not garbage collect globally
> > visible functions.

Try this.

	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark syms in
	executables when export_dynamic.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.428
diff -u -p -r1.428 elflink.c
--- bfd/elflink.c	19 Oct 2011 07:17:19 -0000	1.428
+++ bfd/elflink.c	8 Nov 2011 05:31:11 -0000
@@ -11947,7 +11947,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (stru
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && (h->ref_dynamic
-	  || (!info->executable
+	  || ((!info->executable || info->export_dynamic)
 	      && h->def_regular
 	      && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
 	      && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN


-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Quick --gc-sections question
  2011-11-08  5:35     ` Alan Modra
@ 2011-11-08  7:36       ` Octoploid
  2014-01-29 22:36       ` H.J. Lu
  1 sibling, 0 replies; 6+ messages in thread
From: Octoploid @ 2011-11-08  7:36 UTC (permalink / raw)
  To: Octoploid, binutils

On Tue, Nov 8, 2011 at 6:35 AM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, Nov 07, 2011 at 09:50:26PM +0100, Octoploid wrote:
>> On Mon, Nov 7, 2011 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
>> > I'll note that this was recently fixed in gold.  If --export-dynamic is
>> > passed to the linker, I think we should not garbage collect globally
>> > visible functions.
>
> Try this.
> -         || (!info->executable
> +         || ((!info->executable || info->export_dynamic)

Great and easy enough ;-)

 % ld -v
GNU ld (GNU Binutils) 2.22.51.20111108
 % gcc -ffunction-sections -rdynamic
-Wl,--gc-sections,--print-gc-sections check.c 2>&1 | grep .text.fun
 % nm -D a.out|grep fun
0000000000400622 T fun

-- 
controlled by gamma light

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Quick --gc-sections question
  2011-11-08  5:35     ` Alan Modra
  2011-11-08  7:36       ` Octoploid
@ 2014-01-29 22:36       ` H.J. Lu
  1 sibling, 0 replies; 6+ messages in thread
From: H.J. Lu @ 2014-01-29 22:36 UTC (permalink / raw)
  To: Octoploid, Binutils

On Mon, Nov 7, 2011 at 9:35 PM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, Nov 07, 2011 at 09:50:26PM +0100, Octoploid wrote:
>> On Mon, Nov 7, 2011 at 9:13 PM, Ian Lance Taylor <iant@google.com> wrote:
>> > I'll note that this was recently fixed in gold.  If --export-dynamic is
>> > passed to the linker, I think we should not garbage collect globally
>> > visible functions.
>
> Try this.
>
>         * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark syms in
>         executables when export_dynamic.
>
> Index: bfd/elflink.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elflink.c,v
> retrieving revision 1.428
> diff -u -p -r1.428 elflink.c
> --- bfd/elflink.c       19 Oct 2011 07:17:19 -0000      1.428
> +++ bfd/elflink.c       8 Nov 2011 05:31:11 -0000
> @@ -11947,7 +11947,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (stru
>    if ((h->root.type == bfd_link_hash_defined
>         || h->root.type == bfd_link_hash_defweak)
>        && (h->ref_dynamic
> -         || (!info->executable
> +         || ((!info->executable || info->export_dynamic)
>               && h->def_regular
>               && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
>               && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
>
>

I checked in this patch to make sure that the bug stays fixed.

-- 
H.J.
--
commit 50a53d3ffecd6610fbfd40017224055ea252dea9
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jan 29 14:30:41 2014 -0800

    Add rdynamic-1 test

    It is added for

    commit 409ff343a402799563f71f938138b29f8baf7a1c
    Author: Alan Modra <amodra@gmail.com>
    Date:   Tue Nov 8 13:49:11 2011 +0000

          * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark syms in
          executables when export_dynamic.

    * ld-elf/rdynamic-1.c: New file.
    * ld-elf/rdynamic-1.rd: Likewise.

    * ld-elf/shared.exp (build_tests): Add rdynamic-1.

diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index d3a9f29..3cd1930 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2014-01-29  H.J. Lu  <hongjiu.lu@intel.com>
+
+ * ld-elf/rdynamic-1.c: New file.
+ * ld-elf/rdynamic-1.rd: Likewise.
+
+ * ld-elf/shared.exp (build_tests): Add rdynamic-1.
+
 2014-01-28  Nick Clifton  <nickc@redhat.com>

  PR binutils/16317
diff --git a/ld/testsuite/ld-elf/rdynamic-1.c b/ld/testsuite/ld-elf/rdynamic-1.c
new file mode 100644
index 0000000..7c9d1ab
--- /dev/null
+++ b/ld/testsuite/ld-elf/rdynamic-1.c
@@ -0,0 +1,10 @@
+void
+rdynamic ()
+{
+}
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/ld/testsuite/ld-elf/rdynamic-1.rd
b/ld/testsuite/ld-elf/rdynamic-1.rd
new file mode 100644
index 0000000..dbf3602
--- /dev/null
+++ b/ld/testsuite/ld-elf/rdynamic-1.rd
@@ -0,0 +1,5 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +GLOBAL +DEFAULT +[0-9]+ +_?rdynamic
+#...
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index bbfd464..981ce71 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -224,6 +224,9 @@ set build_tests {
   {"Build libpr2404b.a"
    "" ""
    {pr2404b.c} {} "libpr2404b.a"}
+  {"Build rdynamic-1"
+   "-rdynamic -Wl,--gc-sections" "-ffunction-sections"
+   {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
 }

 run_cc_link_tests $build_tests

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-01-29 22:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-07 19:25 Quick --gc-sections question Octoploid
2011-11-07 20:14 ` Ian Lance Taylor
2011-11-07 20:50   ` Octoploid
2011-11-08  5:35     ` Alan Modra
2011-11-08  7:36       ` Octoploid
2014-01-29 22:36       ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).