This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [testcase] bug caused by the orphan .rel placement patch
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: Jakub Jelinek <jakub at redhat dot com>, binutils at sources dot redhat dot com
- Date: Thu, 10 Oct 2002 12:21:43 +0930
- Subject: Re: [testcase] bug caused by the orphan .rel placement patch
- References: <200209291441.KAA01834@bromo.msbb.uc.edu> <20020929170140.A25376@lucon.org> <20020930110026.G5311@bubble.sa.bigpond.net.au> <20020930125850.J5311@bubble.sa.bigpond.net.au> <20021009223527.S3451@sunsite.ms.mff.cuni.cz> <20021010095420.R979@bubble.sa.bigpond.net.au>
Fixed by the isdyn code. The rest of this patch is just tweakery.
ld/ChangeLog
* emultempl/elf32.em (output_rel_find): Prefer .rel script sections
when orphan is .rel, .rela when orphan is .rela.
(gld${EMULATION_NAME}_place_orphan): Handle combreloc .rel* case
first. Remove outsecname var.
ld/testsuite/ChangeLog
* ld-i386/i386.exp (reloc): Turn off combreloc.
* ld-i386/reloc.d: Likewise.
* ld-powerpc/powerpc.exp: Likewise.
* ld-powerpc/reloc.d: Likewise.
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.81
diff -u -p -r1.81 elf32.em
--- ld/emultempl/elf32.em 30 Sep 2002 03:34:46 -0000 1.81
+++ ld/emultempl/elf32.em 10 Oct 2002 02:43:49 -0000
@@ -75,7 +75,7 @@ static void gld${EMULATION_NAME}_before_
static boolean gld${EMULATION_NAME}_open_dynamic_archive
PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
static lang_output_section_statement_type *output_rel_find
- PARAMS ((void));
+ PARAMS ((asection *));
static asection *output_prev_sec_find
PARAMS ((lang_output_section_statement_type *));
static boolean gld${EMULATION_NAME}_place_orphan
@@ -996,13 +996,15 @@ cat >>e${EMULATION_NAME}.c <<EOF
/* A variant of lang_output_section_find. Used by place_orphan. */
static lang_output_section_statement_type *
-output_rel_find ()
+output_rel_find (sec)
+ asection *sec;
{
lang_statement_union_type *u;
lang_output_section_statement_type *lookup;
lang_output_section_statement_type *last = NULL;
lang_output_section_statement_type *last_rel = NULL;
lang_output_section_statement_type *last_rel_alloc = NULL;
+ int rela = sec->name[4] == 'a';
for (u = lang_output_section_statement.head; u; u = lookup->next)
{
@@ -1012,18 +1014,19 @@ output_rel_find ()
/* Don't place after .rel.plt as doing so results in wrong
dynamic tags. Also, place allocated reloc sections before
non-allocated. */
- int rela = lookup->name[4] == 'a';
+ int lookrela = lookup->name[4] == 'a';
- if (strcmp (".plt", lookup->name + 4 + rela) == 0
+ if (strcmp (".plt", lookup->name + 4 + lookrela) == 0
|| (lookup->bfd_section != NULL
&& (lookup->bfd_section->flags & SEC_ALLOC) == 0))
break;
- last_rel = lookup;
+ last = lookup;
+ if (rela == lookrela)
+ last_rel = lookup;
if (lookup->bfd_section != NULL
&& (lookup->bfd_section->flags & SEC_ALLOC) != 0)
last_rel_alloc = lookup;
}
- last = lookup;
}
if (last_rel_alloc)
@@ -1088,13 +1091,23 @@ gld${EMULATION_NAME}_place_orphan (file,
lang_statement_list_type add;
etree_type *address;
const char *secname;
- const char *outsecname;
const char *ps = NULL;
lang_output_section_statement_type *os;
+ int isdyn = 0;
secname = bfd_get_section_name (s->owner, s);
+ if (! link_info.relocateable
+ && link_info.combreloc
+ && strncmp (secname, ".rel", 4) == 0)
+ {
+ if (secname[4] == 'a')
+ secname = ".rela.dyn";
+ else
+ secname = ".rel.dyn";
+ isdyn = 1;
+ }
- if (! config.unique_orphan_sections && ! unique_section_p (secname))
+ if (isdyn || (!config.unique_orphan_sections && !unique_section_p (secname)))
{
/* Look through the script to see where to place this section. */
os = lang_output_section_find (secname);
@@ -1159,7 +1173,7 @@ gld${EMULATION_NAME}_place_orphan (file,
else if (strncmp (secname, ".rel", 4) == 0
&& (s->flags & SEC_LOAD) != 0
&& (hold_rel.os != NULL
- || (hold_rel.os = output_rel_find ()) != NULL))
+ || (hold_rel.os = output_rel_find (s)) != NULL))
place = &hold_rel;
else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY
&& HAVE_SECTION (hold_rodata, ".rodata"))
@@ -1173,13 +1187,10 @@ gld${EMULATION_NAME}_place_orphan (file,
/* Choose a unique name for the section. This will be needed if the
same section name appears in the input file with different
loadable or allocatable characteristics. */
- outsecname = secname;
- if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
+ if (bfd_get_section_by_name (output_bfd, secname) != NULL)
{
- outsecname = bfd_get_unique_section_name (output_bfd,
- outsecname,
- &count);
- if (outsecname == NULL)
+ secname = bfd_get_unique_section_name (output_bfd, secname, &count);
+ if (secname == NULL)
einfo ("%F%P: place_orphan failed: %E\n");
}
@@ -1200,7 +1211,7 @@ gld${EMULATION_NAME}_place_orphan (file,
{
/* If the name of the section is representable in C, then create
symbols to mark the start and the end of the section. */
- for (ps = outsecname; *ps != '\0'; ps++)
+ for (ps = secname; *ps != '\0'; ps++)
if (! ISALNUM (*ps) && *ps != '_')
break;
if (*ps == '\0')
@@ -1208,8 +1219,8 @@ gld${EMULATION_NAME}_place_orphan (file,
char *symname;
etree_type *e_align;
- symname = (char *) xmalloc (ps - outsecname + sizeof "__start_");
- sprintf (symname, "__start_%s", outsecname);
+ symname = (char *) xmalloc (ps - secname + sizeof "__start_");
+ sprintf (symname, "__start_%s", secname);
e_align = exp_unop (ALIGN_K,
exp_intop ((bfd_vma) 1 << s->alignment_power));
lang_add_assignment (exp_assop ('=', symname, e_align));
@@ -1221,7 +1232,7 @@ gld${EMULATION_NAME}_place_orphan (file,
else
address = NULL;
- os = lang_enter_output_section_statement (outsecname, address, 0,
+ os = lang_enter_output_section_statement (secname, address, 0,
(bfd_vma) 0,
(etree_type *) NULL,
(etree_type *) NULL,
@@ -1242,8 +1253,8 @@ gld${EMULATION_NAME}_place_orphan (file,
if (place != NULL)
stat_ptr = &add;
- symname = (char *) xmalloc (ps - outsecname + sizeof "__stop_");
- sprintf (symname, "__stop_%s", outsecname);
+ symname = (char *) xmalloc (ps - secname + sizeof "__stop_");
+ sprintf (symname, "__stop_%s", secname);
lang_add_assignment (exp_assop ('=', symname,
exp_nameop (NAME, ".")));
}
Index: ld/testsuite/ld-i386/i386.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-i386/i386.exp,v
retrieving revision 1.6
diff -u -p -r1.6 i386.exp
--- ld/testsuite/ld-i386/i386.exp 1 Oct 2002 10:43:37 -0000 1.6
+++ ld/testsuite/ld-i386/i386.exp 10 Oct 2002 02:43:49 -0000
@@ -57,8 +57,8 @@ set i386tests {
{{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
{"TLS @indntpoff with %eax" "-melf_i386" "--32" {tlsindntpoff.s}
{{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"}
- {"Reloc section order" "-shared -melf_i386" "--32" {reloc.s}
- {{objdump -hw reloc.d}} "reloc.so"}
+ {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "--32"
+ {reloc.s} {{objdump -hw reloc.d}} "reloc.so"}
}
run_ld_link_tests $i386tests
Index: ld/testsuite/ld-i386/reloc.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-i386/reloc.d,v
retrieving revision 1.1
diff -u -p -r1.1 reloc.d
--- ld/testsuite/ld-i386/reloc.d 30 Sep 2002 03:35:18 -0000 1.1
+++ ld/testsuite/ld-i386/reloc.d 10 Oct 2002 02:43:49 -0000
@@ -2,7 +2,7 @@
# .rel.plt is the only reloc section.
#source: reloc.s
#as: --32
-#ld: -shared -melf_i386
+#ld: -shared -melf_i386 -z nocombreloc
#objdump: -hw
#target: i?86-*-*
Index: ld/testsuite/ld-powerpc/powerpc.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/powerpc.exp,v
retrieving revision 1.2
diff -u -p -r1.2 powerpc.exp
--- ld/testsuite/ld-powerpc/powerpc.exp 30 Sep 2002 05:54:51 -0000 1.2
+++ ld/testsuite/ld-powerpc/powerpc.exp 10 Oct 2002 02:43:50 -0000
@@ -39,7 +39,7 @@ if { [istarget "*-*-macos*"] || [istarge
# readelf: Apply readelf options on result. Compare with regex (last arg).
set ppcelftests {
- {"Reloc section order" "-shared" "" {reloc.s}
+ {"Reloc section order" "-shared -z nocombreloc" "" {reloc.s}
{{objdump -hw reloc.d}} "reloc.so"}
}
Index: ld/testsuite/ld-powerpc/reloc.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/reloc.d,v
retrieving revision 1.1
diff -u -p -r1.1 reloc.d
--- ld/testsuite/ld-powerpc/reloc.d 30 Sep 2002 05:25:20 -0000 1.1
+++ ld/testsuite/ld-powerpc/reloc.d 10 Oct 2002 02:43:50 -0000
@@ -3,7 +3,7 @@
# reloc sections go after alloc sections.
#source: reloc.s
-#ld: -shared
+#ld: -shared -z nocombreloc
#objdump: -hw
.*: +file format elf.*
--
Alan Modra
IBM OzLabs - Linux Technology Centre