public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [RFC] PR ld/13621
@ 2012-01-30  0:57 Richard Henderson
  2012-01-30  3:26 ` Alan Modra
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Richard Henderson @ 2012-01-30  0:57 UTC (permalink / raw)
  To: binutils; +Cc: Mark Wielaard, Alan Modra

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

This PR is about elflint warning about symbols outside of the section
with which they are associated.

The problem can be seen with just about any zero-sized section, nearly
all of which are removed by strip_excluded_output_sections.  Then, the
symbols are relocated to a "near by" section by _bfd_fix_excluded_sec_syms.

This elflint warning will affect essentially all binaries built with
gcc4.7 because of the crt symbol __TMC_END__, present in the normally
empty section .tm_clone_table.  Thus it seems worthwhile to fix this.

At first I attempted to SEC_KEEP any section with global symbols.  But
this ran into all sorts of testsuite failures re .got.  In those cases
the _GLOBAL_OFFSET_TABLE_ symbol still exists, which causes .got to 
be kept instead of removed as unused later in the link.

A second best solution would seem to be to merely move the offending
symbols to the ABS section rather than associate them with some random
section.

Thoughts?


r~

[-- Attachment #2: z1 --]
[-- Type: text/plain, Size: 1778 bytes --]

bfd/
	* linker.c (fix_syms): Don't add a symbol to a section if the
	symbol does not lie inclusively within the section.
ld/
	* testsuite/ld-elf/warn2.d: Expect Foo in ABS.
	* testsuite/ld-elf/zerosize1.d: New file.
	* testsuite/ld-elf/zerosize1.s: New file.


diff --git a/bfd/linker.c b/bfd/linker.c
index 7a01e11..1d9e66a 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -3201,6 +3201,12 @@ fix_syms (struct bfd_link_hash_entry *h, void *data)
 		op = op1;
 	    }
 
+	  /* Refuse to choose a section for which we are out of bounds.  */
+	  /* ??? This may make most of the above moot.  */
+	  if (h->u.def.value < op->vma
+	      || h->u.def.value > op->vma + op->size)
+	    op = bfd_abs_section_ptr;
+
 	  h->u.def.value -= op->vma;
 	  h->u.def.section = op;
 	}
diff --git a/ld/testsuite/ld-elf/warn2.d b/ld/testsuite/ld-elf/warn2.d
index 95b7ef4..a9c05f9 100644
--- a/ld/testsuite/ld-elf/warn2.d
+++ b/ld/testsuite/ld-elf/warn2.d
@@ -13,5 +13,5 @@
 # construct and that the symbol still appears as expected.
 
 #...
- +[0-9]+: +[0-9a-f]+ +20 +OBJECT +GLOBAL +DEFAULT +[1-9] Foo
+ +[0-9]+: +[0-9a-f]+ +20 +OBJECT +GLOBAL +DEFAULT +ABS Foo
 #pass
diff --git a/ld/testsuite/ld-elf/zerosize1.d b/ld/testsuite/ld-elf/zerosize1.d
new file mode 100644
index 0000000..0da5171
--- /dev/null
+++ b/ld/testsuite/ld-elf/zerosize1.d
@@ -0,0 +1,10 @@
+#source: start.s
+#source: zerosize1.s
+#ld:
+#readelf: -s
+
+# Check that xyzzy is not placed in the ABS section.
+
+#...
+ +[0-9]+: +[0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +ABS xyzzy
+#pass
diff --git a/ld/testsuite/ld-elf/zerosize1.s b/ld/testsuite/ld-elf/zerosize1.s
new file mode 100644
index 0000000..4fc8198
--- /dev/null
+++ b/ld/testsuite/ld-elf/zerosize1.s
@@ -0,0 +1,3 @@
+	.section "zerosize","aw"
+	.globl	xyzzy
+xyzzy:

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

end of thread, other threads:[~2012-05-07  6:20 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-30  0:57 [RFC] PR ld/13621 Richard Henderson
2012-01-30  3:26 ` Alan Modra
2012-01-30  8:28   ` Mark Wielaard
2012-01-30 13:17     ` Alan Modra
2012-01-30 14:14       ` Mark Wielaard
2012-01-30 23:16         ` Alan Modra
2012-01-31  9:58           ` Mark Wielaard
2012-02-07 11:57             ` Alan Modra
2012-01-30 20:00       ` Richard Henderson
2012-01-30 23:41         ` Alan Modra
2012-01-31  0:34           ` Richard Henderson
2012-01-30 19:51   ` Richard Henderson
2012-01-30  8:23 ` Mark Wielaard
2012-03-01  3:58 ` Hans-Peter Nilsson
2012-03-01  4:19   ` Alan Modra
2012-05-05 14:42 ` H.J. Lu
2012-05-07  6:20   ` Alan Modra

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