This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: Fix ld for ELF/PPC
- From: Jack Howarth <howarth at bromo dot msbb dot uc dot edu>
- To: Alan Modra <amodra at bigpond dot net dot au>
- Cc: binutils at sources dot redhat dot com
- Date: Mon, 30 Sep 2002 10:30:17 -0400 (EDT)
- Subject: Re: PATCH: Fix ld for ELF/PPC
- References: <200209291441.KAA01834@bromo.msbb.uc.edu> <20020929170140.A25376@lucon.org> <200209300356.XAA04557@bromo.msbb.uc.edu>
Alan,
I tested Jakub's test 2.13.90.0.5 tarballs with the attached patch
applied which I believe represents all the critical parts of your final
fix. Let me know if I am wrong. The resulting binutils builds fine
and passes make check as expected. Once installed I am able to build
hesiod shared libs that are prelinkable. So the fix looks good so far.
Jack
---------------------------------------------------------------------
diff -uNr binutils-2.13.90.0.5/ld/emulparams/elf32ppc.sh binutils-2.13.90.0.5.new/ld/emulparams/elf32ppc.sh
--- binutils-2.13.90.0.5/ld/emulparams/elf32ppc.sh Fri Sep 27 08:33:09 2002+++ binutils-2.13.90.0.5.new/ld/emulparams/elf32ppc.sh Mon Sep 30 07:02:30 2002@@ -17,6 +17,10 @@
.got1 ${RELOCATING-0} : { *(.got1) }
.got2 ${RELOCATING-0} : { *(.got2) }
"
+OTHER_GOT_RELOC_SECTIONS="
+ .rela.got1 ${RELOCATING-0} : { *(.rela.got1) }
+ .rela.got2 ${RELOCATING-0} : { *(.rela.got2) }
+"
# Treat a host that matches the target with the possible exception of "64"
# in the name as if it were native.
diff -uNr binutils-2.13.90.0.5/ld/emultempl/elf32.em binutils-2.13.90.0.5.new/ld/emultempl/elf32.em
--- binutils-2.13.90.0.5/ld/emultempl/elf32.em Mon Jul 29 08:19:19 2002
+++ binutils-2.13.90.0.5.new/ld/emultempl/elf32.em Mon Sep 30 06:53:17 2002@@ -1016,20 +1016,39 @@
{
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;
- for (u = lang_output_section_statement.head;
- u != (lang_statement_union_type *) NULL;
- u = lookup->next)
+ for (u = lang_output_section_statement.head; u; u = lookup->next)
{
lookup = &u->output_section_statement;
- if (strncmp (".rel", lookup->name, 4) == 0
- && lookup->bfd_section != NULL
- && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
+ if (strncmp (".rel", lookup->name, 4) == 0)
{
- return lookup;
+ /* 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';
+
+ if (strcmp (".plt", lookup->name + 4 + rela) == 0
+ || (lookup->bfd_section != NULL
+ && (lookup->bfd_section->flags & SEC_ALLOC) == 0))
+ break;
+ last_rel = lookup;
+ if (lookup->bfd_section != NULL
+ && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
+ last_rel_alloc = lookup;
}
+ last = lookup;
}
- return (lang_output_section_statement_type *) NULL;
+
+ if (last_rel_alloc)
+ return last_rel_alloc;
+
+ if (last_rel)
+ return last_rel;
+
+ return last;
}
/* Find the last output section before given output statement.
@@ -1154,27 +1173,10 @@
&& HAVE_SECTION (hold_data, ".data"))
place = &hold_data;
else if (strncmp (secname, ".rel", 4) == 0
+ && (s->flags & SEC_LOAD) != 0
&& (hold_rel.os != NULL
|| (hold_rel.os = output_rel_find ()) != NULL))
- {
- if (! link_info.relocateable && link_info.combreloc)
- {
- if (strncmp (secname, ".rela", 5) == 0)
- os = lang_output_section_find (".rela.dyn");
- else
- os = lang_output_section_find (".rel.dyn");
-
- if (os != NULL
- && os->bfd_section != NULL
- && ((s->flags ^ os->bfd_section->flags)
- & (SEC_LOAD | SEC_ALLOC)) == 0)
- {
- lang_add_section (&os->children, s, os, file);
- return true;
- }
- }
- place = &hold_rel;
- }
+ place = &hold_rel;
else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY
&& HAVE_SECTION (hold_rodata, ".rodata"))
place = &hold_rodata;
diff -uNr binutils-2.13.90.0.5/ld/testsuite/ld-i386/i386.exp binutils-2.13.90.0.5.new/ld/testsuite/ld-i386/i386.exp
--- binutils-2.13.90.0.5/ld/testsuite/ld-i386/i386.exp Fri Sep 27 08:33:09 2002+++ binutils-2.13.90.0.5.new/ld/testsuite/ld-i386/i386.exp Mon Sep 30 06:56:24 2002
@@ -57,6 +57,8 @@
"--32" {tlsnopic1.s tlsnopic2.s}
{{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
{objdump -sj.got tlsnopic.sd}} "libtlsnopic.so"}
+ {"Reloc section order" "-shared -melf_i386" "--32" {reloc.s}
+ {{objdump -hw reloc.d}} "reloc.so"}
}
# FIXME: Generalize and move this to ld-lib.exp
diff -uNr binutils-2.13.90.0.5/ld/testsuite/ld-i386/reloc.d binutils-2.13.90.0.5.new/ld/testsuite/ld-i386/reloc.d
--- binutils-2.13.90.0.5/ld/testsuite/ld-i386/reloc.d Wed Dec 31 17:00:00 1969+++ binutils-2.13.90.0.5.new/ld/testsuite/ld-i386/reloc.d Mon Sep 30 06:57:28 2002
@@ -0,0 +1,18 @@
+# Test that orphan reloc sections are placed before .rel.plt even when
+# .rel.plt is the only reloc section.
+#source: reloc.s
+#as: --32
+#ld: -shared -melf_i386
+#objdump: -hw
+#target: i?86-*-*
+
+.*: +file format elf32-i386
+#...
+.*\.relplatypus.*
+#...
+.*\.rel\.plt.*
+# x86 ld doesn't output non-alloc reloc sections to shared libs, so disable
+# the following two lines for the time being.
+# #...
+# .*\.relechidna.*
+#pass
diff -uNr binutils-2.13.90.0.5/ld/testsuite/ld-i386/reloc.s binutils-2.13.90.0.5.new/ld/testsuite/ld-i386/reloc.s
--- binutils-2.13.90.0.5/ld/testsuite/ld-i386/reloc.s Wed Dec 31 17:00:00 1969+++ binutils-2.13.90.0.5.new/ld/testsuite/ld-i386/reloc.s Mon Sep 30 06:58:43 2002
@@ -0,0 +1,8 @@
+ .section echidna
+ .long .text
+
+ .section platypus,"ax"
+ .long .text
+
+ .text
+ jmp _start@plt
------------------------------------------------------------------------------