This is the mail archive of the binutils@sources.redhat.com 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]

[PATCH] Fix TLS @dtpoff in unallocated sections


Hi!

The following patch changes @dtpoff handling in unallocated sections, so
that it is never converted to @{n,}tpoff.
On x86-64 if gdb wants to write 64-bit address, it has to use
.long foo@dtpoff, 0
ATM. AS PT_TLS segment size is limited to 4GB anyway, IMHO that's not that
big trouble, but if you'd prefer to use
.quad foo@dtpoff
and R_X86_64_DTPOFF64 instead of *32, it is doable too (though would require
a couple of tc-i386.c and elf64-x86-64.c changes, as e.g. lex_got is
currently solely for 32-bit fields).

2002-09-27  Jakub Jelinek  <jakub@redhat.com>

bfd/
	* elf32-i386.c (elf_i386_relocate_section): Resolve R_386_TLS_LDO_32
	to st_value + addend in non-alloced sections.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Resolve
	R_X86_64_DTPOFF32 to st_value + addend in non-alloced sections.

ld/testsuite/
	* ld-i386/i386.exp: Add tlsg test.
	* ld-i386/tlsg.s: New test.
	* ld-i386/tlsg.sd: New test.
	* ld-i386/tlsbin.dd: Change LD into LD -> LE in comments.
	* ld-i386/tlsbinpic.s: Likewise.
	* ld-x86-64/x86-64.exp: Add tlsg test.
	* ld-x86-64/tlsg.s: New test.
	* ld-x86-64/tlsg.sd: New test.
	* ld-x86-64/tlsbin.dd: Change LD into LD -> LE in comments.
	* ld-x86-64/tlsbinpic.s: Likewise.

