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]

RFC: Assign regions to orphan sections


A frequent error message we see is this one, resulting from incomplete
embedded linker scripts:

error: no memory region specified for loadable section `.eh_frame`

The attached test case demonstrates how it happens (.moredata in the
testcase).  Orphan sections are placed into the default memory region.
This would result (e.g. with --no-check-sections) in their being
placed in the *default* memory region.  The linker rightly complains;
the resulting binary is not useful.  I've even managed to create
accidental overlays this way, where two of the LOAD segments have the
same address assigned.

The warning is sometimes useful (fix your linker script!) but also
contrary to the point of orphan placement.  This seems like the right
fix but I would appreciate comments on it.

The patch is simple once you have the testcase: use AFTER to assign
regions (and phdrs - I think that's safe and I verified that this
doesn't place orphan notes in PT_INTERP).

What do you think?

-- 
Daniel Jacobowitz
CodeSourcery

2010-03-15  Daniel Jacobowitz  <dan@codesourcery.com>

	* ldlang.c (lang_insert_orphan): Place loadable orphans in the same
	region and phdrs as their placement section.

	* ld-elf/orphan-region.d, ld-elf/orphan-region.ld,
	ld-elf/orphan-region.s: New files.

Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.332
diff -u -p -r1.332 ldlang.c
--- ldlang.c	25 Feb 2010 03:49:15 -0000	1.332
+++ ldlang.c	15 Mar 2010 22:06:58 -0000
@@ -1761,7 +1761,20 @@ lang_insert_orphan (asection *s,
     add_child = &os->children;
   lang_add_section (add_child, s, os);
 
-  lang_leave_output_section_statement (0, "*default*", NULL, NULL);
+  if (after && (s->flags & (SEC_LOAD | SEC_ALLOC)) != 0)
+    {
+      const char *region = (after->region
+			    ? after->region->name_list.name
+			    : DEFAULT_MEMORY_REGION);
+      const char *lma_region = (after->lma_region
+				? after->lma_region->name_list.name
+				: NULL);
+      lang_leave_output_section_statement (NULL, region, after->phdrs,
+					   lma_region);
+    }
+  else
+    lang_leave_output_section_statement (NULL, DEFAULT_MEMORY_REGION, NULL,
+					 NULL);
 
   if (ps != NULL && *ps == '\0')
     {
Index: testsuite/ld-elf/orphan-region.d
===================================================================
RCS file: testsuite/ld-elf/orphan-region.d
diff -N testsuite/ld-elf/orphan-region.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ld-elf/orphan-region.d	15 Mar 2010 22:06:58 -0000
@@ -0,0 +1,16 @@
+#source: orphan-region.s
+#ld: -T orphan-region.ld
+#readelf: -S -l --wide
+
+#...
+  \[[ 0-9]+\] \.text[ \t]+PROGBITS[ \t]+0*40000000[ \t]+.*
+  \[[ 0-9]+\] \.rodata[ \t]+PROGBITS[ \t]+0*400000[0-9a-f]+[ \t]+.*
+  \[[ 0-9]+\] \.moredata[ \t]+PROGBITS[ \t]+0*400000[0-9a-f]+[ \t]+.*
+#...
+Program Headers:
+  Type.*
+  LOAD[ \t]+0x[0-9a-f]+ 0x0*40000000 0x0*40000000 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x[0-9a-f]+
+
+ Section to Segment mapping:
+  Segment Sections...
+   00     .text .rodata .moredata *
Index: testsuite/ld-elf/orphan-region.ld
===================================================================
RCS file: testsuite/ld-elf/orphan-region.ld
diff -N testsuite/ld-elf/orphan-region.ld
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ld-elf/orphan-region.ld	15 Mar 2010 22:06:58 -0000
@@ -0,0 +1,10 @@
+MEMORY
+{
+	region : ORIGIN = 0x40000000, LENGTH = 8M
+}
+
+SECTIONS
+{
+	.text : ALIGN (4) { *(.text) } > region
+	.rodata : ALIGN (4) { *(.rodata) } > region
+}
\ No newline at end of file
Index: testsuite/ld-elf/orphan-region.s
===================================================================
RCS file: testsuite/ld-elf/orphan-region.s
diff -N testsuite/ld-elf/orphan-region.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ld-elf/orphan-region.s	15 Mar 2010 22:06:58 -0000
@@ -0,0 +1,8 @@
+	.text
+	.long 0
+	.section ".rodata", "a", %progbits
+	.long 0
+	.section ".moredata", "a", %progbits
+	.long 0
+	.section ".notdata", "", %progbits
+	.long 0


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