From 14fbec49dce3b655fe667be98e8d3186f786eec1 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 9 Mar 2015 13:21:51 +1300 Subject: [PATCH] cmd/internal/obj/x86: implement -shared computation of TLS base Somehow, terribly embarrassingly, I lost part of the "re-enable -shared on amd64" patch when rebasing before it got submitted. This restores it and also fixes the addend to be the necessary -4. Now updated so that Git will not put the new case into the wrong switch. Change-Id: I1d628232771a6d6ce6d085adf379f94a377822c5 Reviewed-on: https://go-review.googlesource.com/7126 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/internal/obj/x86/asm6.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/cmd/internal/obj/x86/asm6.go b/src/cmd/internal/obj/x86/asm6.go index ae47801249..3bcec5de64 100644 --- a/src/cmd/internal/obj/x86/asm6.go +++ b/src/cmd/internal/obj/x86/asm6.go @@ -3801,6 +3801,32 @@ func doasm(ctxt *obj.Link, p *obj.Prog) { default: log.Fatalf("unknown TLS base location for %s", obj.Headstr(ctxt.Headtype)) + case obj.Hlinux: + if ctxt.Flag_shared == 0 { + log.Fatalf("unknown TLS base location for linux without -shared") + } + // Note that this is not generating the same insn as the other cases. + // MOV TLS, R_to + // becomes + // movq g@gottpoff(%rip), R_to + // which is encoded as + // movq 0(%rip), R_to + // and a R_TLS_IE reloc. This all assumes the only tls variable we access + // is g, which we can't check here, but will when we assemble the second + // instruction. + ctxt.Rexflag = Pw | (regrex[p.To.Reg] & Rxr) + + ctxt.Andptr[0] = 0x8B + ctxt.Andptr = ctxt.Andptr[1:] + ctxt.Andptr[0] = byte(0x05 | (reg[p.To.Reg] << 3)) + ctxt.Andptr = ctxt.Andptr[1:] + r = obj.Addrel(ctxt.Cursym) + r.Off = int32(p.Pc + int64(-cap(ctxt.Andptr)+cap(ctxt.And[:]))) + r.Type = obj.R_TLS_IE + r.Siz = 4 + r.Add = -4 + put4(ctxt, 0) + case obj.Hplan9: if ctxt.Plan9privates == nil { ctxt.Plan9privates = obj.Linklookup(ctxt, "_privates", 0) -- 2.48.1