|
|
|
cmd/ld: emit TLS relocations during external linking
This CL adds TLS relocation to the ELF .o file we write during external linking,
so that the host linker (gcc) can decide the final location of m and g.
Similar relocations are not necessary on OS X because we use an alternate
program start-time mechanism to acquire thread-local storage.
Similar relocations are not necessary on ARM or Plan 9 or Windows
because external linking mode is not yet supported on those systems.
On almost all ELF systems, the references we use are like %fs:-0x4 or %gs:-0x4,
which we write in 6a/8a as -0x4(FS) or -0x4(GS). On Linux/ELF, however,
Xen's lack of support for this mode forced us long ago to use a two-instruction
sequence: first we load %gs:0x0 into a register r, and then we use -0x4(r).
(The ELF program loader arranges that %gs:0x0 contains a regular pointer to
that same memory location.) In order to relocate those -0x4(r) references,
the linker must know where they are. This CL adds the equivalent notation
-0x4(r)(GS*1) for this purpose: it assembles to the same encoding as -0x4(r)
but the (GS*1) indicates to the linker that this is one of those thread-local
references that needs relocation.
Thanks to Elias Naur for reminding me about this missing piece and
also for writing the test.
Patch Set 1 #Patch Set 2 : diff -r b3cfb8be2faf https://code.google.com/p/go/ #Patch Set 3 : diff -r bcc0898b0026 https://code.google.com/p/go/ #
Total comments: 1
Total messages: 3
|
rsc
Hello iant (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
|
12 years, 9 months ago (2013年03月25日 21:50:48 UTC) #1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hello iant (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
https://codereview.appspot.com/7975045/diff/4001/src/cmd/8l/pass.c File src/cmd/8l/pass.c (right): https://codereview.appspot.com/7975045/diff/4001/src/cmd/8l/pass.c#newcode304 src/cmd/8l/pass.c:304: q->from.index = D_GS; // signal to relocate I don't think this is right when linkmode == LinkExternal. In that case I think we should generate the relocation on the movl and let the system linker sort it out. If we do this, we wind up using a TLS reloc to indirect into the TCB, which pretty much works, but only by accident, and is not what the reloc is intended to do. I will incorporate this CL into 7891047 and submit that instead.
R=close (assigned by rsc@google.com)