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]

Re: powerpc64 ld --emit-relocs generates exe that segfaults


The 2005-07-08 patch that introduced the segfault also created another
problem.  I think at the time I was interested in removing a section
from the output, and making the branch lookup table read-only.  All
well and good, but the branch lookup table is addressed relative to
the current TOC/GOT pointer with a 2G max offset.  That means we'll
have a problem accessing the table in binaries with 2G or more of
.data + .rodata + .toc/.got.  This patch puts the table back to just
before .got.

bfd/
	* elf64-ppc.c (create_linkage_sections): Use section ".branch_lt"
	for branch lookup table.
ld/
	* emulparams/elf64ppc.sh (OTHER_READWRITE_SECTIONS): Add ".branch_lt".
	* emultempl/ppc64elf.em (ppc_add_stub_section): Create without
	SEC_RELOC flag set.
ld/testsuite/
	* ld-powerpc/relbrlt.d: Update.
	* ld-powerpc/tlsexe.r: Update.
	* ld-powerpc/tlsexetoc.r: Update.
	* ld-powerpc/tlsso.r: Update.
	* ld-powerpc/tlstocso.r: Update.

Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.256
diff -u -p -r1.256 elf64-ppc.c
--- bfd/elf64-ppc.c	12 Feb 2007 12:02:58 -0000	1.256
+++ bfd/elf64-ppc.c	13 Feb 2007 01:36:02 -0000
@@ -3818,37 +3818,22 @@ create_linkage_sections (bfd *dynobj, st
     return FALSE;
 
   /* Create branch lookup table for plt_branch stubs.  */
-  if (info->shared)
-    {
-      flags = (SEC_ALLOC | SEC_LOAD
-	       | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-      htab->brlt
-	= bfd_make_section_anyway_with_flags (dynobj, ".data.rel.ro.brlt",
-					      flags);
-    }
-  else
-    {
-      flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
-	       | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-      htab->brlt
-	= bfd_make_section_anyway_with_flags (dynobj, ".rodata.brlt", flags);
-    }
-
+  flags = (SEC_ALLOC | SEC_LOAD
+	   | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
+  htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
+						   flags);
   if (htab->brlt == NULL
       || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
     return FALSE;
 
-  if (info->shared)
-    {
-      flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
-	       | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-      htab->relbrlt
-	= bfd_make_section_anyway_with_flags (dynobj, ".rela.data.rel.ro.brlt",
-					      flags);
-    }
-  else
+  if (!info->shared)
     return TRUE;
 
+  flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
+	   | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
+  htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
+						      ".rela.branch_lt",
+						      flags);
   if (!htab->relbrlt
       || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
     return FALSE;
Index: ld/emulparams/elf64ppc.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64ppc.sh,v
retrieving revision 1.18
diff -u -p -r1.18 elf64ppc.sh
--- ld/emulparams/elf64ppc.sh	30 May 2006 16:45:32 -0000	1.18
+++ ld/emulparams/elf64ppc.sh	13 Feb 2007 01:36:15 -0000
@@ -31,7 +31,8 @@ OTHER_GOT_RELOC_SECTIONS="
   .rela.toc	${RELOCATING-0} : { *(.rela.toc) }"
 OTHER_READWRITE_SECTIONS="
   .toc1		${RELOCATING-0} :${RELOCATING+ ALIGN(8)} { *(.toc1) }
-  .opd		${RELOCATING-0} :${RELOCATING+ ALIGN(8)} { KEEP (*(.opd)) }"
+  .opd		${RELOCATING-0} :${RELOCATING+ ALIGN(8)} { KEEP (*(.opd)) }
+  .branch_lt	${RELOCATING-0} :${RELOCATING+ ALIGN(8)} { *(.branch_lt) }"
 
 # Treat a host that matches the target with the possible exception of "64"
 # in the name as if it were native.
Index: ld/emultempl/ppc64elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ppc64elf.em,v
retrieving revision 1.50
diff -u -p -r1.50 ppc64elf.em
--- ld/emultempl/ppc64elf.em	20 Jun 2006 02:22:14 -0000	1.50
+++ ld/emultempl/ppc64elf.em	13 Feb 2007 01:36:15 -0000
@@ -225,7 +225,7 @@ ppc_add_stub_section (const char *stub_s
     goto err_ret;
 
   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
-	   | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
+	   | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_KEEP);
   if (!bfd_set_section_flags (stub_file->the_bfd, stub_sec, flags))
     goto err_ret;
 
Index: ld/testsuite/ld-powerpc/relbrlt.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/relbrlt.d,v
retrieving revision 1.2
diff -u -p -r1.2 relbrlt.d
--- ld/testsuite/ld-powerpc/relbrlt.d	12 Feb 2007 12:02:58 -0000	1.2
+++ ld/testsuite/ld-powerpc/relbrlt.d	13 Feb 2007 01:36:16 -0000
@@ -7,44 +7,44 @@
 
 Disassembly of section \.text:
 
-0*10000078 <_start>:
-    10000078:	49 bf 00 31 	bl      11bf00a8 .*
-			10000078: R_PPC64_REL24	\.text\+0x37e0044
-    1000007c:	60 00 00 00 	nop
-    10000080:	49 bf 00 19 	bl      11bf0098 .*
-			10000080: R_PPC64_REL24	\.text\+0x3bf0020
-    10000084:	60 00 00 00 	nop
-    10000088:	49 bf 00 25 	bl      11bf00ac .*
-			10000088: R_PPC64_REL24	\.text\+0x57e0024
-    1000008c:	60 00 00 00 	nop
-    10000090:	00 00 00 00 	\.long 0x0
-    10000094:	4b ff ff e4 	b       10000078 <_start>
+0*100000b0 <_start>:
+[0-9a-f	 ]*:	49 bf 00 31 	bl      .*
+[0-9a-f	 ]*: R_PPC64_REL24	\.text\+0x37e0044
+[0-9a-f	 ]*:	60 00 00 00 	nop
+[0-9a-f	 ]*:	49 bf 00 19 	bl      .*
+[0-9a-f	 ]*: R_PPC64_REL24	\.text\+0x3bf0020
+[0-9a-f	 ]*:	60 00 00 00 	nop
+[0-9a-f	 ]*:	49 bf 00 25 	bl      .*
+[0-9a-f	 ]*: R_PPC64_REL24	\.text\+0x57e0024
+[0-9a-f	 ]*:	60 00 00 00 	nop
+[0-9a-f	 ]*:	00 00 00 00 	\.long 0x0
+[0-9a-f	 ]*:	4b ff ff e4 	b       .* <_start>
 	\.\.\.
 
-0*11bf0098 <.*plt_branch.*>:
-    11bf0098:	3d 82 05 7e 	addis   r12,r2,1406
-    11bf009c:	e9 6c 80 28 	ld      r11,-32728\(r12\)
-    11bf00a0:	7d 69 03 a6 	mtctr   r11
-    11bf00a4:	4e 80 04 20 	bctr
-
-0*11bf00a8 <.*long_branch.*>:
-    11bf00a8:	49 bf 00 14 	b       137e00bc <far>
-			11bf00a8: R_PPC64_REL24	\*ABS\*\+0x137e00bc
-
-0*11bf00ac <.*plt_branch.*>:
-    11bf00ac:	3d 82 05 7e 	addis   r12,r2,1406
-    11bf00b0:	e9 6c 80 30 	ld      r11,-32720\(r12\)
-    11bf00b4:	7d 69 03 a6 	mtctr   r11
-    11bf00b8:	4e 80 04 20 	bctr
+[0-9a-f	 ]*<.*plt_branch.*>:
+[0-9a-f	 ]*:	3d 82 00 00 	addis   r12,r2,0
+[0-9a-f	 ]*:	e9 6c 80 00 	ld      r11,-32768\(r12\)
+[0-9a-f	 ]*:	7d 69 03 a6 	mtctr   r11
+[0-9a-f	 ]*:	4e 80 04 20 	bctr
+
+[0-9a-f	 ]*<.*long_branch.*>:
+[0-9a-f	 ]*:	49 bf 00 14 	b       .* <far>
+[0-9a-f	 ]*: R_PPC64_REL24	\*ABS\*\+0x137e00f4
+
+[0-9a-f	 ]*<.*plt_branch.*>:
+[0-9a-f	 ]*:	3d 82 00 00 	addis   r12,r2,0
+[0-9a-f	 ]*:	e9 6c 80 08 	ld      r11,-32760\(r12\)
+[0-9a-f	 ]*:	7d 69 03 a6 	mtctr   r11
+[0-9a-f	 ]*:	4e 80 04 20 	bctr
 	\.\.\.
 
-0*137e00bc <far>:
-    137e00bc:	4e 80 00 20 	blr
+0*137e00f4 <far>:
+[0-9a-f	 ]*:	4e 80 00 20 	blr
 	\.\.\.
 
-0*13bf0098 <far2far>:
-    13bf0098:	4e 80 00 20 	blr
+[0-9a-f	 ]*<far2far>:
+[0-9a-f	 ]*:	4e 80 00 20 	blr
 	\.\.\.
 
-0*157e009c <huge>:
-    157e009c:	4e 80 00 20 	blr
+[0-9a-f	 ]*<huge>:
+[0-9a-f	 ]*:	4e 80 00 20 	blr
Index: ld/testsuite/ld-powerpc/tlsexe.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexe.r,v
retrieving revision 1.18
diff -u -p -r1.18 tlsexe.r
--- ld/testsuite/ld-powerpc/tlsexe.r	17 Aug 2006 08:21:06 -0000	1.18
+++ ld/testsuite/ld-powerpc/tlsexe.r	13 Feb 2007 01:36:16 -0000
@@ -17,10 +17,10 @@ Section Headers:
  +\[ 5\] \.rela\.dyn +.*
  +\[ 6\] \.rela\.plt +.*
  +\[ 7\] \.text +PROGBITS .* 0+100 0+ +AX +0 +0 +8
- +\[ 8\] \.rodata + PROGBITS .* 0+ 0+ +A +0 +0 +8
- +\[ 9\] \.tdata +PROGBITS .* 0+38 0+ WAT +0 +0 +8
- +\[10\] \.tbss +NOBITS .* 0+38 0+ WAT +0 +0 +8
- +\[11\] \.dynamic +DYNAMIC .* 0+150 10 +WA +4 +0 +8
+ +\[ 8\] \.tdata +PROGBITS .* 0+38 0+ WAT +0 +0 +8
+ +\[ 9\] \.tbss +NOBITS .* 0+38 0+ WAT +0 +0 +8
+ +\[10\] \.dynamic +DYNAMIC .* 0+150 10 +WA +4 +0 +8
+ +\[11\] \.branch_lt + PROGBITS .* 0+ 0+ +WA +0 +0 +8
  +\[12\] \.got +PROGBITS .* 0+30 08 +WA +0 +0 +8
  +\[13\] \.plt +.*
  +\[14\] \.shstrtab +.*
@@ -67,7 +67,7 @@ Symbol table '\.dynsym' contains [0-9]+ 
 .* TLS +GLOBAL DEFAULT +UND gd
 .* FUNC +GLOBAL DEFAULT +UND __tls_get_addr
 .* TLS +GLOBAL DEFAULT +UND ld
-.* TLS +GLOBAL DEFAULT +10 ld2
+.* TLS +GLOBAL DEFAULT +9 ld2
 .* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
 .* NOTYPE +GLOBAL DEFAULT +ABS _edata
 .* NOTYPE +GLOBAL DEFAULT +ABS _end
@@ -88,26 +88,26 @@ Symbol table '\.symtab' contains .* entr
 .* SECTION LOCAL +DEFAULT +11 
 .* SECTION LOCAL +DEFAULT +12 
 .* SECTION LOCAL +DEFAULT +13 
-.* TLS +LOCAL +DEFAULT +9 gd4
-.* TLS +LOCAL +DEFAULT +9 ld4
-.* TLS +LOCAL +DEFAULT +9 ld5
-.* TLS +LOCAL +DEFAULT +9 ld6
-.* TLS +LOCAL +DEFAULT +9 ie4
-.* TLS +LOCAL +DEFAULT +9 le4
-.* TLS +LOCAL +DEFAULT +9 le5
-.* OBJECT +LOCAL +HIDDEN +11 _DYNAMIC
+.* TLS +LOCAL +DEFAULT +8 gd4
+.* TLS +LOCAL +DEFAULT +8 ld4
+.* TLS +LOCAL +DEFAULT +8 ld5
+.* TLS +LOCAL +DEFAULT +8 ld6
+.* TLS +LOCAL +DEFAULT +8 ie4
+.* TLS +LOCAL +DEFAULT +8 le4
+.* TLS +LOCAL +DEFAULT +8 le5
+.* OBJECT +LOCAL +HIDDEN +10 _DYNAMIC
 .* FUNC +LOCAL +DEFAULT +UND \.__tls_get_addr
 .* GLOBAL DEFAULT +UND gd
-.* GLOBAL DEFAULT +10 le0
+.* GLOBAL DEFAULT +9 le0
 .* GLOBAL DEFAULT +UND __tls_get_addr
-.* GLOBAL DEFAULT +10 ld0
-.* GLOBAL DEFAULT +10 le1
+.* GLOBAL DEFAULT +9 ld0
+.* GLOBAL DEFAULT +9 le1
 .* GLOBAL DEFAULT +UND ld
 .* NOTYPE +GLOBAL DEFAULT +7 _start
-.* TLS +GLOBAL DEFAULT +10 ld2
-.* TLS +GLOBAL DEFAULT +10 ld1
+.* TLS +GLOBAL DEFAULT +9 ld2
+.* TLS +GLOBAL DEFAULT +9 ld1
 .* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
 .* NOTYPE +GLOBAL DEFAULT +ABS _edata
 .* NOTYPE +GLOBAL DEFAULT +ABS _end
-.* TLS +GLOBAL DEFAULT +10 gd0
-.* TLS +GLOBAL DEFAULT +10 ie0
+.* TLS +GLOBAL DEFAULT +9 gd0
+.* TLS +GLOBAL DEFAULT +9 ie0
Index: ld/testsuite/ld-powerpc/tlsexetoc.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsexetoc.r,v
retrieving revision 1.19
diff -u -p -r1.19 tlsexetoc.r
--- ld/testsuite/ld-powerpc/tlsexetoc.r	17 Aug 2006 08:21:06 -0000	1.19
+++ ld/testsuite/ld-powerpc/tlsexetoc.r	13 Feb 2007 01:36:16 -0000
@@ -17,10 +17,10 @@ Section Headers:
  +\[ 5\] \.rela\.dyn +.*
  +\[ 6\] \.rela\.plt +.*
  +\[ 7\] \.text +PROGBITS .* 0+c0 0+ +AX +0 +0 +8
- +\[ 8\] \.rodata +PROGBITS .* 0+ 0+ +A +0 +0 +8
- +\[ 9\] \.tdata +PROGBITS .* 0+38 0+ WAT +0 +0 +8
- +\[10\] \.tbss +NOBITS .* 0+38 0+ WAT +0 +0 +8
- +\[11\] \.dynamic +DYNAMIC .* 0+150 10 +WA +4 +0 +8
+ +\[ 8\] \.tdata +PROGBITS .* 0+38 0+ WAT +0 +0 +8
+ +\[ 9\] \.tbss +NOBITS .* 0+38 0+ WAT +0 +0 +8
+ +\[10\] \.dynamic +DYNAMIC .* 0+150 10 +WA +4 +0 +8
+ +\[11\] \.branch_lt +PROGBITS .* 0+ 0+ +WA +0 +0 +8
  +\[12\] \.got +PROGBITS .* 0+58 08 +WA +0 +0 +8
  +\[13\] \.plt +.*
  +\[14\] \.shstrtab +.*
@@ -87,27 +87,27 @@ Symbol table '\.symtab' contains .* entr
 .* SECTION LOCAL +DEFAULT +11 
 .* SECTION LOCAL +DEFAULT +12 
 .* SECTION LOCAL +DEFAULT +13 
-.* TLS +LOCAL +DEFAULT +9 gd4
-.* TLS +LOCAL +DEFAULT +9 ld4
-.* TLS +LOCAL +DEFAULT +9 ld5
-.* TLS +LOCAL +DEFAULT +9 ld6
-.* TLS +LOCAL +DEFAULT +9 ie4
-.* TLS +LOCAL +DEFAULT +9 le4
-.* TLS +LOCAL +DEFAULT +9 le5
+.* TLS +LOCAL +DEFAULT +8 gd4
+.* TLS +LOCAL +DEFAULT +8 ld4
+.* TLS +LOCAL +DEFAULT +8 ld5
+.* TLS +LOCAL +DEFAULT +8 ld6
+.* TLS +LOCAL +DEFAULT +8 ie4
+.* TLS +LOCAL +DEFAULT +8 le4
+.* TLS +LOCAL +DEFAULT +8 le5
 .* NOTYPE +LOCAL +DEFAULT +12 \.Lie0
-.* OBJECT +LOCAL +HIDDEN +11 _DYNAMIC
+.* OBJECT +LOCAL +HIDDEN +10 _DYNAMIC
 .* FUNC +LOCAL +DEFAULT +UND \.__tls_get_addr
 .* TLS +GLOBAL DEFAULT +UND gd
-.* TLS +GLOBAL DEFAULT +10 le0
+.* TLS +GLOBAL DEFAULT +9 le0
 .* FUNC +GLOBAL DEFAULT +UND __tls_get_addr
-.* TLS +GLOBAL DEFAULT +10 ld0
-.* TLS +GLOBAL DEFAULT +10 le1
+.* TLS +GLOBAL DEFAULT +9 ld0
+.* TLS +GLOBAL DEFAULT +9 le1
 .* TLS +GLOBAL DEFAULT +UND ld
 .* NOTYPE +GLOBAL DEFAULT +7 _start
-.* TLS +GLOBAL DEFAULT +10 ld2
-.* TLS +GLOBAL DEFAULT +10 ld1
+.* TLS +GLOBAL DEFAULT +9 ld2
+.* TLS +GLOBAL DEFAULT +9 ld1
 .* NOTYPE +GLOBAL DEFAULT +ABS __bss_start
 .* NOTYPE +GLOBAL DEFAULT +ABS _edata
 .* NOTYPE +GLOBAL DEFAULT +ABS _end
-.* TLS +GLOBAL DEFAULT +10 gd0
-.* TLS +GLOBAL DEFAULT +10 ie0
+.* TLS +GLOBAL DEFAULT +9 gd0
+.* TLS +GLOBAL DEFAULT +9 ie0
Index: ld/testsuite/ld-powerpc/tlsso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlsso.r,v
retrieving revision 1.18
diff -u -p -r1.18 tlsso.r
--- ld/testsuite/ld-powerpc/tlsso.r	17 Oct 2006 13:41:48 -0000	1.18
+++ ld/testsuite/ld-powerpc/tlsso.r	13 Feb 2007 01:36:16 -0000
@@ -17,8 +17,8 @@ Section Headers:
  +\[ 6\] \.text .*
  +\[ 7\] \.tdata +PROGBITS .* 0+38 0+ WAT +0 +0 +8
  +\[ 8\] \.tbss +NOBITS .* 0+38 0+ WAT +0 +0 +8
- +\[ 9\] \.data\.rel\.ro .*
- +\[10\] \.dynamic .*
+ +\[ 9\] \.dynamic .*
+ +\[10\] \.branch_lt .*
  +\[11\] \.got .*
  +\[12\] \.plt .*
  +\[13\] \.shstrtab .*
Index: ld/testsuite/ld-powerpc/tlstocso.r
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/tlstocso.r,v
retrieving revision 1.18
diff -u -p -r1.18 tlstocso.r
--- ld/testsuite/ld-powerpc/tlstocso.r	17 Oct 2006 13:41:48 -0000	1.18
+++ ld/testsuite/ld-powerpc/tlstocso.r	13 Feb 2007 01:36:16 -0000
@@ -17,8 +17,8 @@ Section Headers:
  +\[ 6\] \.text .*
  +\[ 7\] \.tdata +PROGBITS .* 0+38 0+ WAT +0 +0 +8
  +\[ 8\] \.tbss +NOBITS .* 0+38 0+ WAT +0 +0 +8
- +\[ 9\] \.data\.rel\.ro .*
- +\[10\] \.dynamic .*
+ +\[ 9\] \.dynamic .*
+ +\[10\] \.branch_lt .*
  +\[11\] \.got .*
  +\[12\] \.plt .*
  +\[13\] \.shstrtab .*

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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