This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] Sparc32 ELF TLS fixes
- From: "David S. Miller" <davem at davemloft dot net>
- To: binutils at sources dot redhat dot com
- Cc: jakub at redhat dot com, ebotcazou at libertysurf dot fr
- Date: Sat, 9 Apr 2005 22:46:45 -0700
- Subject: [PATCH] Sparc32 ELF TLS fixes
While working on Sparc64 ELF TLS support, I found a bug in TLS
handling on sparc32 ELF TLS.
For relocations R_SPARC_TLS_*_{HIX22,LOX10} it clearly states at:
http://docsun.cities.uiuc.edu/sun_docs/C/Solaris_9/SUNWdev/LLM/p60.html
that the formula for R_SPARC_TLS_LDO_HIX22 is:
@dtpoff(S + A) >> 10
and for R_SPARC_TLS_LDO_LOX10 it is:
@dtpoff(S + A) & 0x3ff
furthermore it describes for R_SPARC_TLS_LE_HIX22 that the
formula is:
(@tpoff(S + A) ^ 0xffffffffffffffff) >> 10
and for R_SPARC_TLS_LE_LOX10 it is:
(@tpoff(S + A) & 0x3ff) | 0x1c00
In the elf32-sparc BFD code we were making two mistakes:
1) we were not transitioning from LDO --> LE properly when
not shared
2) For the TLS HIX22/LOX10 relocations, we should only do the
"reloc ^ -1" and "reloc ^ 0x1c00" transformations for the
LE case
So here are two patches to address these problems. The first
does the BFD fixes, the next does the LD testsuite update.
I verified these changes with elf32-sparc builds of GLIBC current
CVS, both with NPTL and LINUXTHREADS. The full ld testsuite passes.
2005-04-09 David S. Miller <davem@davemloft.net>
* elf32-sparc.c (elf32_sparc_relocate_section,
R_SPARC_TLS_LDO_{HIX22,LOX10}): When not shared, transition to
R_SPARC_TLS_LE_{HIX22,LOX10}.
(elf32_sparc_relocate_section, R_SPARC_TLS_{LDO,LE}_HIX22): Only
xor relocation with 0xffffffff if R_SPARC_TLS_LE_HIX22.
(elf32_sparc_relocate_section, R_SPARC_TLS_{LDO,LE}_LOX10): Only
or 0x1c00 into relocation if R_SPARC_TLS_LE_HIX22.
*** bfd/elf32-sparc.c 11 Jan 2005 09:32:51 -0000 1.79
--- bfd/elf32-sparc.c 10 Apr 2005 05:21:55 -0000
***************
*** 2678,2687 ****
case R_SPARC_TLS_LDO_HIX22:
case R_SPARC_TLS_LDO_LOX10:
if (info->shared)
! relocation -= dtpoff_base (info);
! else
! relocation = tpoff (info, relocation);
! break;
case R_SPARC_TLS_LE_HIX22:
case R_SPARC_TLS_LE_LOX10:
--- 2678,2691 ----
case R_SPARC_TLS_LDO_HIX22:
case R_SPARC_TLS_LDO_LOX10:
if (info->shared)
! {
! relocation -= dtpoff_base (info);
! break;
! }
!
! r_type = (r_type == R_SPARC_TLS_LDO_HIX22
! ? R_SPARC_TLS_LE_HIX22 : R_SPARC_TLS_LE_LOX10);
! /* Fall through. */
case R_SPARC_TLS_LE_HIX22:
case R_SPARC_TLS_LE_LOX10:
***************
*** 2900,2906 ****
bfd_vma x;
relocation += rel->r_addend;
! relocation = relocation ^ 0xffffffff;
x = bfd_get_32 (input_bfd, contents + rel->r_offset);
x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
--- 2904,2911 ----
bfd_vma x;
relocation += rel->r_addend;
! if (r_type == R_SPARC_TLS_LE_HIX22)
! relocation = relocation ^ 0xffffffff;
x = bfd_get_32 (input_bfd, contents + rel->r_offset);
x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
***************
*** 2913,2919 ****
bfd_vma x;
relocation += rel->r_addend;
! relocation = (relocation & 0x3ff) | 0x1c00;
x = bfd_get_32 (input_bfd, contents + rel->r_offset);
x = (x & ~(bfd_vma) 0x1fff) | relocation;
--- 2918,2926 ----
bfd_vma x;
relocation += rel->r_addend;
! relocation &= 0x3ff;
! if (r_type == R_SPARC_TLS_LE_LOX10)
! relocation |= 0x1c00;
x = bfd_get_32 (input_bfd, contents + rel->r_offset);
x = (x & ~(bfd_vma) 0x1fff) | relocation;
2005-04-09 David S. Miller <davem@davemloft.net>
* ld-sparc/tlssunbin32.dd: Update for TLS relocation fixes.
* ld-sparc/tlssunbin32.rd: Likewise.
* ld-sparc/tlssunbin32.sd: Likewise.
*** ld/testsuite/ld-sparc/tlssunbin32.dd 1 Jul 2004 16:24:51 -0000 1.2
--- ld/testsuite/ld-sparc/tlssunbin32.dd 10 Apr 2005 05:21:57 -0000
***************
*** 16,22 ****
+11008: 9d e3 bf 98 save %sp, -104, %sp
+1100c: 2f 00 00 48 sethi %hi\(0x12000\), %l7
+11010: 7f ff ff fc call 11000 <.*>
! +11014: ae 05 e2 68 add %l7, 0x268, %l7 ! 12268 <.*>
+11018: 01 00 00 00 nop *
+1101c: 01 00 00 00 nop *
+11020: 01 00 00 00 nop *
--- 16,22 ----
+11008: 9d e3 bf 98 save %sp, -104, %sp
+1100c: 2f 00 00 48 sethi %hi\(0x12000\), %l7
+11010: 7f ff ff fc call 11000 <.*>
! +11014: ae 05 e2 64 add %l7, 0x264, %l7 ! 12264 <.*>
+11018: 01 00 00 00 nop *
+1101c: 01 00 00 00 nop *
+11020: 01 00 00 00 nop *
***************
*** 172,178 ****
00012000 <_start>:
+12000: 9d e3 bf 98 save %sp, -104, %sp
+12004: 29 00 00 8c sethi %hi\(0x23000\), %l4
! +12008: a8 15 22 78 or %l4, 0x278, %l4 ! 23278 <.*>
+1200c: 01 00 00 00 nop *
+12010: 01 00 00 00 nop *
+12014: 01 00 00 00 nop *
--- 172,178 ----
00012000 <_start>:
+12000: 9d e3 bf 98 save %sp, -104, %sp
+12004: 29 00 00 8c sethi %hi\(0x23000\), %l4
! +12008: a8 15 22 74 or %l4, 0x274, %l4 ! 23274 <.*>
+1200c: 01 00 00 00 nop *
+12010: 01 00 00 00 nop *
+12014: 01 00 00 00 nop *
*** ld/testsuite/ld-sparc/tlssunbin32.rd 16 Mar 2005 21:52:47 -0000 1.4
--- ld/testsuite/ld-sparc/tlssunbin32.rd 10 Apr 2005 05:21:57 -0000
***************
*** 17,24 ****
+\[ 6\] .text +PROGBITS +0+11000 0+1000 0+1194 00 +AX +0 +0 4096
+\[ 7\] .tdata +PROGBITS +0+22194 0+2194 0+1060 00 WAT +0 +0 +4
+\[ 8\] .tbss +NOBITS +0+231f4 0+31f4 0+40 00 WAT +0 +0 +4
! +\[ 9\] .dynamic +DYNAMIC +0+231f8 0+31f8 0+80 08 +WA +4 +0 +4
! +\[10\] .got +PROGBITS +0+23278 0+3278 0+14 04 +WA +0 +0 +4
+\[11\] .plt +.*
+\[12\] .shstrtab +.*
+\[13\] .symtab +.*
--- 17,24 ----
+\[ 6\] .text +PROGBITS +0+11000 0+1000 0+1194 00 +AX +0 +0 4096
+\[ 7\] .tdata +PROGBITS +0+22194 0+2194 0+1060 00 WAT +0 +0 +4
+\[ 8\] .tbss +NOBITS +0+231f4 0+31f4 0+40 00 WAT +0 +0 +4
! +\[ 9\] .dynamic +DYNAMIC +0+231f4 0+31f4 0+80 08 +WA +4 +0 +4
! +\[10\] .got +PROGBITS +0+23274 0+3274 0+14 04 +WA +0 +0 +4
+\[11\] .plt +.*
+\[12\] .shstrtab +.*
+\[13\] .symtab +.*
***************
*** 35,57 ****
+INTERP +0x0+f4 0x0+100f4 0x0+100f4 0x0+11 0x0+11 R +0x1
.*Requesting program interpreter.*
+LOAD +0x0+ 0x0+10000 0x0+10000 0x0+2194 0x0+2194 R E 0x10000
! +LOAD +0x0+2194 0x0+22194 0x0+22194 0x0+10f8 0x0+10f8 RWE 0x10000
! +DYNAMIC +0x0+31f8 0x0+231f8 0x0+231f8 0x0+80 0x0+80 RW +0x4
+TLS +0x0+2194 0x0+22194 0x0+22194 0x0+1060 0x0+10a0 R +0x4
#...
Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 4 entries:
Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend
! 0002327c +0000014e R_SPARC_TLS_TPOFF32 +00000000 +sG5 \+ 0
! 00023280 +0000034e R_SPARC_TLS_TPOFF32 +00000000 +sG2 \+ 0
! 00023284 +0000074e R_SPARC_TLS_TPOFF32 +00000000 +sG6 \+ 0
! 00023288 +0000084e R_SPARC_TLS_TPOFF32 +00000000 +sG1 \+ 0
Symbol table '.dynsym' contains 11 entries:
+Num: +Value +Size Type +Bind +Vis +Ndx Name
+0: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND *
+1: 0+ +0 TLS +GLOBAL DEFAULT +UND sG5
! +2: 0+231f8 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+3: 0+ +0 TLS +GLOBAL DEFAULT +UND sG2
+4: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +ABS _PROCEDURE_LINKAGE_TABLE_
+5: 0+ +0 FUNC +GLOBAL DEFAULT +UND __tls_get_addr
--- 35,57 ----
+INTERP +0x0+f4 0x0+100f4 0x0+100f4 0x0+11 0x0+11 R +0x1
.*Requesting program interpreter.*
+LOAD +0x0+ 0x0+10000 0x0+10000 0x0+2194 0x0+2194 R E 0x10000
! +LOAD +0x0+2194 0x0+22194 0x0+22194 0x0+10f4 0x0+10f4 RWE 0x10000
! +DYNAMIC +0x0+31f4 0x0+231f4 0x0+231f4 0x0+80 0x0+80 RW +0x4
+TLS +0x0+2194 0x0+22194 0x0+22194 0x0+1060 0x0+10a0 R +0x4
#...
Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 4 entries:
Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend
! 00023278 +0000014e R_SPARC_TLS_TPOFF32 +00000000 +sG5 \+ 0
! 0002327c +0000034e R_SPARC_TLS_TPOFF32 +00000000 +sG2 \+ 0
! 00023280 +0000074e R_SPARC_TLS_TPOFF32 +00000000 +sG6 \+ 0
! 00023284 +0000084e R_SPARC_TLS_TPOFF32 +00000000 +sG1 \+ 0
Symbol table '.dynsym' contains 11 entries:
+Num: +Value +Size Type +Bind +Vis +Ndx Name
+0: 0+ +0 NOTYPE +LOCAL +DEFAULT +UND *
+1: 0+ +0 TLS +GLOBAL DEFAULT +UND sG5
! +2: 0+231f4 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+3: 0+ +0 TLS +GLOBAL DEFAULT +UND sG2
+4: [0-9a-f]+ +0 OBJECT +GLOBAL DEFAULT +ABS _PROCEDURE_LINKAGE_TABLE_
+5: 0+ +0 FUNC +GLOBAL DEFAULT +UND __tls_get_addr
***************
*** 99,105 ****
+[0-9]+: 0+1074 +0 TLS +GLOBAL DEFAULT +8 bg6
+[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND sG5
+[0-9]+: 0+1068 +0 TLS +GLOBAL DEFAULT +8 bg3
! +[0-9]+: 0+231f8 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+[0-9]+: 0+1008 +0 TLS +GLOBAL DEFAULT +7 sg3
+[0-9]+: 0+1048 +0 TLS +GLOBAL HIDDEN +7 sh3
+[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND sG2
--- 99,105 ----
+[0-9]+: 0+1074 +0 TLS +GLOBAL DEFAULT +8 bg6
+[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND sG5
+[0-9]+: 0+1068 +0 TLS +GLOBAL DEFAULT +8 bg3
! +[0-9]+: 0+231f4 +0 OBJECT +GLOBAL DEFAULT +ABS _DYNAMIC
+[0-9]+: 0+1008 +0 TLS +GLOBAL DEFAULT +7 sg3
+[0-9]+: 0+1048 +0 TLS +GLOBAL HIDDEN +7 sh3
+[0-9]+: 0+ +0 TLS +GLOBAL DEFAULT +UND sG2
***************
*** 124,130 ****
+[0-9]+: 0+1014 +0 TLS +GLOBAL DEFAULT +7 sg6
+[0-9]+: 0+1018 +0 TLS +GLOBAL DEFAULT +7 sg7
+[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _edata
! +[0-9]+: 0+23278 +0 OBJECT +GLOBAL +HIDDEN +10 _GLOBAL_OFFSET_TABLE_
+[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _end
+[0-9]+: 0+1044 +0 TLS +GLOBAL HIDDEN +7 sh2
+[0-9]+: 0+1054 +0 TLS +GLOBAL HIDDEN +7 sh6
--- 124,130 ----
+[0-9]+: 0+1014 +0 TLS +GLOBAL DEFAULT +7 sg6
+[0-9]+: 0+1018 +0 TLS +GLOBAL DEFAULT +7 sg7
+[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _edata
! +[0-9]+: 0+23274 +0 OBJECT +GLOBAL +HIDDEN +10 _GLOBAL_OFFSET_TABLE_
+[0-9]+: [0-9a-f]+ +0 NOTYPE +GLOBAL DEFAULT +ABS _end
+[0-9]+: 0+1044 +0 TLS +GLOBAL HIDDEN +7 sh2
+[0-9]+: 0+1054 +0 TLS +GLOBAL HIDDEN +7 sh6
*** ld/testsuite/ld-sparc/tlssunbin32.sd 1 Oct 2004 11:11:28 -0000 1.3
--- ld/testsuite/ld-sparc/tlssunbin32.sd 10 Apr 2005 05:21:57 -0000
***************
*** 7,11 ****
.*: +file format elf32-sparc
Contents of section .got:
! 23278 000231f8 0+ 0+ 0+ .*
! 23288 0+ .*
--- 7,11 ----
.*: +file format elf32-sparc
Contents of section .got:
! 23274 000231f4 0+ 0+ 0+ .*
! 23284 0+ .*