On Sun, Nov 27, 2016 at 10:40:02PM +0530, Suprateeka R Hegde wrote:
> On 24-Nov-2016 01:21 AM, Cary Coutant wrote:
> >I'd like to propose amending this statement to the following:
> >
> >"Symbols of type STT_TLS can be referenced only by special
> >thread-local storage relocations. Thread-local storage relocations can
> >reference only symbols of type STT_TLS, or symbols of type STT_SECTION
> >where the referenced section has the SHF_TLS flag."
> 
> That looks complete enough. I have just one thought:
I hesitate to mention it because covering everything leads to
unwieldy specs, but there is one special relocation case:  Relocations
used to mark instructions for optimization.  It is reasonable to allow
these relocations to reference TLS symbols *or* non-TLS symbols.
For example, the PowerPC64 TLS ABI specifies two variants for
small-model __tls_get_addr calls, one for the usual ELF linker managed
GOT, and one for the PowerOpen compiler managed GOT (or TOC).  Notice
how the R_PPC64_TLSGD marker reloc that ties the argument setup insn
with the __tls_get_addr call takes a TLS symbol in the ELF GOT code:
Code sequence			Reloc			Sym
 addi 3,2,x@got@tlsgd		R_PPC64_GOT_TLSGD16	x
 bl __tls_get_addr(x@tlsgd)	R_PPC64_TLSGD		x
				R_PPC64_REL24		__tls_get_addr
 nop
..
GOT[n]				R_PPC64_DTPMOD64	x
GOT[n+1]			R_PPC64_DTPREL64	x
and a non-TLS symbol in the PowerOpec TOC code:
Code sequence			Reloc			Sym
 addi 3,2,.LC0@toc		R_PPC64_TOC16		.LC0
 bl __tls_get_addr(.LC0@tlsgd)	R_PPC64_TLSGD		.LC0
				R_PPC64_REL24		__tls_get_addr
 nop
..
 .section .toc,"aw"
.LC0:
 .quad x@dtpmod			R_PPC64_DTPMOD64	x
 .quad x@dtprel			R_PPC64_DTPREL64	x
> Taking it to runtime, there might be dyn relocs offsetting into PT_TLS? I
> remember reading that in Drepper's TLS paper.
> 
> On HP-UX/IA-64, we have __thread_specific_seg, and thats of type STT_SECTION
> pointing to (with a section index same as) .tbss/.tdata.
> 
> I was just thinking if there is an implementation that uses STT_NOTYPE to
> create a symbol to point to such TLS segments and dyn-reloca are based on
> that? So do we want to include STT_NOTYPE? Or does that become too generic?
I don't see why any such symbol can't be created as STT_TLS.  If
STT_NOTYPE is allowed then linker relocation validity checks are
weakened.
> 
> --
> Supra
> 
> >
> >As the architect of the PA-RISC and IA-64 TLS model that was then
> >adopted into the gABI, I can confirm that this was the intent from the
> >very beginning. The overly-restrictive wording is nothing but an
> >oversight, in my opinion.
> >
> >-cary
> >
-- 
Alan Modra
Australia Development Lab, IBM