This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] Use STT_TLS for all TLS symbols (even SHN_UNDEF)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Thu, 14 Nov 2002 17:07:43 +0100
- Subject: [PATCH] Use STT_TLS for all TLS symbols (even SHN_UNDEF)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
I think all the undefined symbols mentioned in TLS relocations should
have STT_TLS type, so that ld.so can easily detect attempts to resolve
TLS undef symbol to non-TLS symbol or vice versa (instead of having to
track which relocation was used and if it is TLS reloc or not).
Seems like this is what Sun assembler/linker does too.
If you agree with this, I'll change IA-64/Alpha too (and hope Kaz will
change SH).
2002-11-14 Jakub Jelinek <jakub@redhat.com>
* symbols.c (S_SET_THREAD_LOCAL): New function.
* symbols.h (S_SET_THREAD_LOCAL): New prototype.
* config/tc-i386.c (md_apply_fix3): Call S_SET_THREAD_LOCAL
for TLS relocations.
* ld-i386/tlsnopic.rd: Change NOTYPE to TLS for UND sg* symbols.
--- gas/config/tc-i386.c.jj 2002-10-14 13:30:31.000000000 +0200
+++ gas/config/tc-i386.c 2002-11-14 15:11:07.000000000 +0100
@@ -4679,17 +4679,27 @@ md_apply_fix3 (fixP, valP, seg)
value = -4;
break;
- case BFD_RELOC_386_GOT32:
case BFD_RELOC_386_TLS_GD:
case BFD_RELOC_386_TLS_LDM:
case BFD_RELOC_386_TLS_IE_32:
case BFD_RELOC_386_TLS_IE:
case BFD_RELOC_386_TLS_GOTIE:
- case BFD_RELOC_X86_64_GOT32:
case BFD_RELOC_X86_64_TLSGD:
case BFD_RELOC_X86_64_TLSLD:
case BFD_RELOC_X86_64_GOTTPOFF:
value = 0; /* Fully resolved at runtime. No addend. */
+ /* Fallthrough */
+ case BFD_RELOC_386_TLS_LE:
+ case BFD_RELOC_386_TLS_LDO_32:
+ case BFD_RELOC_386_TLS_LE_32:
+ case BFD_RELOC_X86_64_DTPOFF32:
+ case BFD_RELOC_X86_64_TPOFF32:
+ S_SET_THREAD_LOCAL (fixP->fx_addsy);
+ break;
+
+ case BFD_RELOC_386_GOT32:
+ case BFD_RELOC_X86_64_GOT32:
+ value = 0; /* Fully resolved at runtime. No addend. */
break;
case BFD_RELOC_VTABLE_INHERIT:
--- gas/symbols.h.jj 2002-09-10 14:50:53.000000000 +0200
+++ gas/symbols.h 2002-11-14 14:26:10.000000000 +0100
@@ -102,6 +102,7 @@ extern void S_SET_EXTERNAL PARAMS ((symb
extern void S_SET_NAME PARAMS ((symbolS *, char *));
extern void S_CLEAR_EXTERNAL PARAMS ((symbolS *));
extern void S_SET_WEAK PARAMS ((symbolS *));
+extern void S_SET_THREAD_LOCAL PARAMS ((symbolS *));
#endif
#ifndef WORKING_DOT_WORD
--- gas/symbols.c.jj 2002-09-21 23:44:50.000000000 +0200
+++ gas/symbols.c 2002-11-14 18:08:35.000000000 +0100
@@ -1951,6 +1951,22 @@ S_SET_WEAK (s)
}
void
+S_SET_THREAD_LOCAL (s)
+ symbolS *s;
+{
+ if (LOCAL_SYMBOL_CHECK (s))
+ s = local_symbol_convert ((struct local_symbol *) s);
+ s->bsym->flags |= BSF_THREAD_LOCAL;
+ if ((s->bsym->flags & BSF_FUNCTION) != 0)
+ as_bad (_("Accessing function `%s' as thread-local object"),
+ S_GET_NAME (s));
+ else if (! bfd_is_und_section (s->bsym->section)
+ && (s->bsym->section->flags & SEC_THREAD_LOCAL) == 0)
+ as_bad (_("Accessing `%s' as thread-local object"),
+ S_GET_NAME (s));
+}
+
+void
S_SET_NAME (s, name)
symbolS *s;
char *name;
--- ld/testsuite/ld-i386/tlsnopic.rd.jj 2002-09-19 12:01:19.000000000 +0200
+++ ld/testsuite/ld-i386/tlsnopic.rd 2002-11-14 15:07:13.000000000 +0100
@@ -84,13 +84,13 @@ Symbol table '.dynsym' contains 22 entri
+9: [0-9a-f]+ +0 SECTION LOCAL DEFAULT +9 *
+10: [0-9a-f]+ +0 SECTION LOCAL DEFAULT +10 *
+11: [0-9a-f]+ +0 OBJECT GLOBAL DEFAULT ABS _DYNAMIC
- +12: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg3
- +13: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg4
+ +12: 0+ +0 TLS +GLOBAL DEFAULT UND sg3
+ +13: 0+ +0 TLS +GLOBAL DEFAULT UND sg4
+14: 0+1000 +0 FUNC +GLOBAL DEFAULT +5 fn3
- +15: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg5
- +16: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg1
+ +15: 0+ +0 TLS +GLOBAL DEFAULT UND sg5
+ +16: 0+ +0 TLS +GLOBAL DEFAULT UND sg1
+17: [0-9a-f]+ +0 NOTYPE GLOBAL DEFAULT ABS __bss_start
- +18: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg2
+ +18: 0+ +0 TLS +GLOBAL DEFAULT UND sg2
+19: [0-9a-f]+ +0 NOTYPE GLOBAL DEFAULT ABS _edata
+20: 0+2080 +0 OBJECT GLOBAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_
+21: [0-9a-f]+ +0 NOTYPE GLOBAL DEFAULT ABS _end
@@ -121,13 +121,13 @@ Symbol table '.symtab' contains 34 entri
+21: 0+14 +0 TLS +LOCAL HIDDEN +7 sh1
+22: 0+18 +0 TLS +LOCAL HIDDEN +7 sh2
+23: [0-9a-f]+ +0 OBJECT GLOBAL DEFAULT ABS _DYNAMIC
- +24: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg3
- +25: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg4
+ +24: 0+ +0 TLS +GLOBAL DEFAULT UND sg3
+ +25: 0+ +0 TLS +GLOBAL DEFAULT UND sg4
+26: 0+1000 +0 FUNC +GLOBAL DEFAULT +5 fn3
- +27: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg5
- +28: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg1
+ +27: 0+ +0 TLS +GLOBAL DEFAULT UND sg5
+ +28: 0+ +0 TLS +GLOBAL DEFAULT UND sg1
+29: [0-9a-f]+ +0 NOTYPE GLOBAL DEFAULT ABS __bss_start
- +30: 0+ +0 NOTYPE GLOBAL DEFAULT UND sg2
+ +30: 0+ +0 TLS +GLOBAL DEFAULT UND sg2
+31: [0-9a-f]+ +0 NOTYPE GLOBAL DEFAULT ABS _edata
+32: 0+2080 +0 OBJECT GLOBAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_
+33: [0-9a-f]+ +0 NOTYPE GLOBAL DEFAULT ABS _end
Jakub