public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
@ 2011-09-14 19:14 H.J. Lu
  2011-09-15  0:25 ` Alan Modra
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: H.J. Lu @ 2011-09-14 19:14 UTC (permalink / raw)
  To: binutils

Hi,

We shoul also remove symbols without PLT nor GOT references from dynamic
symbol table.  OK to install?

Thanks.


H.J.
---
bfd/

2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13177
	* elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
	nor GOT references.

ld/testsuite/

2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/13177
	* ld-elf/pr13177.d: New.
	* ld-elf/pr13177.s: Likewise.

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 528f705..5a703b3 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -11694,13 +11694,18 @@ struct elf_gc_sweep_symbol_info
 static bfd_boolean
 elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
 {
-  if ((h->root.type == bfd_link_hash_defined
-       || h->root.type == bfd_link_hash_defweak)
-      && !h->root.u.def.section->gc_mark
-      && !(h->root.u.def.section->owner->flags & DYNAMIC))
+  if (((h->root.type == bfd_link_hash_defined
+	|| h->root.type == bfd_link_hash_defweak)
+       && !h->root.u.def.section->gc_mark
+       && (!(h->root.u.def.section->owner->flags & DYNAMIC)
+	   || (h->plt.refcount <= 0
+	       && h->got.refcount <= 0)))
+      || (h->root.type == bfd_link_hash_undefined
+	  && h->plt.refcount <= 0
+	  && h->got.refcount <= 0))
     {
       struct elf_gc_sweep_symbol_info *inf =
-          (struct elf_gc_sweep_symbol_info *) data;
+	(struct elf_gc_sweep_symbol_info *) data;
       (*inf->hide_symbol) (inf->info, h, TRUE);
     }
 
diff --git a/ld/testsuite/ld-elf/pr13177.d b/ld/testsuite/ld-elf/pr13177.d
new file mode 100644
index 0000000..425a239
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr13177.d
@@ -0,0 +1,11 @@
+#source: pr13177.s
+#ld: --gc-sections -shared
+#readelf: -s -D --wide
+#notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
+#notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
+# generic linker targets don't support --gc-sections, nor do a bunch of others
+
+#failif
+#...
+.*: 0+0 +0 +NOTYPE +GLOBAL +DEFAULT +UND bar
+#...
diff --git a/ld/testsuite/ld-elf/pr13177.s b/ld/testsuite/ld-elf/pr13177.s
new file mode 100644
index 0000000..25232ba
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr13177.s
@@ -0,0 +1,9 @@
+	.section .text.foo,"ax",%progbits
+	.globl	foo
+	.type	foo, %function
+foo:
+	.byte 0
+	.section .text.opt_out,"ax",%progbits
+	.type	opt_out, %function
+opt_out:
+	.dc.a bar

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-09-14 19:14 PATCH: PR ld/13177: garbage collector retains zombie references to external libraries H.J. Lu
@ 2011-09-15  0:25 ` Alan Modra
  2011-09-15  0:47   ` H.J. Lu
  2011-09-16  6:21 ` Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries" Hans-Peter Nilsson
  2011-09-28 18:32 ` Regression: --gc-sections: local symbol `_dl_argv@@GLIBC_PRIVATE' in ld.so is referenced by DSO (PR ld/13232) [Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries] Jan Kratochvil
  2 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2011-09-15  0:25 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Wed, Sep 14, 2011 at 12:14:38PM -0700, H.J. Lu wrote:
> We shoul also remove symbols without PLT nor GOT references from dynamic
> symbol table.  OK to install?

No.  A symbol that isn't used in the defining object will have no PLT
or GOT refs in that object, but may need to be exported to satisfy a
reference in some other object.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-09-15  0:25 ` Alan Modra
@ 2011-09-15  0:47   ` H.J. Lu
  2011-09-16  0:52     ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: H.J. Lu @ 2011-09-15  0:47 UTC (permalink / raw)
  To: H.J. Lu, binutils

On Wed, Sep 14, 2011 at 5:25 PM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Sep 14, 2011 at 12:14:38PM -0700, H.J. Lu wrote:
>> We shoul also remove symbols without PLT nor GOT references from dynamic
>> symbol table.  OK to install?
>
> No.  A symbol that isn't used in the defining object will have no PLT
> or GOT refs in that object, but may need to be exported to satisfy a
> reference in some other object.
>

