Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(53)

Issue 7891047: code review 7891047: cmd/ld: emit TLS relocations during external linking (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 11 months ago by iant
Modified:
11 years, 11 months ago
Reviewers:
CC:
r, golang-dev
Visibility:
Public.

Description

cmd/ld: emit TLS relocations during external linking This CL was written by rsc. I just tweaked 8l. 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 79f4bd3dda85 https://code.google.com/p/go #

Patch Set 3 : diff -r 79f4bd3dda85 https://code.google.com/p/go #

Patch Set 4 : diff -r 43052d8c5ebf https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+800 lines, -852 lines) Patch
A misc/cgo/testtls/tls.go View 1 1 chunk +28 lines, -0 lines 0 comments Download
A misc/cgo/testtls/tls_test.go View 1 1 chunk +13 lines, -0 lines 0 comments Download
A misc/cgo/testtls/tls_unix.c View 1 1 chunk +19 lines, -0 lines 0 comments Download
M src/cmd/5l/5.out.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6l/6.out.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6l/asm.c View 1 1 chunk +7 lines, -0 lines 0 comments Download
M src/cmd/6l/obj.c View 1 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/6l/span.c View 1 2 chunks +23 lines, -0 lines 0 comments Download
M src/cmd/8a/a.y View 1 1 chunk +9 lines, -0 lines 0 comments Download
M src/cmd/8a/y.tab.h View 1 4 chunks +21 lines, -25 lines 0 comments Download
M src/cmd/8a/y.tab.c View 1 117 chunks +535 lines, -795 lines 0 comments Download
M src/cmd/8l/8.out.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8l/asm.c View 1 1 chunk +6 lines, -0 lines 0 comments Download
M src/cmd/8l/obj.c View 1 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/8l/pass.c View 1 2 chunks +33 lines, -17 lines 0 comments Download
M src/cmd/8l/span.c View 1 5 chunks +33 lines, -2 lines 0 comments Download
M src/cmd/dist/buildruntime.c View 1 1 chunk +8 lines, -3 lines 0 comments Download
M src/cmd/ld/data.c View 1 4 chunks +25 lines, -6 lines 0 comments Download
M src/cmd/ld/elf.c View 1 3 chunks +7 lines, -1 line 0 comments Download
M src/cmd/ld/lib.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/ld/symtab.c View 1 1 chunk +20 lines, -0 lines 0 comments Download
M src/run.bash View 1 1 chunk +7 lines, -1 line 0 comments Download

Messages

Total messages: 3
iant
Hello r (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
11 years, 11 months ago (2013-03-27 20:20:57 UTC) #1
r
LGTM
11 years, 11 months ago (2013-03-27 20:21:21 UTC) #2
iant
11 years, 11 months ago (2013-03-27 20:27:37 UTC) #3
*** Submitted as https://code.google.com/p/go/source/detail?r=030625a923ca ***

cmd/ld: emit TLS relocations during external linking

This CL was written by rsc.  I just tweaked 8l.

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.

R=r
CC=golang-dev
https://codereview.appspot.com/7891047
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b