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

Issue 87920043: code review 87920043: liblink: introduce TLS register on 386 and amd64 (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by rsc
Modified:
11 years, 1 month ago
Reviewers:
r, iant, bradfitz
CC:
iant, aram, minux1, dave_cheney.net, golang-codereviews
Visibility:
Public.

Description

liblink: introduce TLS register on 386 and amd64 When I did the original 386 ports on Linux and OS X, I chose to define GS-relative expressions like 4(GS) as relative to the actual thread-local storage base, which was usually GS but might not be (it might be FS, or it might be a different constant offset from GS or FS). The original scope was limited but since then the rewrites have gotten out of control. Sometimes GS is rewritten, sometimes FS. Some ports do other rewrites to enable shared libraries and other linking. At no point in the code is it clear whether you are looking at the real GS/FS or some synthesized thing that will be rewritten. The code manipulating all these is duplicated in many places. The first step to fixing issue 7719 is to make the code intelligible again. This CL adds an explicit TLS pseudo-register to the 386 and amd64. As a register, TLS refers to the thread-local storage base, and it can only be loaded into another register: MOVQ TLS, AX An offset from the thread-local storage base is written off(reg)(TLS*1). Semantically it is off(reg), but the (TLS*1) annotation marks this as indexing from the loaded TLS base. This emits a relocation so that if the linker needs to adjust the offset, it can. For example: MOVQ TLS, AX MOVQ 8(AX)(TLS*1), CX // load m into CX On systems that support direct access to the TLS memory, this pair of instructions can be reduced to a direct TLS memory reference: MOVQ 8(TLS), CX // load m into CX The 2-instruction and 1-instruction forms correspond roughly to ELF TLS initial exec mode and ELF TLS local exec mode, respectively. Liblink applies this rewrite on systems that support the 1-instruction form. The decision is made using only the operating system (and probably the -shared flag, eventually), not the link mode. If some link modes on a particular operating system require the 2-instruction form, then all builds for that operating system will use the 2-instruction form, so that the link mode decision can be delayed to link time. Obviously it is late to be making changes like this, but I despair of correcting issue 7719 and issue 7164 without it. To make sure I am not changing existing behavior, I built a "hello world" program for every GOOS/GOARCH combination we have and then worked to make sure that the rewrite generates exactly the same binaries, byte for byte. There are a handful of TODOs in the code marking kludges to get the byte-for-byte property, but at least now I can explain exactly how each binary is handled. The targets I tested this way are: darwin-386 darwin-amd64 dragonfly-386 dragonfly-amd64 freebsd-386 freebsd-amd64 freebsd-arm linux-386 linux-amd64 linux-arm nacl-386 nacl-amd64p32 netbsd-386 netbsd-amd64 openbsd-386 openbsd-amd64 plan9-386 plan9-amd64 solaris-amd64 windows-386 windows-amd64 There were four exceptions to the byte-for-byte goal: windows-386 and windows-amd64 have a time stamp at bytes 137 and 138 of the header. darwin-386 and plan9-386 have five or six modified bytes in the middle of the Go symbol table, caused by editing comments in runtime/sys_{darwin,plan9}_386.s. Fixes issue 7164.

Patch Set 1 #

Patch Set 2 : diff -r 15c88860a91c https://code.google.com/p/go/ #

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

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

Patch Set 5 : diff -r 15c88860a91c https://code.google.com/p/go/ #

Patch Set 6 : diff -r 15c88860a91c https://code.google.com/p/go/ #

Patch Set 7 : diff -r 15c88860a91c https://code.google.com/p/go/ #

Total comments: 20

Patch Set 8 : diff -r 15c88860a91c https://code.google.com/p/go/ #

Patch Set 9 : diff -r ae48c492cd8d https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+491 lines, -397 lines) Patch
M include/link.h View 1 2 3 4 5 6 7 2 chunks +2 lines, -1 line 0 comments Download
M src/cmd/6a/lex.c View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6c/txt.c View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/6l/6.out.h View 1 1 chunk +11 lines, -13 lines 0 comments Download
M src/cmd/6l/obj.c View 1 2 3 4 1 chunk +0 lines, -1 line 0 comments Download
M src/cmd/8a/lex.c View 1 2 3 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8c/txt.c View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/8l/8.out.h View 1 2 1 chunk +12 lines, -14 lines 0 comments Download
M src/cmd/8l/obj.c View 1 2 3 4 1 chunk +0 lines, -1 line 0 comments Download
M src/cmd/dist/buildruntime.c View 1 2 3 4 5 6 1 chunk +12 lines, -89 lines 0 comments Download
M src/cmd/ld/data.c View 1 2 3 chunks +17 lines, -0 lines 0 comments Download
M src/cmd/ld/pobj.c View 1 2 3 4 1 chunk +0 lines, -1 line 0 comments Download
M src/liblink/asm6.c View 1 2 3 4 5 6 7 11 chunks +107 lines, -7 lines 0 comments Download
M src/liblink/asm8.c View 1 2 3 4 5 6 7 11 chunks +119 lines, -7 lines 0 comments Download
M src/liblink/list6.c View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/liblink/list8.c View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/liblink/obj6.c View 1 2 4 chunks +114 lines, -134 lines 0 comments Download
M src/liblink/obj8.c View 1 2 2 chunks +72 lines, -113 lines 0 comments Download
M src/liblink/objfile.c View 1 2 chunks +5 lines, -1 line 0 comments Download
M src/liblink/sym.c View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M src/pkg/runtime/runtime.h View 1 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M src/pkg/runtime/sys_darwin_386.s View 1 2 1 chunk +1 line, -2 lines 0 comments Download
M src/pkg/runtime/sys_linux_386.s View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/sys_nacl_amd64p32.s View 1 2 4 chunks +5 lines, -5 lines 0 comments Download
M src/pkg/runtime/sys_plan9_386.s View 1 2 1 chunk +3 lines, -2 lines 0 comments Download
M src/pkg/runtime/sys_plan9_amd64.s View 1 2 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 10
rsc
Hello iant (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
11 years, 1 month ago (2014-04-15 06:11:25 UTC) #1
rsc
The five or six modified bytes in the middle of the Go symbol table are ...
11 years, 1 month ago (2014-04-15 06:37:58 UTC) #2
aram
[+cc minux] Thank you very much for doing this. It is much more clear than ...
11 years, 1 month ago (2014-04-15 10:58:22 UTC) #3
dave_cheney.net
https://codereview.appspot.com/87920043/diff/100001/src/liblink/obj6.c File src/liblink/obj6.c (right): https://codereview.appspot.com/87920043/diff/100001/src/liblink/obj6.c#newcode106 src/liblink/obj6.c:106: // case Hlinux: so, just windows then ?
11 years, 1 month ago (2014-04-15 12:13:43 UTC) #4
rsc
Thanks for reviewing it. Changes uploaded. https://codereview.appspot.com/87920043/diff/100001/include/link.h File include/link.h (right): https://codereview.appspot.com/87920043/diff/100001/include/link.h#newcode235 include/link.h:235: R_TLS_LE, // TLS ...
11 years, 1 month ago (2014-04-15 14:05:27 UTC) #5
iant
LGTM
11 years, 1 month ago (2014-04-15 17:21:52 UTC) #6
rsc
*** Submitted as https://code.google.com/p/go/source/detail?r=32d26349cf59 *** liblink: introduce TLS register on 386 and amd64 When I ...
11 years, 1 month ago (2014-04-15 17:45:44 UTC) #7
bradfitz
Do you have to update the assembly programming guide now? On Apr 15, 2014 10:45 ...
11 years, 1 month ago (2014-04-15 19:19:35 UTC) #8
r
Yes, if I understood the change properly. -rob On Tue, Apr 15, 2014 at 12:19 ...
11 years, 1 month ago (2014-04-15 19:37:47 UTC) #9
rsc
11 years, 1 month ago (2014-04-15 19:44:09 UTC) #10
I looked at the assembly guide last night, and it doesn't mention any of
the thread-local storage conventions. That's not to say they shouldn't be
there, but there's no existing text to update. The only occurrence of FS or
GS is in some example 6l -a output (but that's a separate issue). I filed
issue 7790.

Russ
Sign in to reply to this message.

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