There are


  if (((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && !h->root.u.def.section->gc_mark
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       && (!(h->root.u.def.section->owner->flags & DYNAMIC)
           || (h->plt.refcount <= 0
               && h->got.refcount <= 0)))
      || (h->root.type == bfd_link_hash_undefined
          && h->plt.refcount <= 0
          && h->got.refcount <= 0))

Shouldn't gc_mark be 1 if the section where the symbol is defined is kept?

-- 
H.J.

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-09-15  0:47   ` H.J. Lu
@ 2011-09-16  0:52     ` Alan Modra
  2011-10-17  7:29       ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2011-09-16  0:52 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Wed, Sep 14, 2011 at 05:47:15PM -0700, H.J. Lu wrote:
> On Wed, Sep 14, 2011 at 5:25 PM, Alan Modra <amodra@gmail.com> wrote:
> > On Wed, Sep 14, 2011 at 12:14:38PM -0700, H.J. Lu wrote:
> >> We shoul also remove symbols without PLT nor GOT references from dynamic
> >> symbol table.  OK to install?
> >
> > No.  A symbol that isn't used in the defining object will have no PLT
> > or GOT refs in that object, but may need to be exported to satisfy a
> > reference in some other object.
> >
> 
> There are
> 
> 
>   if (((h->root.type == bfd_link_hash_defined
>         || h->root.type == bfd_link_hash_defweak)
>        && !h->root.u.def.section->gc_mark
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>        && (!(h->root.u.def.section->owner->flags & DYNAMIC)
>            || (h->plt.refcount <= 0
>                && h->got.refcount <= 0)))
>       || (h->root.type == bfd_link_hash_undefined
>           && h->plt.refcount <= 0
>           && h->got.refcount <= 0))
> 
> Shouldn't gc_mark be 1 if the section where the symbol is defined is kept?

Uh, I read your patch description and rejected the patch based on the
description..  Patch OK.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries"
  2011-09-14 19:14 PATCH: PR ld/13177: garbage collector retains zombie references to external libraries H.J. Lu
  2011-09-15  0:25 ` Alan Modra
@ 2011-09-16  6:21 ` Hans-Peter Nilsson
  2011-09-16 14:45   ` H.J. Lu
  2011-09-16 16:24   ` H.J. Lu
  2011-09-28 18:32 ` Regression: --gc-sections: local symbol `_dl_argv@@GLIBC_PRIVATE' in ld.so is referenced by DSO (PR ld/13232) [Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries] Jan Kratochvil
  2 siblings, 2 replies; 19+ messages in thread
From: Hans-Peter Nilsson @ 2011-09-16  6:21 UTC (permalink / raw)
  To: hjl.tools; +Cc: binutils

> Date: Wed, 14 Sep 2011 12:14:38 -0700
> From: "H.J. Lu" <hongjiu.lu@intel.com>

> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	PR ld/13177
> 	* elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
> 	nor GOT references.
> 
> ld/testsuite/
> 
> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	PR ld/13177
> 	* ld-elf/pr13177.d: New.
> 	* ld-elf/pr13177.s: Likewise.

Caused regressions for cris-elf and cris-axis-linux-gnu:

cris-elf:
Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
FAIL: ld-cris/pic-gc-72

ld.log:
Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215

...
Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf/elf.exp ...
FAIL: ld-elf/pr12975

ld.log:
./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -version-script pr12975.t -o tmpdir/dump tmpdir/dump0.o 
Executing on host: sh -c {./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -version-script pr12975.t -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp (timeout = 300)
./ld-new: -shared not supported

Your test wrongly assumes that all ELF target support -shared or
at least don't complain.  Other tests don't fall for that.

FAIL: ld-elf/pr13177

Same here.

cris-axis-linux-gnu:
Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
FAIL: ld-cris/pic-gc-72
ld.log says the same as for cris-elf for this FAIL.

Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf/elf.exp ...
FAIL: ld-elf/pr13177

ld.log:
./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -o tmpdir/dump tmpdir/dump0.o 
Executing on host: sh -c {./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp (timeout = 300)
./ld-new: tmpdir/dump0.o, section .text.opt_out:
  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC
succeeded with: <./ld-new: tmpdir/dump0.o, section .text.opt_out:
  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC>, expected: <>
./ld-new: tmpdir/dump0.o, section .text.opt_out:
  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC
succeeded with: <./ld-new: tmpdir/dump0.o, section .text.opt_out:
  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC>, expected: <>

Looks like the test emits an absolute address in .text in a
shared library, a no-no.  Try using .data instead or something.
Don't x86_64 and sh err too?

brgds, H-P

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

* Re: Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries"
  2011-09-16  6:21 ` Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries" Hans-Peter Nilsson
@ 2011-09-16 14:45   ` H.J. Lu
  2011-09-16 16:08     ` H.J. Lu
  2011-09-16 16:24   ` H.J. Lu
  1 sibling, 1 reply; 19+ messages in thread
From: H.J. Lu @ 2011-09-16 14:45 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils

On Thu, Sep 15, 2011 at 11:21 PM, Hans-Peter Nilsson
<hans-peter.nilsson@axis.com> wrote:
>> Date: Wed, 14 Sep 2011 12:14:38 -0700
>> From: "H.J. Lu" <hongjiu.lu@intel.com>
>
>> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       PR ld/13177
>>       * elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
>>       nor GOT references.
>>
>> ld/testsuite/
>>
>> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       PR ld/13177
>>       * ld-elf/pr13177.d: New.
>>       * ld-elf/pr13177.s: Likewise.
>
> Caused regressions for cris-elf and cris-axis-linux-gnu:
>
> cris-elf:
> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
> FAIL: ld-cris/pic-gc-72
>
> ld.log:
> Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
> exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215

This looks an cris backend bug.

> ...
> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf/elf.exp ...
> FAIL: ld-elf/pr12975
>
> ld.log:
> ./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -version-script pr12975.t -o tmpdir/dump tmpdir/dump0.o
> Executing on host: sh -c {./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -version-script pr12975.t -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp (timeout = 300)
> ./ld-new: -shared not supported
>
> Your test wrongly assumes that all ELF target support -shared or
> at least don't complain.  Other tests don't fall for that.
>
> FAIL: ld-elf/pr13177
>
> Same here.
>
> cris-axis-linux-gnu:
> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
> FAIL: ld-cris/pic-gc-72
> ld.log says the same as for cris-elf for this FAIL.
>
> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf/elf.exp ...
> FAIL: ld-elf/pr13177
>
> ld.log:
> ./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -o tmpdir/dump tmpdir/dump0.o
> Executing on host: sh -c {./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp (timeout = 300)
> ./ld-new: tmpdir/dump0.o, section .text.opt_out:
>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC
> succeeded with: <./ld-new: tmpdir/dump0.o, section .text.opt_out:
>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC>, expected: <>
> ./ld-new: tmpdir/dump0.o, section .text.opt_out:
>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC
> succeeded with: <./ld-new: tmpdir/dump0.o, section .text.opt_out:
>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC>, expected: <>
>
> Looks like the test emits an absolute address in .text in a
> shared library, a no-no.  Try using .data instead or something.
> Don't x86_64 and sh err too?
>

I can limit it to Linux.


-- 
H.J.

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

* Re: Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries"
  2011-09-16 14:45   ` H.J. Lu
@ 2011-09-16 16:08     ` H.J. Lu
  2011-09-16 17:13       ` Hans-Peter Nilsson
  0 siblings, 1 reply; 19+ messages in thread
From: H.J. Lu @ 2011-09-16 16:08 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils

On Fri, Sep 16, 2011 at 7:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Sep 15, 2011 at 11:21 PM, Hans-Peter Nilsson
> <hans-peter.nilsson@axis.com> wrote:
>>> Date: Wed, 14 Sep 2011 12:14:38 -0700
>>> From: "H.J. Lu" <hongjiu.lu@intel.com>
>>
>>> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>       PR ld/13177
>>>       * elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
>>>       nor GOT references.
>>>
>>> ld/testsuite/
>>>
>>> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>>>
>>>       PR ld/13177
>>>       * ld-elf/pr13177.d: New.
>>>       * ld-elf/pr13177.s: Likewise.
>>
>> Caused regressions for cris-elf and cris-axis-linux-gnu:
>>
>> cris-elf:
>> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
>> FAIL: ld-cris/pic-gc-72
>>
>> ld.log:
>> Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
>> exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215
>
> This looks an cris backend bug.
>
>> ...
>> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf/elf.exp ...
>> FAIL: ld-elf/pr12975
>>
>> ld.log:
>> ./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -version-script pr12975.t -o tmpdir/dump tmpdir/dump0.o
>> Executing on host: sh -c {./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -version-script pr12975.t -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp (timeout = 300)
>> ./ld-new: -shared not supported
>>
>> Your test wrongly assumes that all ELF target support -shared or
>> at least don't complain.  Other tests don't fall for that.
>>
>> FAIL: ld-elf/pr13177
>>
>> Same here.
>>
>> cris-axis-linux-gnu:
>> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
>> FAIL: ld-cris/pic-gc-72
>> ld.log says the same as for cris-elf for this FAIL.
>>
>> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf/elf.exp ...
>> FAIL: ld-elf/pr13177
>>
>> ld.log:
>> ./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -o tmpdir/dump tmpdir/dump0.o
>> Executing on host: sh -c {./ld-new  -L/tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-elf  --gc-sections -shared -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp (timeout = 300)
>> ./ld-new: tmpdir/dump0.o, section .text.opt_out:
>>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC
>> succeeded with: <./ld-new: tmpdir/dump0.o, section .text.opt_out:
>>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC>, expected: <>
>> ./ld-new: tmpdir/dump0.o, section .text.opt_out:
>>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC
>> succeeded with: <./ld-new: tmpdir/dump0.o, section .text.opt_out:
>>  relocation R_CRIS_32 should not be used in a shared object; recompile with -fPIC>, expected: <>
>>
>> Looks like the test emits an absolute address in .text in a
>> shared library, a no-no.  Try using .data instead or something.
>> Don't x86_64 and sh err too?
>>
>
> I can limit it to Linux.

I checked in this patch.


-- 
H.J.
---
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index c5349be..be38879 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2011-09-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* ld-elf/pr12975.d: Only run for *-*-linux* and *-*-gnu*
+	targets.
+	* ld-elf/pr13177.d: Likewise.
+
+	* ld-elf/pr13177.s: Avoid relocations in text sections.
+
 2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>

 	PR ld/13177
diff --git a/ld/testsuite/ld-elf/pr12975.d b/ld/testsuite/ld-elf/pr12975.d
index 549e8d5..b361cc2 100644
--- a/ld/testsuite/ld-elf/pr12975.d
+++ b/ld/testsuite/ld-elf/pr12975.d
@@ -1,5 +1,6 @@
 #ld: --gc-sections -shared -version-script pr12975.t
 #readelf: -s --wide
+#target: *-*-linux* *-*-gnu*
 #notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
 #notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
diff --git a/ld/testsuite/ld-elf/pr13177.d b/ld/testsuite/ld-elf/pr13177.d
index 425a239..e56e865 100644
--- a/ld/testsuite/ld-elf/pr13177.d
+++ b/ld/testsuite/ld-elf/pr13177.d
@@ -1,6 +1,7 @@
 #source: pr13177.s
 #ld: --gc-sections -shared
 #readelf: -s -D --wide
+#target: *-*-linux* *-*-gnu*
 #notarget: arc-*-* d30v-*-* dlx-*-* i960-*-* or32-*-* pj*-*-*
 #notarget: hppa64-*-* i370-*-* i860-*-* ia64-*-* mep-*-* mn10200-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
diff --git a/ld/testsuite/ld-elf/pr13177.s b/ld/testsuite/ld-elf/pr13177.s
index 25232ba..d7caad3 100644
--- a/ld/testsuite/ld-elf/pr13177.s
+++ b/ld/testsuite/ld-elf/pr13177.s
@@ -3,7 +3,7 @@
 	.type	foo, %function
 foo:
 	.byte 0
-	.section .text.opt_out,"ax",%progbits
-	.type	opt_out, %function
+	.section .data.opt_out,"aw",%progbits
+	.type	opt_out, %object
 opt_out:
 	.dc.a bar

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

* Re: Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries"
  2011-09-16  6:21 ` Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries" Hans-Peter Nilsson
  2011-09-16 14:45   ` H.J. Lu
@ 2011-09-16 16:24   ` H.J. Lu
  2011-10-14  7:01     ` Fix for cris-* regressions with "PATCH: PR ld/13177" Hans-Peter Nilsson
  1 sibling, 1 reply; 19+ messages in thread
From: H.J. Lu @ 2011-09-16 16:24 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils

On Thu, Sep 15, 2011 at 11:21 PM, Hans-Peter Nilsson
<hans-peter.nilsson@axis.com> wrote:
>> Date: Wed, 14 Sep 2011 12:14:38 -0700
>> From: "H.J. Lu" <hongjiu.lu@intel.com>
>
>> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       PR ld/13177
>>       * elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
>>       nor GOT references.
>>
>> ld/testsuite/
>>
>> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       PR ld/13177
>>       * ld-elf/pr13177.d: New.
>>       * ld-elf/pr13177.s: Likewise.
>
> Caused regressions for cris-elf and cris-axis-linux-gnu:
>
> cris-elf:
> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
> FAIL: ld-cris/pic-gc-72
>
> ld.log:
> Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
> exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215
>
> ...

The problem is cris backend doesn't use plt.refcount nor got.refcount.

-- 
H.J.

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

* Re: Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries"
  2011-09-16 16:08     ` H.J. Lu
@ 2011-09-16 17:13       ` Hans-Peter Nilsson
  0 siblings, 0 replies; 19+ messages in thread
From: Hans-Peter Nilsson @ 2011-09-16 17:13 UTC (permalink / raw)
  To: hjl.tools; +Cc: hp, binutils

> Date: Fri, 16 Sep 2011 09:07:53 -0700
> From: "H.J. Lu" <hjl.tools@gmail.com>

> On Fri, Sep 16, 2011 at 7:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > On Thu, Sep 15, 2011 at 11:21 PM, Hans-Peter Nilsson
> > <hans-peter.nilsson@axis.com> wrote:
> >> cris-elf:
> >> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
> >> FAIL: ld-cris/pic-gc-72
> >>
> >> ld.log:
> >> Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
> >> exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215
> >
> > This looks an cris backend bug.

> The problem is cris backend doesn't use plt.refcount nor got.refcount.

It certainly does refcounting for PLT/GOT entries, but it's time
for me to have a look.  Thanks for checking.

> diff --git a/ld/testsuite/ld-elf/pr13177.s b/ld/testsuite/ld-elf/pr13177.s
> index 25232ba..d7caad3 100644
> --- a/ld/testsuite/ld-elf/pr13177.s
> +++ b/ld/testsuite/ld-elf/pr13177.s
> @@ -3,7 +3,7 @@
>  	.type	foo, %function
>  foo:
>  	.byte 0
> -	.section .text.opt_out,"ax",%progbits
> -	.type	opt_out, %function
> +	.section .data.opt_out,"aw",%progbits
> +	.type	opt_out, %object
>  opt_out:
>  	.dc.a bar
> 

The other new test does not fail anymore (i.e. disabled / working).

JFTR, ld.log now has:

Executing on host: sh -c
{/tmp/hpautotest-binutils/cris-axis-linux-gnu/ld/../binutils/readelf -s -D --wide tmpdir/dump 
> tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
fail if no difference
FAIL: ld-elf/pr13177

If there's an issue with the CRIS backend and refcounting, I
guess this is a likely result.  I'll check.  Film at 11.

brgds, H-P

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

* Regression: --gc-sections: local symbol `_dl_argv@@GLIBC_PRIVATE' in ld.so is referenced by DSO (PR ld/13232)  [Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries]
  2011-09-14 19:14 PATCH: PR ld/13177: garbage collector retains zombie references to external libraries H.J. Lu
  2011-09-15  0:25 ` Alan Modra
  2011-09-16  6:21 ` Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries" Hans-Peter Nilsson
@ 2011-09-28 18:32 ` Jan Kratochvil
  2011-09-28 18:46   ` Jan Kratochvil
  2 siblings, 1 reply; 19+ messages in thread
From: Jan Kratochvil @ 2011-09-28 18:32 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

Hi H.J.,

3475fe928892df696f6ea9b2c912e1379591e736 is the first bad commit

On Wed, 14 Sep 2011 21:14:38 +0200, H.J. Lu wrote:
> 2011-09-14  H.J. Lu  <hongjiu.lu@intel.com>
>
>       PR ld/13177
>       * elflink.c (elf_gc_sweep_symbol): Also hide symbols without PLT
>       nor GOT references.

echo 'int main(void){return 0;}'|gcc -o 1.o -c -Wall -x c -;gcc -v -o 1 1.o -Wall -Wl,--gc-sections

# OK but replace collect2 (old system BFD ld) with BFD HEAD ld:

.../ld/ld-new --build-id --no-add-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o 1 /usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.6.1/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.6.1 -L/usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../.. 1.o --gc-sections -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.6.1/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../lib64/crtn.o

ld-new: 1: local symbol `_dl_argv@@GLIBC_PRIVATE' in /lib64/ld-linux-x86-64.so.2 is referenced by DSO
ld-new: final link failed: Bad value

Tested on fedora-16-x86_64.  gold works OK.


Thanks,
Jan

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

* Re: Regression: --gc-sections: local symbol `_dl_argv@@GLIBC_PRIVATE' in ld.so is referenced by DSO (PR ld/13232)  [Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries]
  2011-09-28 18:32 ` Regression: --gc-sections: local symbol `_dl_argv@@GLIBC_PRIVATE' in ld.so is referenced by DSO (PR ld/13232) [Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries] Jan Kratochvil
@ 2011-09-28 18:46   ` Jan Kratochvil
  0 siblings, 0 replies; 19+ messages in thread
From: Jan Kratochvil @ 2011-09-28 18:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

replied by H.J. as DUPLICATE:
	Bug 13195 - -ffunction-sections -Wl,--gc-sections failure with symbol versioning
	http://sourceware.org/bugzilla/show_bug.cgi?id=13195
	Re: PATCH: PR ld/13195: -ffunction-sections -Wl,--gc-sections failure with symbol versioning
	http://sourceware.org/ml/binutils/2011-09/msg00103.html

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

* Fix for cris-* regressions with "PATCH: PR ld/13177"
  2011-09-16 16:24   ` H.J. Lu
@ 2011-10-14  7:01     ` Hans-Peter Nilsson
  2011-10-14  8:07       ` Tristan Gingold
  0 siblings, 1 reply; 19+ messages in thread
From: Hans-Peter Nilsson @ 2011-10-14  7:01 UTC (permalink / raw)
  To: binutils, gingold; +Cc: hp

> Date: Fri, 16 Sep 2011 09:24:22 -0700
> From: "H.J. Lu" <hjl.tools@gmail.com>

> > cris-elf:
> > Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
> > FAIL: ld-cris/pic-gc-72
> >
> > ld.log:
> > Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
> > exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215
> >
> > ...
> 
> The problem is cris backend doesn't use plt.refcount nor got.refcount.

Wrong, it does, modulo bugs of course.  The problem is "just"
mismatching bookkeeping between cris_elf_gc_sweep_hook and
cris_elf_check_relocs.  Fixed thus, committed.

Yuck for that bookkeeping; a generally error-prone machinery.
There has to be a better way to "count down".  Something like
registering the "increment" for each reloc and then just apply a
general method without having to inspect the reloc and the
related symbol?  (Who said "C++"? :-)

Tristan, ok for 2.22 as well?  What's policy there; are
target-specific fixes up to target maintainers or is explicit
approval required for that too?

bfd:
	* elf32-cris.c (cris_elf_gc_sweep_hook) <R_CRIS_16_GOTPLT>
	<R_CRIS_32_GOTPLT>: Fix missing update of gotplt refcount for
	global symbols.
	<R_CRIS_8, R_CRIS_16, R_CRIS_32>: New cases for similar missing
	updates of the plt refcount.
	(elf_cris_adjust_gotplt_to_got): Assert integrity of the gotplt
	refcount in relation to the plt refcount.

Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.115
diff -p -u -r1.115 elf32-cris.c
--- elf32-cris.c	13 Jun 2011 00:59:10 -0000	1.115
+++ elf32-cris.c	14 Oct 2011 06:43:36 -0000
@@ -2663,6 +2663,9 @@ cris_elf_gc_sweep_hook (bfd *abfd,
 	  /* For local symbols, treat these like GOT relocs.  */
 	  if (h == NULL)
 	    goto local_got_reloc;
+	  else
+	    /* For global symbols, adjust the reloc-specific refcount.  */
+	    elf_cris_hash_entry (h)->gotplt_refcount--;
 	  /* Fall through.  */
 
 	case R_CRIS_32_PLT_GOTREL:
@@ -2671,10 +2674,14 @@ cris_elf_gc_sweep_hook (bfd *abfd,
 	    local_got_refcounts[-1]--;
 	  /* Fall through.  */
 
+	case R_CRIS_8:
+	case R_CRIS_16:
+	case R_CRIS_32:
 	case R_CRIS_8_PCREL:
 	case R_CRIS_16_PCREL:
 	case R_CRIS_32_PCREL:
 	case R_CRIS_32_PLT_PCREL:
+	  /* Negate the increment we did in cris_elf_check_relocs.  */
 	  if (h != NULL)
 	    {
 	      if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
@@ -2733,6 +2740,11 @@ elf_cris_adjust_gotplt_to_got (h, p)
 {
   struct bfd_link_info *info = (struct bfd_link_info *) p;
 
+  /* A GOTPLT reloc, when activated, is supposed to be included into
+     the PLT refcount.  */
+  BFD_ASSERT (h->gotplt_refcount == 0
+	      || h->gotplt_refcount <= h->root.plt.refcount);
+
   /* If nobody wanted a GOTPLT with this symbol, we're done.  */
   if (h->gotplt_refcount <= 0)
     return TRUE;


ld/testsuite:

	* ld-cris/pic-gc-72.d: Adjust for dropping unused undefined
	dynamic symbol "dsofn".

Index: ld-cris/pic-gc-72.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-cris/pic-gc-72.d,v
retrieving revision 1.1
diff -p -u -r1.1 pic-gc-72.d
--- ld-cris/pic-gc-72.d	25 Nov 2008 04:10:47 -0000	1.1
+++ ld-cris/pic-gc-72.d	14 Oct 2011 06:41:41 -0000
@@ -19,10 +19,11 @@ Contents of section .dynsym:
 Contents of section .dynstr:
 #...
 Contents of section .text:
- 0188 0f050f05                             .*
+ 016e 0f050f05                             .*
 Contents of section .dynamic:
+ 2174 .*
 #...
 Contents of section .got:
- 21e4 8c210000 00000000 00000000           .*
+ 21cc 74210000 00000000 00000000           .*
 Contents of section .data:
- 21f0 00000000                             .*
+ 21d8 00000000                             .*

brgds, H-P

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

* Re: Fix for cris-* regressions with "PATCH: PR ld/13177"
  2011-10-14  7:01     ` Fix for cris-* regressions with "PATCH: PR ld/13177" Hans-Peter Nilsson
@ 2011-10-14  8:07       ` Tristan Gingold
  0 siblings, 0 replies; 19+ messages in thread
From: Tristan Gingold @ 2011-10-14  8:07 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils, hp


On Oct 14, 2011, at 9:01 AM, Hans-Peter Nilsson wrote:

>> Date: Fri, 16 Sep 2011 09:24:22 -0700
>> From: "H.J. Lu" <hjl.tools@gmail.com>
> 
>>> cris-elf:
>>> Running /tmp/hpautotest-binutils/bsrc/src/ld/testsuite/ld-cris/cris.exp ...
>>> FAIL: ld-cris/pic-gc-72
>>> 
>>> ld.log:
>>> Executing on host: sh -c {/tmp/hpautotest-binutils/cris-axis-elf/ld/../binutils/objdump  -s -t -R -p -T tmpdir/dump > tmpdir/dump.out 2>ld.tmp}  /dev/null  (timeout = 300)
>>> exited abnormally with 0, output:BFD: tmpdir/dump(.rela.dyn): relocation 0 has invalid symbol index 16777215
>>> 
>>> ...
>> 
>> The problem is cris backend doesn't use plt.refcount nor got.refcount.
> 
> Wrong, it does, modulo bugs of course.  The problem is "just"
> mismatching bookkeeping between cris_elf_gc_sweep_hook and
> cris_elf_check_relocs.  Fixed thus, committed.
> 
> Yuck for that bookkeeping; a generally error-prone machinery.
> There has to be a better way to "count down".  Something like
> registering the "increment" for each reloc and then just apply a
> general method without having to inspect the reloc and the
> related symbol?  (Who said "C++"? :-)
> 
> Tristan, ok for 2.22 as well?

Yes.

>  What's policy there; are
> target-specific fixes up to target maintainers or is explicit
> approval required for that too?

Asking is very welcome because it would avoid possible collision with the creation of a release.

Tristan.

> 
> bfd:
> 	* elf32-cris.c (cris_elf_gc_sweep_hook) <R_CRIS_16_GOTPLT>
> 	<R_CRIS_32_GOTPLT>: Fix missing update of gotplt refcount for
> 	global symbols.
> 	<R_CRIS_8, R_CRIS_16, R_CRIS_32>: New cases for similar missing
> 	updates of the plt refcount.
> 	(elf_cris_adjust_gotplt_to_got): Assert integrity of the gotplt
> 	refcount in relation to the plt refcount.
> 
> Index: elf32-cris.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elf32-cris.c,v
> retrieving revision 1.115
> diff -p -u -r1.115 elf32-cris.c
> --- elf32-cris.c	13 Jun 2011 00:59:10 -0000	1.115
> +++ elf32-cris.c	14 Oct 2011 06:43:36 -0000
> @@ -2663,6 +2663,9 @@ cris_elf_gc_sweep_hook (bfd *abfd,
> 	  /* For local symbols, treat these like GOT relocs.  */
> 	  if (h == NULL)
> 	    goto local_got_reloc;
> +	  else
> +	    /* For global symbols, adjust the reloc-specific refcount.  */
> +	    elf_cris_hash_entry (h)->gotplt_refcount--;
> 	  /* Fall through.  */
> 
> 	case R_CRIS_32_PLT_GOTREL:
> @@ -2671,10 +2674,14 @@ cris_elf_gc_sweep_hook (bfd *abfd,
> 	    local_got_refcounts[-1]--;
> 	  /* Fall through.  */
> 
> +	case R_CRIS_8:
> +	case R_CRIS_16:
> +	case R_CRIS_32:
> 	case R_CRIS_8_PCREL:
> 	case R_CRIS_16_PCREL:
> 	case R_CRIS_32_PCREL:
> 	case R_CRIS_32_PLT_PCREL:
> +	  /* Negate the increment we did in cris_elf_check_relocs.  */
> 	  if (h != NULL)
> 	    {
> 	      if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
> @@ -2733,6 +2740,11 @@ elf_cris_adjust_gotplt_to_got (h, p)
> {
>   struct bfd_link_info *info = (struct bfd_link_info *) p;
> 
> +  /* A GOTPLT reloc, when activated, is supposed to be included into
> +     the PLT refcount.  */
> +  BFD_ASSERT (h->gotplt_refcount == 0
> +	      || h->gotplt_refcount <= h->root.plt.refcount);
> +
>   /* If nobody wanted a GOTPLT with this symbol, we're done.  */
>   if (h->gotplt_refcount <= 0)
>     return TRUE;
> 
> 
> ld/testsuite:
> 
> 	* ld-cris/pic-gc-72.d: Adjust for dropping unused undefined
> 	dynamic symbol "dsofn".
> 
> Index: ld-cris/pic-gc-72.d
> ===================================================================
> RCS file: /cvs/src/src/ld/testsuite/ld-cris/pic-gc-72.d,v
> retrieving revision 1.1
> diff -p -u -r1.1 pic-gc-72.d
> --- ld-cris/pic-gc-72.d	25 Nov 2008 04:10:47 -0000	1.1
> +++ ld-cris/pic-gc-72.d	14 Oct 2011 06:41:41 -0000
> @@ -19,10 +19,11 @@ Contents of section .dynsym:
> Contents of section .dynstr:
> #...
> Contents of section .text:
> - 0188 0f050f05                             .*
> + 016e 0f050f05                             .*
> Contents of section .dynamic:
> + 2174 .*
> #...
> Contents of section .got:
> - 21e4 8c210000 00000000 00000000           .*
> + 21cc 74210000 00000000 00000000           .*
> Contents of section .data:
> - 21f0 00000000                             .*
> + 21d8 00000000                             .*
> 
> brgds, H-P

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-09-16  0:52     ` Alan Modra
@ 2011-10-17  7:29       ` Alan Modra
  2011-10-17 13:50         ` Alan Modra
  2011-10-17 17:21         ` H.J. Lu
  0 siblings, 2 replies; 19+ messages in thread
From: Alan Modra @ 2011-10-17  7:29 UTC (permalink / raw)
  To: H.J. Lu, binutils

HJ,
  Your patch for PR13177 causes
hppa-linux  +FAIL: --gc-sections with __start_
mips64-linux  +FAIL: --gc-sections with __start_
mipsel-linux-gnu  +FAIL: --gc-sections with __start_
mipsisa32el-linux  +FAIL: --gc-sections with __start_
mips-linux  +FAIL: --gc-sections with __start_
powerpc64-linux  +FAIL: --gc-sections with __start_

The failures show up because __start__foo is undefined when
lang_gc_sections runs (the symbol is defined later in
lang_place_orphans).  This exposes an error in the way you treat
undefined symbols.  Not all ABIs require an undefined symbol reference
to generate a PLT entry.  You only need one when there is a function
call, or when the address of a function is taken and the ABI defines
the address to be the PLT entry in the executable
(ptr_equality_needed case).  So it is quite reasonable for
__start__foo to have a plt.refcount of zero in elf_gc_sweep_symbol.

I'm testing the following.

	PR ld/13177
	* elflink.c (_bfd_elf_gc_mark_rsec): Set symbol "mark".
	(elf_gc_sweep_symbol): Don't test plt/got refcounts, instead test
	"mark".  Hide undefweak too.
	(elf_link_output_extsym): Correct test for warning when forced local
	executable syms are referenced from shared libraries.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.425
diff -u -p -r1.425 elflink.c
--- bfd/elflink.c	8 Oct 2011 16:51:09 -0000	1.425
+++ bfd/elflink.c	17 Oct 2011 07:08:58 -0000
@@ -8659,10 +8659,11 @@ elf_link_output_extsym (struct bfd_hash_
 
   /* We should also warn if a forced local symbol is referenced from
      shared libraries.  */
-  if (! finfo->info->relocatable
-      && (! finfo->info->shared)
+  if (!finfo->info->relocatable
+      && finfo->info->executable
       && h->forced_local
       && h->ref_dynamic
+      && h->def_regular
       && !h->dynamic_def
       && !h->dynamic_weak
       && ! elf_link_check_versioned_symbol (finfo->info, bed, h))
@@ -11571,6 +11577,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
       while (h->root.type == bfd_link_hash_indirect
 	     || h->root.type == bfd_link_hash_warning)
 	h = (struct elf_link_hash_entry *) h->root.u.i.link;
+      h->mark = 1;
       return (*gc_mark_hook) (sec, info, cookie->rel, h, NULL);
     }
 
@@ -11718,18 +11725,16 @@ struct elf_gc_sweep_symbol_info
 static bfd_boolean
 elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
 {
-  if (((h->root.type == bfd_link_hash_defined
-	|| h->root.type == bfd_link_hash_defweak)
-       && !h->root.u.def.section->gc_mark
-       && (!(h->root.u.def.section->owner->flags & DYNAMIC)
-	   || (h->plt.refcount <= 0
-	       && h->got.refcount <= 0)))
-      || (h->root.type == bfd_link_hash_undefined
-	  && h->plt.refcount <= 0
-	  && h->got.refcount <= 0))
+  if (!h->mark
+      && (((h->root.type == bfd_link_hash_defined
+	    || h->root.type == bfd_link_hash_defweak)
+	   && !h->root.u.def.section->gc_mark)
+	  || h->root.type == bfd_link_hash_undefined
+	  || h->root.type == bfd_link_hash_undefweak))
     {
-      struct elf_gc_sweep_symbol_info *inf =
-	(struct elf_gc_sweep_symbol_info *) data;
+      struct elf_gc_sweep_symbol_info *inf;
+
+      inf = (struct elf_gc_sweep_symbol_info *) data;
       (*inf->hide_symbol) (inf->info, h, TRUE);
     }
 


-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-10-17  7:29       ` Alan Modra
@ 2011-10-17 13:50         ` Alan Modra
  2011-10-17 17:21         ` H.J. Lu
  1 sibling, 0 replies; 19+ messages in thread
From: Alan Modra @ 2011-10-17 13:50 UTC (permalink / raw)
  To: H.J. Lu, binutils

On Mon, Oct 17, 2011 at 05:58:47PM +1030, Alan Modra wrote:
> I'm testing the following.
> 
> 	PR ld/13177
> 	* elflink.c (_bfd_elf_gc_mark_rsec): Set symbol "mark".
> 	(elf_gc_sweep_symbol): Don't test plt/got refcounts, instead test
> 	"mark".  Hide undefweak too.
> 	(elf_link_output_extsym): Correct test for warning when forced local
> 	executable syms are referenced from shared libraries.

I found this resulted in a couple of errors in the gcc testsuite.
+FAIL: 23_containers/vector/allocator/copy.cc (test for excess errors)
+FAIL: 23_containers/vector/allocator/minimal.cc (test for excess errors)

Both of these are link errors
copy.o:(.eh_frame+0x123): unresolvable R_PPC_ADDR32 relocation against
symbol `__gxx_personality_v0@@CXXABI_1.3'

My new linker gc-sections code has correctly decided that
__gxx_personality_v0 is not needed, the eh_frame editing code also
correctly discards the CIE referring to this symbol.  The trouble is
that the entire .eh_frame section is relocated, not just those parts
copied to output.  So we get a silly relocation error for a CIE that
isn't used.

Curable by suppressing the error as follows, but of course this needs
duplicating for all ELF backends.  :-(

Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.302
diff -u -p -r1.302 elf32-ppc.c
--- bfd/elf32-ppc.c	14 Aug 2011 09:17:17 -0000	1.302
+++ bfd/elf32-ppc.c	17 Oct 2011 13:44:13 -0000
@@ -8150,7 +8150,9 @@ ppc_elf_relocate_section (bfd *output_bf
 
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  info->callbacks->einfo
 	    (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-10-17  7:29       ` Alan Modra
  2011-10-17 13:50         ` Alan Modra
@ 2011-10-17 17:21         ` H.J. Lu
  2011-10-17 22:59           ` Alan Modra
  1 sibling, 1 reply; 19+ messages in thread
From: H.J. Lu @ 2011-10-17 17:21 UTC (permalink / raw)
  To: Binutils

On Mon, Oct 17, 2011 at 12:28 AM, Alan Modra <amodra@gmail.com> wrote:
> HJ,
>  Your patch for PR13177 causes
> hppa-linux  +FAIL: --gc-sections with __start_
> mips64-linux  +FAIL: --gc-sections with __start_
> mipsel-linux-gnu  +FAIL: --gc-sections with __start_
> mipsisa32el-linux  +FAIL: --gc-sections with __start_
> mips-linux  +FAIL: --gc-sections with __start_
> powerpc64-linux  +FAIL: --gc-sections with __start_
>
> The failures show up because __start__foo is undefined when
> lang_gc_sections runs (the symbol is defined later in
> lang_place_orphans).  This exposes an error in the way you treat
> undefined symbols.  Not all ABIs require an undefined symbol reference
> to generate a PLT entry.  You only need one when there is a function
> call, or when the address of a function is taken and the ABI defines
> the address to be the PLT entry in the executable
> (ptr_equality_needed case).  So it is quite reasonable for
> __start__foo to have a plt.refcount of zero in elf_gc_sweep_symbol.
>
> I'm testing the following.
>
>        PR ld/13177
>        * elflink.c (_bfd_elf_gc_mark_rsec): Set symbol "mark".
>        (elf_gc_sweep_symbol): Don't test plt/got refcounts, instead test
>        "mark".  Hide undefweak too.
>        (elf_link_output_extsym): Correct test for warning when forced local
>        executable syms are referenced from shared libraries.
>

Should we make elf_gc_sweep_symbol target dependent to take ABI
differences into account?


-- 
H.J.

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-10-17 17:21         ` H.J. Lu
@ 2011-10-17 22:59           ` Alan Modra
  2011-10-18 19:08             ` H.J. Lu
  0 siblings, 1 reply; 19+ messages in thread
From: Alan Modra @ 2011-10-17 22:59 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils

On Mon, Oct 17, 2011 at 10:21:37AM -0700, H.J. Lu wrote:
> Should we make elf_gc_sweep_symbol target dependent to take ABI
> differences into account?

No.  I believe the only solution to this PR is marking symbols used by
relocs in kept sections.  I'm quite certain the existing code in
elf_gc_sweep_symbol will break corner cases on powerpc64-linux,
hppa-linux and probably other targets.  Modifying what we have there,
even with a target hook, won't work.

You should revert your patch on the branch, and I'll continue with the
symbol marking change for mainline.  This will likely mean that 2.22
goes out without this PR fixed.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-10-17 22:59           ` Alan Modra
@ 2011-10-18 19:08             ` H.J. Lu
  2011-10-19  7:20               ` Alan Modra
  0 siblings, 1 reply; 19+ messages in thread
From: H.J. Lu @ 2011-10-18 19:08 UTC (permalink / raw)
  To: Binutils

On Mon, Oct 17, 2011 at 3:59 PM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, Oct 17, 2011 at 10:21:37AM -0700, H.J. Lu wrote:
>> Should we make elf_gc_sweep_symbol target dependent to take ABI
>> differences into account?
>
> No.  I believe the only solution to this PR is marking symbols used by
> relocs in kept sections.  I'm quite certain the existing code in
> elf_gc_sweep_symbol will break corner cases on powerpc64-linux,
> hppa-linux and probably other targets.  Modifying what we have there,
> even with a target hook, won't work.
>
> You should revert your patch on the branch, and I'll continue with the
> symbol marking change for mainline.  This will likely mean that 2.22
> goes out without this PR fixed.
>

Done.

-- 
H.J.

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

* Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries
  2011-10-18 19:08             ` H.J. Lu
@ 2011-10-19  7:20               ` Alan Modra
  0 siblings, 0 replies; 19+ messages in thread
From: Alan Modra @ 2011-10-19  7:20 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils

On Tue, Oct 18, 2011 at 12:08:23PM -0700, H.J. Lu wrote:
> Done.

Thanks HJ.  I've just committed the following to mainline.  Please see
if you can break it.  ;-)

bfd/
	PR ld/13177
	* elflink.c (_bfd_elf_gc_mark_rsec): Set symbol "mark".
	(elf_gc_sweep_symbol): Don't test plt/got refcounts, instead test
	"mark".  Hide undefweak too.  Clear def_regular and ref_regular.
	* elf-m10300.c (mn10300_elf_relocate_section): Ignore unresolved
	reloc errors from garbage-collected code.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-bfin.c (bfin_relocate_section): Likewise.
	(bfinfdpic_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-sh.c (sh_elf_relocate_section): Likewise.
	* elf32-spu.c (spu_elf_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-sh64.c (sh_elf64_relocate_section): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
ld/testsuite/
	* ld-elf/elf.exp: Move test for shared lib support..
	* lib/ld-lib.exp (check_shared_lib_support): ..to here. Add m68hc1*,
	and s/ms1/mt/.
	(check_gc_sections_available): Match hppa*64 not hppa64.  Comment.
	* ld-gc/libpersonality.s: New.
	* ld-gc/personality.s, * ld-gc/personality.d: New.
	* ld-gc/gc.exp: Run personality test.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.426
diff -u -p -r1.426 elflink.c
--- bfd/elflink.c	19 Oct 2011 04:13:28 -0000	1.426
+++ bfd/elflink.c	19 Oct 2011 05:00:46 -0000
@@ -11576,6 +11577,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
       while (h->root.type == bfd_link_hash_indirect
 	     || h->root.type == bfd_link_hash_warning)
 	h = (struct elf_link_hash_entry *) h->root.u.i.link;
+      h->mark = 1;
       return (*gc_mark_hook) (sec, info, cookie->rel, h, NULL);
     }
 
@@ -11723,19 +11725,20 @@ struct elf_gc_sweep_symbol_info
 static bfd_boolean
 elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
 {
-  if (((h->root.type == bfd_link_hash_defined
-	|| h->root.type == bfd_link_hash_defweak)
-       && !h->root.u.def.section->gc_mark
-       && (!(h->root.u.def.section->owner->flags & DYNAMIC)
-	   || (h->plt.refcount <= 0
-	       && h->got.refcount <= 0)))
-      || (h->root.type == bfd_link_hash_undefined
-	  && h->plt.refcount <= 0
-	  && h->got.refcount <= 0))
+  if (!h->mark
+      && (((h->root.type == bfd_link_hash_defined
+	    || h->root.type == bfd_link_hash_defweak)
+	   && !h->root.u.def.section->gc_mark)
+	  || h->root.type == bfd_link_hash_undefined
+	  || h->root.type == bfd_link_hash_undefweak))
     {
-      struct elf_gc_sweep_symbol_info *inf =
-	(struct elf_gc_sweep_symbol_info *) data;
+      struct elf_gc_sweep_symbol_info *inf;
+
+      inf = (struct elf_gc_sweep_symbol_info *) data;
       (*inf->hide_symbol) (inf->info, h, TRUE);
+      h->def_regular = 0;
+      h->ref_regular = 0;
+      h->ref_regular_nonweak = 0;
     }
 
   return TRUE;
Index: bfd/elf-m10300.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-m10300.c,v
retrieving revision 1.108
diff -u -p -r1.108 elf-m10300.c
--- bfd/elf-m10300.c	13 Jun 2011 00:59:09 -0000	1.108
+++ bfd/elf-m10300.c	19 Oct 2011 05:00:23 -0000
@@ -1499,7 +1499,10 @@ mn10300_elf_relocate_section (bfd *outpu
 	       obscure cases sec->output_section will be NULL.  */
 	    relocation = 0;
 
-	  else if (!info->relocatable && unresolved_reloc)
+	  else if (!info->relocatable && unresolved_reloc
+		   && _bfd_elf_section_offset (output_bfd, info, input_section,
+					       rel->r_offset) != (bfd_vma) -1)
+
 	    (*_bfd_error_handler)
 	      (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	       input_bfd,
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.277
diff -u -p -r1.277 elf32-arm.c
--- bfd/elf32-arm.c	13 Oct 2011 09:47:51 -0000	1.277
+++ bfd/elf32-arm.c	19 Oct 2011 05:00:26 -0000
@@ -10386,7 +10386,9 @@ elf32_arm_relocate_section (bfd *       
 	 not process them.  */
       if (unresolved_reloc
           && !((input_section->flags & SEC_DEBUGGING) != 0
-               && h->def_dynamic))
+               && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  (*_bfd_error_handler)
 	    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf32-bfin.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-bfin.c,v
retrieving revision 1.54
diff -u -p -r1.54 elf32-bfin.c
--- bfd/elf32-bfin.c	13 Jun 2011 00:59:10 -0000	1.54
+++ bfd/elf32-bfin.c	19 Oct 2011 05:00:27 -0000
@@ -1585,7 +1585,9 @@ bfin_relocate_section (bfd * output_bfd,
          because such sections are not SEC_ALLOC and thus ld.so will
          not process them.  */
       if (unresolved_reloc
-	  && !((input_section->flags & SEC_DEBUGGING) != 0 && h->def_dynamic))
+	  && !((input_section->flags & SEC_DEBUGGING) != 0 && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  (*_bfd_error_handler)
 	    (_("%B(%A+0x%lx): unresolvable relocation against symbol `%s'"),
@@ -2731,7 +2733,9 @@ bfinfdpic_relocate_section (bfd * output
 	default:
 	non_fdpic:
 	  picrel = NULL;
-	  if (h && ! BFINFDPIC_SYM_LOCAL (info, h))
+	  if (h && ! BFINFDPIC_SYM_LOCAL (info, h)
+	      && _bfd_elf_section_offset (output_bfd, info, input_section,
+					  rel->r_offset) != (bfd_vma) -1)
 	    {
 	      info->callbacks->warning
 		(info, _("relocation references symbol not defined in the module"),
Index: bfd/elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.116
diff -u -p -r1.116 elf32-cris.c
--- bfd/elf32-cris.c	14 Oct 2011 06:52:46 -0000	1.116
+++ bfd/elf32-cris.c	19 Oct 2011 05:00:28 -0000
@@ -1166,7 +1166,11 @@ cris_elf_relocate_section (bfd *output_b
 		      || r_type == R_CRIS_16_PCREL
 		      || r_type == R_CRIS_32_PCREL))
 		relocation = 0;
-	      else if (!info->relocatable && unresolved_reloc)
+	      else if (!info->relocatable && unresolved_reloc
+		       && (_bfd_elf_section_offset (output_bfd, info,
+						    input_section,
+						    rel->r_offset)
+			   != (bfd_vma) -1))
 		{
 		  _bfd_error_handler
 		    (_("%B, section %A: unresolvable relocation %s against symbol `%s'"),
Index: bfd/elf32-frv.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-frv.c,v
retrieving revision 1.73
diff -u -p -r1.73 elf32-frv.c
--- bfd/elf32-frv.c	23 May 2011 06:14:21 -0000	1.73
+++ bfd/elf32-frv.c	19 Oct 2011 05:00:29 -0000
@@ -2896,7 +2896,10 @@ elf32_frv_relocate_section (output_bfd, 
 	default:
 	non_fdpic:
 	  picrel = NULL;
-	  if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
+	  if (h
+	      && ! FRVFDPIC_SYM_LOCAL (info, h)
+	      && _bfd_elf_section_offset (output_bfd, info, input_section,
+					  rel->r_offset) != (bfd_vma) -1)
 	    {
 	      info->callbacks->einfo
 		(_("%H: relocation references symbol"
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.260
diff -u -p -r1.260 elf32-i386.c
--- bfd/elf32-i386.c	28 Jul 2011 22:35:15 -0000	1.260
+++ bfd/elf32-i386.c	19 Oct 2011 05:00:30 -0000
@@ -4244,7 +4237,9 @@ elf_i386_relocate_section (bfd *output_b
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  (*_bfd_error_handler)
 	    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf32-m32r.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m32r.c,v
retrieving revision 1.102
diff -u -p -r1.102 elf32-m32r.c
--- bfd/elf32-m32r.c	13 Jun 2011 00:59:10 -0000	1.102
+++ bfd/elf32-m32r.c	19 Oct 2011 05:00:31 -0000
@@ -2589,7 +2589,11 @@ m32r_elf_relocate_section (bfd *output_b
 		relocation = (h->root.u.def.value
 			      + sec->output_section->vma
 			      + sec->output_offset);
-	      else if (!info->relocatable)
+	      else if (!info->relocatable
+		       && (_bfd_elf_section_offset (output_bfd, info,
+						    input_section,
+						    rel->r_offset)
+			   != (bfd_vma) -1))
 		{
 		  (*_bfd_error_handler)
 		    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf32-m68k.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m68k.c,v
retrieving revision 1.126
diff -u -p -r1.126 elf32-m68k.c
--- bfd/elf32-m68k.c	13 Jun 2011 00:59:10 -0000	1.126
+++ bfd/elf32-m68k.c	19 Oct 2011 05:00:32 -0000
@@ -4148,7 +4148,9 @@ elf_m68k_relocate_section (output_bfd, i
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  (*_bfd_error_handler)
 	    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.302
diff -u -p -r1.302 elf32-ppc.c
--- bfd/elf32-ppc.c	14 Aug 2011 09:17:17 -0000	1.302
+++ bfd/elf32-ppc.c	19 Oct 2011 05:00:33 -0000
@@ -8150,7 +8150,9 @@ ppc_elf_relocate_section (bfd *output_bf
 
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  info->callbacks->einfo
 	    (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
Index: bfd/elf32-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-s390.c,v
retrieving revision 1.108
diff -u -p -r1.108 elf32-s390.c
--- bfd/elf32-s390.c	13 Jun 2011 00:59:11 -0000	1.108
+++ bfd/elf32-s390.c	19 Oct 2011 05:00:34 -0000
@@ -2996,7 +2996,9 @@ elf_s390_relocate_section (output_bfd, i
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	(*_bfd_error_handler)
 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	   input_bfd,
Index: bfd/elf32-sh.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh.c,v
retrieving revision 1.172
diff -u -p -r1.172 elf32-sh.c
--- bfd/elf32-sh.c	22 Jun 2011 22:02:16 -0000	1.172
+++ bfd/elf32-sh.c	19 Oct 2011 05:00:35 -0000
@@ -4208,7 +4208,11 @@ sh_elf_relocate_section (bfd *output_bfd
 				 STT_DATALABEL on the way to it.  */
 			      | ((h->other & STO_SH5_ISA32) != 0
 				 && ! seen_stt_datalabel));
-	      else if (!info->relocatable)
+	      else if (!info->relocatable
+		       && (_bfd_elf_section_offset (output_bfd, info,
+						    input_section,
+						    rel->r_offset)
+			   != (bfd_vma) -1))
 		{
 		  (*_bfd_error_handler)
 		    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf32-spu.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-spu.c,v
retrieving revision 1.101
diff -u -p -r1.101 elf32-spu.c
--- bfd/elf32-spu.c	28 Feb 2011 18:30:16 -0000	1.101
+++ bfd/elf32-spu.c	19 Oct 2011 05:00:36 -0000
@@ -5000,7 +5000,9 @@ spu_elf_relocate_section (bfd *output_bf
       else if (is_ea_sym)
 	unresolved_reloc = TRUE;
 
-      if (unresolved_reloc)
+      if (unresolved_reloc
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  (*_bfd_error_handler)
 	    (_("%B(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf32-tilepro.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-tilepro.c,v
retrieving revision 1.3
diff -u -p -r1.3 elf32-tilepro.c
--- bfd/elf32-tilepro.c	14 Jun 2011 04:03:23 -0000	1.3
+++ bfd/elf32-tilepro.c	19 Oct 2011 05:00:36 -0000
@@ -3110,7 +3110,9 @@ tilepro_elf_relocate_section (bfd *outpu
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	(*_bfd_error_handler)
 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	   input_bfd,
Index: bfd/elf32-xtensa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v
retrieving revision 1.130
diff -u -p -r1.130 elf32-xtensa.c
--- bfd/elf32-xtensa.c	13 Jun 2011 00:59:11 -0000	1.130
+++ bfd/elf32-xtensa.c	19 Oct 2011 05:00:38 -0000
@@ -3058,7 +3058,9 @@ elf_xtensa_relocate_section (bfd *output
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  (*_bfd_error_handler)
 	    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.181
diff -u -p -r1.181 elf64-alpha.c
--- bfd/elf64-alpha.c	30 Sep 2011 10:39:45 -0000	1.181
+++ bfd/elf64-alpha.c	19 Oct 2011 05:00:39 -0000
@@ -4213,6 +4213,7 @@ elf64_alpha_relocate_section (bfd *outpu
       bfd_vma value;
       bfd_vma addend;
       bfd_boolean dynamic_symbol_p;
+      bfd_boolean unresolved_reloc = FALSE;
       bfd_boolean undef_weak_ref = FALSE;
       unsigned long r_type;
 
@@ -4294,7 +4295,6 @@ elf64_alpha_relocate_section (bfd *outpu
       else
 	{
 	  bfd_boolean warned;
-	  bfd_boolean unresolved_reloc;
 	  struct elf_link_hash_entry *hh;
 	  struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
 
@@ -4527,7 +4527,12 @@ elf64_alpha_relocate_section (bfd *outpu
 	    else if (info->shared
 		     && r_symndx != STN_UNDEF
 		     && (input_section->flags & SEC_ALLOC)
-		     && !undef_weak_ref)
+		     && !undef_weak_ref
+		     && !(unresolved_reloc
+			  && (_bfd_elf_section_offset (output_bfd, info,
+						       input_section,
+						       rel->r_offset)
+			      == (bfd_vma) -1)))
 	      {
 		if (r_type == R_ALPHA_REFLONG)
 		  {
@@ -4573,7 +4578,11 @@ elf64_alpha_relocate_section (bfd *outpu
 	  /* ??? .eh_frame references to discarded sections will be smashed
 	     to relocations against SHN_UNDEF.  The .eh_frame format allows
 	     NULL to be encoded as 0 in any format, so this works here.  */
-	  if (r_symndx == STN_UNDEF)
+	  if (r_symndx == STN_UNDEF
+	      || (unresolved_reloc
+		  && _bfd_elf_section_offset (output_bfd, info,
+					      input_section,
+					      rel->r_offset) == (bfd_vma) -1))
 	    howto = (elf64_alpha_howto_table
 		     + (r_type - R_ALPHA_SREL32 + R_ALPHA_REFLONG));
 	  goto default_reloc;
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.366
diff -u -p -r1.366 elf64-ppc.c
--- bfd/elf64-ppc.c	17 Oct 2011 08:27:45 -0000	1.366
+++ bfd/elf64-ppc.c	19 Oct 2011 05:00:42 -0000
@@ -13459,7 +13459,9 @@ ppc64_elf_relocate_section (bfd *output_
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->elf.def_dynamic))
+	       && h->elf.def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	{
 	  info->callbacks->einfo
 	    (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
Index: bfd/elf64-s390.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-s390.c,v
retrieving revision 1.108
diff -u -p -r1.108 elf64-s390.c
--- bfd/elf64-s390.c	13 Jun 2011 00:59:12 -0000	1.108
+++ bfd/elf64-s390.c	19 Oct 2011 05:00:42 -0000
@@ -2971,7 +2971,9 @@ elf_s390_relocate_section (bfd *output_b
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	(*_bfd_error_handler)
 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	   input_bfd,
Index: bfd/elf64-sh64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sh64.c,v
retrieving revision 1.87
diff -u -p -r1.87 elf64-sh64.c
--- bfd/elf64-sh64.c	13 Jun 2011 00:59:13 -0000	1.87
+++ bfd/elf64-sh64.c	19 Oct 2011 05:00:43 -0000
@@ -1630,7 +1630,11 @@ sh_elf64_relocate_section (bfd *output_b
 				 STT_DATALABEL on the way to it.  */
 			      | ((h->other & STO_SH5_ISA32) != 0
 				 && ! seen_stt_datalabel));
-	      else if (!info->relocatable)
+	      else if (!info->relocatable
+		       && (_bfd_elf_section_offset (output_bfd, info,
+						    input_section,
+						    rel->r_offset)
+			   != (bfd_vma) -1))
 		{
 		  (*_bfd_error_handler)
 		    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
Index: bfd/elf64-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-x86-64.c,v
retrieving revision 1.239
diff -u -p -r1.239 elf64-x86-64.c
--- bfd/elf64-x86-64.c	12 Aug 2011 19:42:39 -0000	1.239
+++ bfd/elf64-x86-64.c	19 Oct 2011 05:00:44 -0000
@@ -4103,7 +4086,9 @@ elf_x86_64_relocate_section (bfd *output
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	(*_bfd_error_handler)
 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	   input_bfd,
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.61
diff -u -p -r1.61 elfxx-sparc.c
--- bfd/elfxx-sparc.c	19 Oct 2011 00:32:24 -0000	1.61
+++ bfd/elfxx-sparc.c	19 Oct 2011 05:00:50 -0000
@@ -3828,7 +3828,9 @@ _bfd_sparc_elf_relocate_section (bfd *ou
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	(*_bfd_error_handler)
 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	   input_bfd,
Index: bfd/elfxx-tilegx.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-tilegx.c,v
retrieving revision 1.3
diff -u -p -r1.3 elfxx-tilegx.c
--- bfd/elfxx-tilegx.c	14 Jun 2011 04:03:23 -0000	1.3
+++ bfd/elfxx-tilegx.c	19 Oct 2011 05:00:51 -0000
@@ -3493,7 +3493,9 @@ tilegx_elf_relocate_section (bfd *output
 	 not process them.  */
       if (unresolved_reloc
 	  && !((input_section->flags & SEC_DEBUGGING) != 0
-	       && h->def_dynamic))
+	       && h->def_dynamic)
+	  && _bfd_elf_section_offset (output_bfd, info, input_section,
+				      rel->r_offset) != (bfd_vma) -1)
 	(*_bfd_error_handler)
 	  (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
 	   input_bfd,
Index: ld/testsuite/ld-elf/elf.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/elf.exp,v
retrieving revision 1.30
diff -u -p -r1.30 elf.exp
--- ld/testsuite/ld-elf/elf.exp	7 Oct 2011 19:55:47 -0000	1.30
+++ ld/testsuite/ld-elf/elf.exp	19 Oct 2011 05:01:11 -0000
@@ -58,40 +58,7 @@ if { ![istarget hppa64*-hpux*] } {
 # should not seg-fault whilst creating the binary.
 #
 # Only run the test on targets thats support creating shared libraries.
-if {    ! [istarget arc-*-*]
-     && ! [istarget avr-*-*]
-     && ! [istarget cr16-*-*]
-     && ! [istarget cris*-*-*]
-     && ! [istarget crx-*-*]
-     && ! [istarget d10v-*-*]
-     && ! [istarget d30v-*-*]
-     && ! [istarget dlx-*-*]
-     && ! [istarget fr30-*-*]
-     && ! [istarget frv-*-*]
-     && ! [istarget h8300-*-*]
-     && ! [istarget i860-*-*]
-     && ! [istarget i960-*-*]
-     && ! [istarget ip2k-*-*]
-     && ! [istarget iq2000-*-*]
-     && ! [istarget lm32-*-*]
-     && ! [istarget m32c-*-*]
-     && ! [istarget m32r-*-*]
-     && ! [istarget mcore*-*-*]
-     && ! [istarget mep-*-*]
-     && ! [istarget microblaze-*-*]
-     && ! [istarget mn10200-*-*]
-     && ! [istarget moxie-*-*]
-     && ! [istarget ms1-*-*]
-     && ! [istarget msp430-*-*]
-     && ! [istarget openrisc-*-*]
-     && ! [istarget or32-*-*]
-     && ! [istarget pj-*-*]
-     && ! [istarget rx-*-*]
-     && ! [istarget spu-*-*]
-     && ! [istarget v850*-*-*]
-     && ! [istarget xstormy16-*-*]
-     && ! [istarget *-*-irix*]
-     && ! [istarget *-*-rtems] } {
+if { [check_shared_lib_support] } then {
   run_ld_link_tests {
       {"Build shared library for next test"
        "-shared" "" "note-3.s" {} "note-3.so" }
Index: ld/testsuite/lib/ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.85
diff -u -p -r1.85 ld-lib.exp
--- ld/testsuite/lib/ld-lib.exp	24 Jul 2011 14:20:12 -0000	1.85
+++ ld/testsuite/lib/ld-lib.exp	19 Oct 2011 05:01:13 -0000
@@ -1418,7 +1418,7 @@ proc check_gc_sections_available { } {
 	     || [istarget or32-*-*]
 	     || [istarget pj*-*-*]
 	     || [istarget alpha-*-*]
-	     || [istarget hppa64-*-*]
+	     || [istarget hppa*64-*-*]
 	     || [istarget i370-*-*]
 	     || [istarget i860-*-*]
 	     || [istarget ia64-*-*]
@@ -1439,6 +1439,8 @@ proc check_gc_sections_available { } {
 	}
 
 	# Check if the ld used by gcc supports --gc-sections.
+	# FIXME: this test is useless since ld --help always says
+	# --gc-sections is available
 	set ld_output [remote_exec host $ld "--help"]
 	if { [ string first "--gc-sections" $ld_output ] >= 0 } {
 	    set gc_sections_available_saved 1
@@ -1449,6 +1451,50 @@ proc check_gc_sections_available { } {
     return $gc_sections_available_saved
 }
 
+# Returns true if -shared is supported on the target
+# Only used and accurate for ELF targets at the moment
+
+proc check_shared_lib_support { } {
+    if {![istarget arc-*-*]
+	 && ![istarget avr-*-*]
+	 && ![istarget cr16-*-*]
+	 && ![istarget cris*-*-*]
+	 && ![istarget crx-*-*]
+	 && ![istarget d10v-*-*]
+	 && ![istarget d30v-*-*]
+	 && ![istarget dlx-*-*]
+	 && ![istarget fr30-*-*]
+	 && ![istarget frv-*-*]
+	 && ![istarget h8300-*-*]
+	 && ![istarget i860-*-*]
+	 && ![istarget i960-*-*]
+	 && ![istarget ip2k-*-*]
+	 && ![istarget iq2000-*-*]
+	 && ![istarget lm32-*-*]
+	 && ![istarget m32c-*-*]
+	 && ![istarget m32r-*-*]
+	 && ![istarget m68hc1*-*-*]
+	 && ![istarget mcore*-*-*]
+	 && ![istarget mep-*-*]
+	 && ![istarget microblaze-*-*]
+	 && ![istarget mn10200-*-*]
+	 && ![istarget moxie-*-*]
+	 && ![istarget msp430-*-*]
+	 && ![istarget mt-*-*]
+	 && ![istarget openrisc-*-*]
+	 && ![istarget or32-*-*]
+	 && ![istarget pj-*-*]
+	 && ![istarget rx-*-*]
+	 && ![istarget spu-*-*]
+	 && ![istarget v850*-*-*]
+	 && ![istarget xstormy16-*-*]
+	 && ![istarget *-*-irix*]
+	 && ![istarget *-*-rtems] } {
+	return 1
+    }
+    return 0
+}
+
 # Returns true if the target ld supports the plugin API.
 proc check_plugin_api_available { } {
     global plugin_api_available_saved
Index: ld/testsuite/ld-gc/gc.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-gc/gc.exp,v
retrieving revision 1.11
diff -u -p -r1.11 gc.exp
--- ld/testsuite/ld-gc/gc.exp	9 Feb 2011 08:18:54 -0000	1.11
+++ ld/testsuite/ld-gc/gc.exp	19 Oct 2011 07:10:11 -0000
@@ -97,6 +97,20 @@ test_gc "Check --gc-section/-r/-u" "gcre
 run_dump_test "noent"
 run_dump_test "abi-note"
 run_dump_test "start"
+
+if { [is_elf_format] && [check_shared_lib_support] } then {
+    set gasopt ""
+    if { [istarget tic6x-*] } then {
+	set gasopt "-mpic -mpid=near"
+    }
+    if {![ld_assemble_flags $as $gasopt $srcdir/$subdir/libpersonality.s tmpdir/libpersonality.o]
+	|| ![ld_simple_link $ld tmpdir/libpersonality.so "-shared tmpdir/libpersonality.o"] } then {
+	fail libpersonality
+    } else {
+	run_dump_test "personality"
+    }
+}
+
 if { [is_remote host] || [which $CC] != 0 } {
     if { [istarget "*-*-linux*"]
 	 || [istarget "*-*-gnu*"] } {
Index: ld/testsuite/ld-gc/libpersonality.s
===================================================================
RCS file: ld/testsuite/ld-gc/libpersonality.s
diff -N ld/testsuite/ld-gc/libpersonality.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-gc/libpersonality.s	19 Oct 2011 07:10:11 -0000
@@ -0,0 +1,11 @@
+	.weak	__gxx_personality_v0
+	.type	__gxx_personality_v0,%function
+__gxx_personality_v0:
+	.long 0
+	.size	__gxx_personality_v0, . - __gxx_personality_v0
+
+	.globl	__gxx_personality_v1
+	.type	__gxx_personality_v1,%function
+__gxx_personality_v1:
+	.long 0
+	.size	__gxx_personality_v1, . - __gxx_personality_v1
Index: ld/testsuite/ld-gc/personality.d
===================================================================
RCS file: ld/testsuite/ld-gc/personality.d
diff -N ld/testsuite/ld-gc/personality.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-gc/personality.d	19 Oct 2011 07:10:11 -0000
@@ -0,0 +1,10 @@
+#name: --gc-sections with __gxx_personality
+#ld: --gc-sections -e main -L tmpdir -lpersonality
+#nm: -n
+#xfail: bfin-*-* cris*-*-* frv-*-* mn10300-*-* vax-*-* xtensa-*-*
+# above targets don't support cfi
+
+#failif
+#...
+.*gxx_personality.*
+#...
Index: ld/testsuite/ld-gc/personality.s
===================================================================
RCS file: ld/testsuite/ld-gc/personality.s
diff -N ld/testsuite/ld-gc/personality.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-gc/personality.s	19 Oct 2011 07:10:11 -0000
@@ -0,0 +1,28 @@
+	.section	.text.loseme,"ax",%progbits
+	.globl	loseme
+	.type	loseme,%function
+loseme:
+	.cfi_startproc
+	.cfi_personality 0,__gxx_personality_v0
+	.long 0
+	.cfi_endproc
+	.size loseme, . - loseme
+
+	.section	.text.loseme2,"ax",%progbits
+	.globl	loseme2
+	.type	loseme2,%function
+loseme2:
+	.cfi_startproc
+	.cfi_personality 0,__gxx_personality_v1
+	.long 0
+	.cfi_endproc
+	.size loseme2, . - loseme2
+
+	.section	.text.main,"ax",%progbits
+	.globl	main
+	.type	main, %function
+main:
+	.cfi_startproc
+	.long 0
+	.cfi_endproc
+	.size main, . - main


-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2011-10-19  7:20 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-14 19:14 PATCH: PR ld/13177: garbage collector retains zombie references to external libraries H.J. Lu
2011-09-15  0:25 ` Alan Modra
2011-09-15  0:47   ` H.J. Lu
2011-09-16  0:52     ` Alan Modra
2011-10-17  7:29       ` Alan Modra
2011-10-17 13:50         ` Alan Modra
2011-10-17 17:21         ` H.J. Lu
2011-10-17 22:59           ` Alan Modra
2011-10-18 19:08             ` H.J. Lu
2011-10-19  7:20               ` Alan Modra
2011-09-16  6:21 ` Regressions with "PATCH: PR ld/13177: garbage collector retains zombie references to external libraries" Hans-Peter Nilsson
2011-09-16 14:45   ` H.J. Lu
2011-09-16 16:08     ` H.J. Lu
2011-09-16 17:13       ` Hans-Peter Nilsson
2011-09-16 16:24   ` H.J. Lu
2011-10-14  7:01     ` Fix for cris-* regressions with "PATCH: PR ld/13177" Hans-Peter Nilsson
2011-10-14  8:07       ` Tristan Gingold
2011-09-28 18:32 ` Regression: --gc-sections: local symbol `_dl_argv@@GLIBC_PRIVATE' in ld.so is referenced by DSO (PR ld/13232) [Re: PATCH: PR ld/13177: garbage collector retains zombie references to external libraries] Jan Kratochvil
2011-09-28 18:46   ` Jan Kratochvil

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).