--- bfd/elf32-i386.c.jj	2002-09-25 18:45:11.000000000 +0200
+++ bfd/elf32-i386.c	2002-09-27 09:38:23.000000000 +0200
@@ -2926,7 +2926,7 @@ elf_i386_relocate_section (output_bfd, i
 	  break;
 
 	case R_386_TLS_LDO_32:
-	  if (info->shared)
+	  if (info->shared || (input_section->flags & SEC_ALLOC) == 0)
 	    relocation -= dtpoff_base (info);
 	  else
 	    /* When converting LDO to LE, we must negate.  */
--- bfd/elf64-x86-64.c.jj	2002-09-26 17:37:10.000000000 +0200
+++ bfd/elf64-x86-64.c	2002-09-27 11:30:39.000000000 +0200
@@ -2496,7 +2496,7 @@ elf64_x86_64_relocate_section (output_bf
 	  break;
 
 	case R_X86_64_DTPOFF32:
-	  if (info->shared)
+	  if (info->shared || (input_section->flags & SEC_ALLOC) == 0)
 	    relocation -= dtpoff_base (info);
 	  else
 	    relocation = tpoff (info, relocation);
--- ld/testsuite/ld-i386/i386.exp.jj	2002-09-25 14:17:27.000000000 +0200
+++ ld/testsuite/ld-i386/i386.exp	2002-09-27 12:13:35.000000000 +0200
@@ -52,6 +52,9 @@ set i386tests {
      "--32" {tlsnopic1.s tlsnopic2.s}
      {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
       {objdump -sj.got tlsnopic.sd}} "libtlsnopic.so"}
+    {"TLS in debug sections" "-melf_i386"
+     "--32" {tlsg.s}
+     {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
 }
 
 run_ld_link_tests $i386tests
--- ld/testsuite/ld-i386/tlsg.s.jj	2002-09-27 11:48:08.000000000 +0200
+++ ld/testsuite/ld-i386/tlsg.s	2002-09-27 11:46:03.000000000 +0200
@@ -0,0 +1,12 @@
+	.section	.tbss,"awT",@nobits
+	.align 4
+	.skip	24
+	.type	a,@object
+	.size	a,4
+a:
+	.zero	4
+	.text
+	.globl	_start
+_start:
+	.section	.debug_foobar
+	.long	a@dtpoff
--- ld/testsuite/ld-i386/tlsg.sd.jj	2002-09-27 12:01:57.000000000 +0200
+++ ld/testsuite/ld-i386/tlsg.sd	2002-09-27 12:24:14.000000000 +0200
@@ -0,0 +1,10 @@
+#source: tlsg.s
+#as: --32
+#ld: -melf_i386
+#objdump: -sj.debug_foobar
+#target: i?86-*-*
+
+.*: +file format elf32-i386
+
+Contents of section .debug_foobar:
+ 0+ 18000000  +.*
--- ld/testsuite/ld-i386/tlsbin.dd.jj	2002-09-19 12:01:19.000000000 +0200
+++ ld/testsuite/ld-i386/tlsbin.dd	2002-09-27 09:20:21.000000000 +0200
@@ -89,7 +89,7 @@ Disassembly of section .text:
  8049082:	90[ 	]+nop *
  8049083:	90[ 	]+nop *
  8049084:	90[ 	]+nop *
-#  LD
+#  LD -> LE
  8049085:	65 a1 00 00 00 00[ 	]+mov    %gs:0x0,%eax
  804908b:	90[ 	]+nop *
  804908c:	8d 74 26 00[ 	]+lea    0x0\(%esi,1\),%esi
@@ -105,7 +105,7 @@ Disassembly of section .text:
  80490a1:	90[ 	]+nop *
  80490a2:	90[ 	]+nop *
  80490a3:	90[ 	]+nop *
-#  LD against hidden variables
+#  LD -> LE against hidden variables
  80490a4:	65 a1 00 00 00 00[ 	]+mov    %gs:0x0,%eax
  80490aa:	90[ 	]+nop *
  80490ab:	8d 74 26 00[ 	]+lea    0x0\(%esi,1\),%esi
--- ld/testsuite/ld-i386/tlsbinpic.s.jj	2002-09-19 12:01:19.000000000 +0200
+++ ld/testsuite/ld-i386/tlsbinpic.s	2002-09-27 09:19:57.000000000 +0200
@@ -83,7 +83,7 @@ fn2:
 	call	___tls_get_addr@plt
 	nop;nop;nop;nop
 
-	/* LD */
+	/* LD -> LE */
 	leal	sl1@tlsldm(%ebx), %eax
 	call	___tls_get_addr@PLT
 	nop;nop
@@ -92,7 +92,7 @@ fn2:
 	leal	sl2@dtpoff(%eax), %ecx
 	nop;nop;nop;nop
 
-	/* LD against hidden variables */
+	/* LD -> LE against hidden variables */
 	leal	sh1@tlsldm(%ebx), %eax
 	call	___tls_get_addr@PLT
 	nop;nop
--- ld/testsuite/ld-x86-64/tlsg.s.jj	2002-09-27 11:48:08.000000000 +0200
+++ ld/testsuite/ld-x86-64/tlsg.s	2002-09-27 11:59:33.000000000 +0200
@@ -0,0 +1,12 @@
+	.section	.tbss,"awT",@nobits
+	.align 4
+	.skip	24
+	.type	a,@object
+	.size	a,4
+a:
+	.zero	4
+	.text
+	.globl	_start
+_start:
+	.section	.debug_foobar
+	.long	a@dtpoff, 0
--- ld/testsuite/ld-x86-64/tlsbinpic.s.jj	2002-09-27 09:19:16.000000000 +0200
+++ ld/testsuite/ld-x86-64/tlsbinpic.s	2002-09-27 09:19:16.000000000 +0200
@@ -70,7 +70,7 @@ fn2:
 	call	__tls_get_addr@plt
 	nop;nop;nop;nop
 
-	/* LD */
+	/* LD -> LE */
 	leaq	sl1@tlsld(%rip), %rdi
 	call	__tls_get_addr@plt
 	nop;nop
@@ -79,7 +79,7 @@ fn2:
 	leaq	sl2@dtpoff+2(%rax), %r9
 	nop;nop;nop;nop
 
-	/* LD against hidden variables */
+	/* LD -> LE against hidden variables */
 	leaq	sh1@tlsld(%rip), %rdi
 	call	__tls_get_addr@plt
 	nop;nop
--- ld/testsuite/ld-x86-64/tlsbin.dd.jj	2002-09-27 09:18:53.000000000 +0200
+++ ld/testsuite/ld-x86-64/tlsbin.dd	2002-09-27 09:18:53.000000000 +0200
@@ -67,7 +67,7 @@ Disassembly of section .text:
   401065:	90[ 	]+nop *
   401066:	90[ 	]+nop *
   401067:	90[ 	]+nop *
-#  LD
+#  LD -> LE
   401068:	66 66 66 64 48 8b 04[ 	]+mov    %fs:0x0,%rax
   40106f:	25 00 00 00 00 *
   401074:	90[ 	]+nop *
@@ -82,7 +82,7 @@ Disassembly of section .text:
   401087:	90[ 	]+nop *
   401088:	90[ 	]+nop *
   401089:	90[ 	]+nop *
-#  LD against hidden variables
+#  LD -> LE against hidden variables
   40108a:	66 66 66 64 48 8b 04[ 	]+mov    %fs:0x0,%rax
   401091:	25 00 00 00 00 *
   401096:	90[ 	]+nop *
--- ld/testsuite/ld-x86-64/x86-64.exp.jj	2002-09-26 13:18:22.000000000 +0200
+++ ld/testsuite/ld-x86-64/x86-64.exp	2002-09-27 12:14:10.000000000 +0200
@@ -46,6 +46,9 @@ set x86_64tests {
      {{readelf -WSsrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
       {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
       "tlsbin"}
+    {"TLS in debug sections" "-melf_x86_64"
+     "--64" {tlsg.s}
+     {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
 }
 
 run_ld_link_tests $x86_64tests
--- ld/testsuite/ld-x86-64/tlsg.sd.jj	2002-09-27 12:01:57.000000000 +0200
+++ ld/testsuite/ld-x86-64/tlsg.sd	2002-09-27 12:24:03.000000000 +0200
@@ -0,0 +1,10 @@
+#source: tlsg.s
+#as: --64
+#ld: -melf_x86_64
+#objdump: -sj.debug_foobar
+#target: x86_64-*-*
+
+.*: +file format elf64-x86-64
+
+Contents of section .debug_foobar:
+ 0+ 18000000 0+  +.*

	Jakub


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