This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR ld/16643: ARM: BFD_ASSERT when only ref to a GC'd symbol is in a stripped section


Below is a patch that adds a test case for bug 16643, which I've just
filed.  I don't have a fix.  I'm seeking advice on what the proper fix
might be.

The case is under --gc-sections --strip-all.  My test is doing -shared
mostly just because that's what the original case was doing, but it
actually doesn't matter whether it's -shared or a normal final link.

The situation is that there is a symbol, defined in a section that will be
GC'd, whose only reference is in a non-GC'd but non-allocated section that
will be stripped.  (In the real case, it was in .debug_info as part of the
real DWARF data.)  It hits this assert:
	  /* If PLT refcount book-keeping is wrong and too low, we'll
	     see a zero value (going to -1) for the root PLT reference
	     count.  */
	  if (root_plt->refcount >= 0)
	    {
	      BFD_ASSERT (root_plt->refcount != 0);
	      root_plt->refcount -= 1;
	    }
(elf32-arm.c:12445 in today's trunk).  This hits in the call to
elf32_arm_gc_sweep_hook for the input .debug_blah section (the
non-allocated section containing a reference to the symbol), which will be
stripped from the output.  Without --strip-all, the assert does not hit.

I haven't had much luck trying to figure out where the PLT refcount is
supposed to be maintained in general.  Apparently, something about
--strip-all mode affects how this bookkeeping gets done.  Can anyone point
me to where the actual bug here might be?


Thanks,
Roland


ld/testsuite/
2014-02-27  Roland McGrath  <mcgrathr@google.com>

	PR ld/16643
	* ld-arm/gc-hidden-strip.d: New file.
	* ld-arm/gc-hidden-strip-unused.s: New file.
	* ld-arm/gc-hidden-strip-main.s: New file.
	* ld-arm/arm-elf.exp: Run the new test.

--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -842,3 +842,4 @@ if { ![istarget "arm*-*-nacl*"] } {
 }
 run_dump_test "unresolved-2"
 run_dump_test "gc-hidden-1"
+run_dump_test "gc-hidden-strip"
--- /dev/null
+++ b/ld/testsuite/ld-arm/gc-hidden-strip-main.s
@@ -0,0 +1,6 @@
+	.text
+	.globl foo
+	.type foo, %function
+foo:
+	bx lr
+	.size foo, . - foo
--- /dev/null
+++ b/ld/testsuite/ld-arm/gc-hidden-strip-unused.s
@@ -0,0 +1,11 @@
+	.section .data.unused_item,"aw",%progbits
+	.p2align 2
+	.global unused_item
+	.hidden	unused_item
+	.type unused_item, %object
+	.size unused_item, 4
+unused_item:
+	.word 1
+
+	.section .debug_blah,"",%progbits
+	.word unused_item
--- /dev/null
+++ b/ld/testsuite/ld-arm/gc-hidden-strip.d
@@ -0,0 +1,15 @@
+#source: gc-hidden-strip-main.s
+#source: gc-hidden-strip-unused.s
+#ld: --gc-sections --shared --strip-all
+#objdump: -RT
+# This test is only valid on ELF based ports.
+# not-target: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd *-*-riscix*
+
+# See PR ld/16643: the only reference to a GC'd symbol is in a stripped
+# section, trigging a BFD_ASSERT.
+
+.*:     file format elf32-.*
+
+DYNAMIC SYMBOL TABLE:
+0+[0-9a-f]+ l\s+d\s+\.text\s+0+\s+\.text
+#pass


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]