cmd/link/ld,cmd/internal/obj,runtime: make the Android TLS offset dynamic

We're going to need a different TLS offset for Android Q, so the static
offsets used for 386 and amd64 are no longer viable on Android.

Introduce runtime·tls_g and use that for indexing into TLS storage. As
an added benefit, we can then merge the TLS setup code for all android
GOARCHs.

While we're at it, remove a bunch of android special cases no longer
needed.

Updates #29674
Updates #29249 (perhaps fixes it)

Change-Id: I77c7385aec7de8f1f6a4da7c9c79999157e39572
Reviewed-on: https://go-review.googlesource.com/c/go/+/169817
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Elias Naur 2019-03-28 13:11:53 +01:00
parent 2cc347382f
commit 1d10b17589
14 changed files with 102 additions and 275 deletions

View file

@ -218,9 +218,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
Errorf(s, "unknown reloc to %v: %d (%s)", r.Sym.Name, r.Type, sym.RelocName(ctxt.Arch, r.Type))
}
case objabi.R_TLS_LE:
isAndroidX86 := objabi.GOOS == "android" && (ctxt.Arch.InFamily(sys.AMD64, sys.I386))
if ctxt.LinkMode == LinkExternal && ctxt.IsELF && !isAndroidX86 {
if ctxt.LinkMode == LinkExternal && ctxt.IsELF {
r.Done = false
if r.Sym == nil {
r.Sym = ctxt.Tlsg
@ -243,7 +241,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
// related to the fact that our own TLS storage happens
// to take up 8 bytes.
o = 8 + r.Sym.Value
} else if ctxt.IsELF || ctxt.HeadType == objabi.Hplan9 || ctxt.HeadType == objabi.Hdarwin || isAndroidX86 {
} else if ctxt.IsELF || ctxt.HeadType == objabi.Hplan9 || ctxt.HeadType == objabi.Hdarwin {
o = int64(ctxt.Tlsoffset) + r.Add
} else if ctxt.HeadType == objabi.Hwindows {
o = r.Add
@ -251,9 +249,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
log.Fatalf("unexpected R_TLS_LE relocation for %v", ctxt.HeadType)
}
case objabi.R_TLS_IE:
isAndroidX86 := objabi.GOOS == "android" && (ctxt.Arch.InFamily(sys.AMD64, sys.I386))
if ctxt.LinkMode == LinkExternal && ctxt.IsELF && !isAndroidX86 {
if ctxt.LinkMode == LinkExternal && ctxt.IsELF {
r.Done = false
if r.Sym == nil {
r.Sym = ctxt.Tlsg