]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/x86: implement -shared computation of TLS base
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Thu, 5 Mar 2015 01:21:42 +0000 (14:21 +1300)
committerMinux Ma <minux@golang.org>
Sun, 8 Mar 2015 23:10:18 +0000 (23:10 +0000)
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.

Change-Id: If71a09121d911a863bc07f1828ef76e3a54c1074
Reviewed-on: https://go-review.googlesource.com/6802
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/obj/x86/asm6.go

index ae4780124958446042e15a6f826039ea07a7f5e9..096c37a29f3c278f725eeeeade3905dcd80659ea 100644 (file)
@@ -3765,6 +3765,39 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
                                                        ctxt.Andptr = ctxt.Andptr[1:]
                                                        asmand(ctxt, p, &pp.From, &p.To)
 
+                                               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
+                                                       ctxt.Andptr[0] = 0x00
+                                                       ctxt.Andptr = ctxt.Andptr[1:]
+                                                       ctxt.Andptr[0] = 0x00
+                                                       ctxt.Andptr = ctxt.Andptr[1:]
+                                                       ctxt.Andptr[0] = 0x00
+                                                       ctxt.Andptr = ctxt.Andptr[1:]
+                                                       ctxt.Andptr[0] = 0x00
+                                                       ctxt.Andptr = ctxt.Andptr[1:]
+
                                                case obj.Hplan9:
                                                        if ctxt.Plan9privates == nil {
                                                                ctxt.Plan9privates = obj.Linklookup(ctxt, "_privates", 0)