]> Cypherpunks repositories - gostls13.git/commit
cmd/link: optimize TLS IE to LE in build mode PIE
authorDavid Crawshaw <crawshaw@golang.org>
Tue, 6 Sep 2016 11:46:59 +0000 (07:46 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Sun, 11 Sep 2016 21:13:42 +0000 (21:13 +0000)
commit44ee2b00db9ae21c4304dbfbd19b4bc70f9ff4c9
treed56619ff86d79b0c3a0c1519f8ebf1fe402bcd25
parent1fe4c81282f22b5ac9ba25e7972109255e173b04
cmd/link: optimize TLS IE to LE in build mode PIE

When cmd/compile generates position-independent code on linux
(the -shared flag), it refers to runtime.tlsg as a TLS IE variable.

When cmd/link is linking a PIE executable internally, all TLS IE
relocations are generated by cmd/compile, and the variable they
refer to, runtime.tlsg, is local to the binary. This means we can
optimize this particular IE case to LE, and thus implement IE
support when internally linking.

To do this optimization in the linker, we need to rewrite the
PC-relative MOVD to a constant load. This may seem like an
unconscionable act born of enthusiasm, but it turns out this is
standard operating procedure for linkers. GNU gold does exactly
the same optimization. I spent some time reading it and documented
at least one missing feature from this version.

Part of adding PIE internal linking on linux/amd64.

Change-Id: I1eb068d0ec774724944c6b308aa5084582ecde0b
Reviewed-on: https://go-review.googlesource.com/28540
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/amd64/obj.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/lib.go