This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
orphan section logic
- From: DJ Delorie <dj at redhat dot com>
- To: binutils at sourceware dot org
- Date: Mon, 11 Jan 2010 21:14:39 -0500
- Subject: orphan section logic
If you have a section .foo in your object, and a .foo output
statement, yet the .foo output statement doesn't specify any objects,
ld fails to allocate the .foo section to the .foo output statement
(although it seems it used to). Instead, it creates a *new* .foo
output section elsewhere in the memory space.
*Should* it allocate it that way?
.section ".foo", "ax"
.byte 45
.text
.byte 15
SECTIONS {
.foo 0x00010000 : {
}
.text 0x00020000 : {
*(.text);
}
}
sh-elf-as a.s -o a.o
sh-elf-ld a.o -o a.x -Ta.lnk
sh-elf-objdump -h a.x
Without patch:
0 .text 00000001 00020000 00020000 00000080 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .foo 00000001 00020001 00020001 00000081 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
With patch:
0 .text 00000001 00020000 00020000 00000100 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .foo 00000001 00010000 00010000 00000080 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
Index: emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.207
diff -p -U3 -r1.207 elf32.em
--- emultempl/elf32.em 11 Dec 2009 13:42:15 -0000 1.207
+++ emultempl/elf32.em 12 Jan 2010 02:00:18 -0000
@@ -1782,6 +1782,7 @@ gld${EMULATION_NAME}_place_orphan (asect
struct orphan_save *place;
lang_output_section_statement_type *after;
lang_output_section_statement_type *os;
+ lang_output_section_statement_type *match_by_name = NULL;
int isdyn = 0;
int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
@@ -1837,8 +1838,19 @@ gld${EMULATION_NAME}_place_orphan (asect
lang_add_section (&os->children, s, os);
return os;
}
+
+ if (strcmp (os->name, secname) == 0)
+ match_by_name = os;
}
+ /* Failing that, look for an output section by name that might not
+ have sections yet. */
+ if (match_by_name)
+ {
+ lang_add_section (&match_by_name->children, s, match_by_name);
+ return os;
+ }
+
if (!orphan_init_done)
{
lang_output_section_statement_type *lookup;