This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: elf64-ppc.c *r_offset patch
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Cc: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 16 Jun 2003 13:38:39 +0930
- Subject: Re: elf64-ppc.c *r_offset patch
- References: <20030614093430.GD24872@sunsite.ms.mff.cuni.cz><20030614095552.GU23826@bubble.sa.bigpond.net.au><20030614102652.GE24872@sunsite.ms.mff.cuni.cz><20030614125547.GV23826@bubble.sa.bigpond.net.au><20030614151535.N15481@devserv.devel.redhat.com><20030614235412.GW23826@bubble.sa.bigpond.net.au><20030615001712.GX23826@bubble.sa.bigpond.net.au><20030615085622.P15481@devserv.devel.redhat.com>
Jakub found an error in handling of DTPMOD dynamic relocs, and we've
been throwing patches at each other over the weekend with the aim of
making prelink work on powerpc64. It's perhaps a little early to apply
this one, as we haven't quite finished arguing. :) Maybe I'm missing
some prelink requirement, but I guess the rest of the discussion can
occur on the mailing list. The prelink aspect of the patch arranges for
section contents at r_offset to be written equal to r_addend for
R_PPC64_RELATIVE relocs, and to zero for other reloc types. We need
RELATIVE relocs to be applied like this in the .opd section to suit the
way our ld.so works, the choice for other relocs is somewhat arbitrary.
Besides fixing the dtpmod bug, this patch also fixes a bad tls
optimization where a toc dtprel sequence was being treated as a toc
tprel one.
bfd/ChangeLog
* elf64-ppc.c (ppc64_elf_relocate_section): When optimizing toctprel
tls, check that a TOC16_DS or TOC16_LO_DS reloc isn't pointing to a
dtprel entry. Ensure TLS_LD DTPMOD reloc has a zero addend. Write
got section for RELATIVE relocs. Fix wrong comment. Change condition
under which dynamic relocs update the section contents.
ld/testsuite/ChangeLog
* ld-powerpc/tlsexetoc.d: Update.
* ld-powerpc/tlsso.d: Update.
* ld-powerpc/tlstoc.d: Update.
* ld-powerpc/tlstocso.d: Update.
* ld-powerpc/tlstocso.r: Update.
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.101
diff -u -p -r1.101 elf64-ppc.c
--- bfd/elf64-ppc.c 10 Jun 2003 07:44:09 -0000 1.101
+++ bfd/elf64-ppc.c 16 Jun 2003 02:16:22 -0000
@@ -7445,7 +7445,10 @@ ppc64_elf_relocate_section (output_bfd,
tls_mask = *toc_tls;
if (r_type == R_PPC64_TOC16_DS
|| r_type == R_PPC64_TOC16_LO_DS)
- goto toctprel;
+ {
+ if (tls_mask != 0 && (tls_mask & TLS_DTPREL) == 0)
+ goto toctprel;
+ }
else
{
/* If we found a GD reloc pair, then we might be
@@ -7985,6 +7988,7 @@ ppc64_elf_relocate_section (output_bfd,
outrel.r_offset = (htab->sgot->output_section->vma
+ htab->sgot->output_offset
+ off);
+ outrel.r_addend = rel->r_addend;
if (tls_type & (TLS_LD | TLS_GD))
{
outrel.r_addend = 0;
@@ -7997,6 +8001,7 @@ ppc64_elf_relocate_section (output_bfd,
bfd_elf64_swap_reloca_out (output_bfd,
&outrel, loc);
outrel.r_offset += 8;
+ outrel.r_addend = rel->r_addend;
outrel.r_info
= ELF64_R_INFO (indx, R_PPC64_DTPREL64);
}
@@ -8006,11 +8011,18 @@ ppc64_elf_relocate_section (output_bfd,
else if (tls_type == (TLS_TLS | TLS_TPREL))
outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
else if (indx == 0)
- outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE);
+ {
+ outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE);
+
+ /* Write the .got section contents for the sake
+ of prelink. */
+ loc = htab->sgot->contents + off;
+ bfd_put_64 (output_bfd, outrel.r_addend, loc);
+ }
else
outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
- outrel.r_addend = rel->r_addend;
- if (indx == 0)
+
+ if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
{
outrel.r_addend += relocation;
if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
@@ -8023,8 +8035,7 @@ ppc64_elf_relocate_section (output_bfd,
}
/* Init the .got section contents here if we're not
- emitting a reloc. A reloc will also init the
- section contents via _bfd_final_link_relocate. */
+ emitting a reloc. */
else
{
relocation += rel->r_addend;
@@ -8254,9 +8265,6 @@ ppc64_elf_relocate_section (output_bfd,
or this is an opd section reloc which must point
at a local function. */
outrel.r_addend += relocation;
- /* We need to relocate .opd contents for ld.so, and
- it doesn't hurt to relocate in other cases. */
- relocate = TRUE;
if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
{
if (is_opd && h != NULL)
@@ -8274,6 +8282,12 @@ ppc64_elf_relocate_section (output_bfd,
unresolved_reloc = FALSE;
}
outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
+
+ /* We need to relocate .opd contents for ld.so.
+ Prelink also wants simple and consistent rules
+ for relocs. This make all RELATIVE relocs have
+ *r_offset equal to r_addend. */
+ relocate = TRUE;
}
else
{
@@ -8315,9 +8329,14 @@ ppc64_elf_relocate_section (output_bfd,
/* If this reloc is against an external symbol, it will
be computed at runtime, so there's no need to do
- anything now. */
+ anything now. However, for the sake of prelink ensure
+ that the section contents are a known value. */
if (! relocate)
- continue;
+ {
+ relocation = 0;
+ addend = 0;
+ unresolved_reloc = FALSE;
+ }
}
break;
Index: ld/testsuite/ld-powerpc/tlsexetoc.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexetoc.d,v
retrieving revision 1.3
diff -u -p -r1.3 tlsexetoc.d
--- ld/testsuite/ld-powerpc/tlsexetoc.d 10 Jun 2003 04:36:01 -0000 1.3
+++ ld/testsuite/ld-powerpc/tlsexetoc.d 16 Jun 2003 02:16:33 -0000
@@ -33,7 +33,7 @@ Disassembly of section \.text:
.* 39 23 80 40 addi r9,r3,-32704
.* 3d 23 00 00 addis r9,r3,0
.* 81 49 80 48 lwz r10,-32696\(r9\)
-.* 3d 2d 00 00 addis r9,r13,0
+.* e9 22 80 48 ld r9,-32696\(r2\)
.* 7d 49 18 2a ldx r10,r9,r3
.* 3d 2d 00 00 addis r9,r13,0
.* a1 49 91 d8 lhz r10,-28200\(r9\)
Index: ld/testsuite/ld-powerpc/tlsso.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso.d,v
retrieving revision 1.2
diff -u -p -r1.2 tlsso.d
--- ld/testsuite/ld-powerpc/tlsso.d 10 Jun 2003 04:36:01 -0000 1.2
+++ ld/testsuite/ld-powerpc/tlsso.d 16 Jun 2003 02:16:33 -0000
@@ -53,9 +53,9 @@ Disassembly of section \.text:
.* 7d 49 19 2a stdx r10,r9,r3
.* e9 22 80 58 ld r9,-32680\(r2\)
.* 7d 49 6b 2e sthx r10,r9,r13
-.* e9 4d 90 2a lwa r10,-28632\(r13\)
+.* e9 4d 00 02 lwa r10,0\(r13\)
.* 3d 2d 00 00 addis r9,r13,0
-.* a9 49 90 30 lha r10,-28624\(r9\)
+.* a9 49 00 00 lha r10,0\(r9\)
.* 7d 89 02 a6 mfctr r12
.* 78 0b 1f 24 rldicr r11,r0,3,60
.* 34 40 80 00 addic\. r2,r0,-32768
Index: ld/testsuite/ld-powerpc/tlstoc.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstoc.d,v
retrieving revision 1.1
diff -u -p -r1.1 tlstoc.d
--- ld/testsuite/ld-powerpc/tlstoc.d 4 Feb 2003 14:52:11 -0000 1.1
+++ ld/testsuite/ld-powerpc/tlstoc.d 16 Jun 2003 02:16:33 -0000
@@ -9,29 +9,29 @@
Disassembly of section \.text:
-00000000100000e8 <\.__tls_get_addr>:
- 100000e8: 4e 80 00 20 blr
+.* <\.__tls_get_addr>:
+.* 4e 80 00 20 blr
-00000000100000ec <_start>:
- 100000ec: 3c 6d 00 00 addis r3,r13,0
- 100000f0: 60 00 00 00 nop
- 100000f4: 38 63 90 58 addi r3,r3,-28584
- 100000f8: 3c 6d 00 00 addis r3,r13,0
- 100000fc: 60 00 00 00 nop
- 10000100: 38 63 10 00 addi r3,r3,4096
- 10000104: 3c 6d 00 00 addis r3,r13,0
- 10000108: 60 00 00 00 nop
- 1000010c: 38 63 90 58 addi r3,r3,-28584
- 10000110: 3c 6d 00 00 addis r3,r13,0
- 10000114: 60 00 00 00 nop
- 10000118: 38 63 10 00 addi r3,r3,4096
- 1000011c: 39 23 80 50 addi r9,r3,-32688
- 10000120: 3d 23 00 00 addis r9,r3,0
- 10000124: 81 49 80 58 lwz r10,-32680\(r9\)
- 10000128: 3d 2d 00 00 addis r9,r13,0
- 1000012c: 7d 49 18 2a ldx r10,r9,r3
- 10000130: 3d 2d 00 00 addis r9,r13,0
- 10000134: a1 49 90 a0 lhz r10,-28512\(r9\)
- 10000138: 89 4d 90 70 lbz r10,-28560\(r13\)
- 1000013c: 3d 2d 00 00 addis r9,r13,0
- 10000140: 99 49 90 78 stb r10,-28552\(r9\)
+.* <_start>:
+.* 3c 6d 00 00 addis r3,r13,0
+.* 60 00 00 00 nop
+.* 38 63 90 58 addi r3,r3,-28584
+.* 3c 6d 00 00 addis r3,r13,0
+.* 60 00 00 00 nop
+.* 38 63 10 00 addi r3,r3,4096
+.* 3c 6d 00 00 addis r3,r13,0
+.* 60 00 00 00 nop
+.* 38 63 90 58 addi r3,r3,-28584
+.* 3c 6d 00 00 addis r3,r13,0
+.* 60 00 00 00 nop
+.* 38 63 10 00 addi r3,r3,4096
+.* 39 23 80 50 addi r9,r3,-32688
+.* 3d 23 00 00 addis r9,r3,0
+.* 81 49 80 58 lwz r10,-32680\(r9\)
+.* e9 22 80 40 ld r9,-32704\(r2\)
+.* 7d 49 18 2a ldx r10,r9,r3
+.* 3d 2d 00 00 addis r9,r13,0
+.* a1 49 90 a0 lhz r10,-28512\(r9\)
+.* 89 4d 90 70 lbz r10,-28560\(r13\)
+.* 3d 2d 00 00 addis r9,r13,0
+.* 99 49 90 78 stb r10,-28552\(r9\)
Index: ld/testsuite/ld-powerpc/tlstocso.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstocso.d,v
retrieving revision 1.2
diff -u -p -r1.2 tlstocso.d
--- ld/testsuite/ld-powerpc/tlstocso.d 10 Jun 2003 04:36:01 -0000 1.2
+++ ld/testsuite/ld-powerpc/tlstocso.d 16 Jun 2003 02:16:33 -0000
@@ -33,7 +33,7 @@ Disassembly of section \.text:
.* 39 23 80 40 addi r9,r3,-32704
.* 3d 23 00 00 addis r9,r3,0
.* 81 49 80 48 lwz r10,-32696\(r9\)
-.* 3d 2d 00 00 addis r9,r13,0
+.* e9 22 80 48 ld r9,-32696\(r2\)
.* 7d 49 18 2a ldx r10,r9,r3
.* e9 22 80 50 ld r9,-32688\(r2\)
.* 7d 49 6a 2e lhzx r10,r9,r13
Index: ld/testsuite/ld-powerpc/tlstocso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstocso.r,v
retrieving revision 1.2
diff -u -p -r1.2 tlstocso.r
--- ld/testsuite/ld-powerpc/tlstocso.r 10 Jun 2003 04:36:01 -0000 1.2
+++ ld/testsuite/ld-powerpc/tlstocso.r 16 Jun 2003 02:16:33 -0000
@@ -50,9 +50,9 @@ Program Headers:
Relocation section '\.rela\.dyn' at offset .* contains 11 entries:
+Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
-0+6c2 +0+d00000048 R_PPC64_TPREL16_HA +0+108b8 \.toc \+ 40
0+6d2 +0+1300000045 R_PPC64_TPREL16 +0+60 le0 \+ 0
0+6d6 +0+1600000048 R_PPC64_TPREL16_HA +0+68 le1 \+ 0
+0+6da +0+1600000046 R_PPC64_TPREL16_LO +0+68 le1 \+ 0
0+108b8 +0+1200000044 R_PPC64_DTPMOD64 +0+ gd \+ 0
0+108c0 +0+120000004e R_PPC64_DTPREL64 +0+ gd \+ 0
0+108c8 +0+1700000044 R_PPC64_DTPMOD64 +0+ ld \+ 0
--
Alan Modra
IBM OzLabs - Linux Technology Centre