]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: some platform independent bits of proper toolchain support for...
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 11 Aug 2015 00:29:00 +0000 (12:29 +1200)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 3 Sep 2015 14:06:07 +0000 (14:06 +0000)
Also simplifies some silliness around making the .tbss section wrt internal
vs external linking. The "make TLS make sense" project has quite a few more
steps to go.

Issue #11270

Change-Id: Ia4fa135cb22d916728ead95bdbc0ebc1ae06f05c
Reviewed-on: https://go-review.googlesource.com/13990
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/obj/data.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/textflag.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/runtime/textflag.h

index 6e01e6e3709505079e0b636781b876e183b6d06a..6645b6969d0c99d167d774713ef26abdb8aaedfb 100644 (file)
@@ -63,6 +63,9 @@ func savedata(ctxt *Link, s *LSym, p *Prog, pn string) {
        if ctxt.Enforce_data_order != 0 && off < int32(len(s.P)) {
                ctxt.Diag("data out of order (already have %d)\n%v", len(s.P), p)
        }
+       if s.Type == SBSS || s.Type == STLSBSS {
+               ctxt.Diag("cannot supply data for BSS var")
+       }
        Symgrow(ctxt, s, int64(off+siz))
 
        switch int(p.To.Type) {
index c5f48203628f4c3f49bc40ed5418391b81845019..76054e2709e73c055ad76b71ab552c9400d8acc7 100644 (file)
@@ -194,6 +194,8 @@ func Writeobjdirect(ctxt *Link, b *Biobuf) {
                                        s.Type = SRODATA
                                } else if flag&NOPTR != 0 {
                                        s.Type = SNOPTRBSS
+                               } else if flag&TLSBSS != 0 {
+                                       s.Type = STLSBSS
                                }
                                edata = s
                                continue
index dbd1bc8a7b2e998e4e897d1b7fd49fea2e8fdd2e..77766c9b3f1cdfcdf9efee6bc617786111eb49ff 100644 (file)
@@ -35,4 +35,8 @@ const (
 
        // When passed to ggloblsym, causes Local to be set to true on the LSym it creates.
        LOCAL = 128
+
+       // Allocate a word of thread local storage and store the offset from the
+       // thread local base to the thread local storage in this variable.
+       TLSBSS = 256
 )
index 91a5edd3760a86e3c39d42b9879dd8be0ac15802..f1561d3c827eb704b1f81b5b23bf655de3cdff0a 100644 (file)
@@ -1401,26 +1401,25 @@ func dodata() {
                Diag("data or bss segment too large")
        }
 
-       if Iself && Linkmode == LinkExternal && s != nil && s.Type == obj.STLSBSS && HEADTYPE != obj.Hopenbsd {
-               sect := addsection(&Segdata, ".tbss", 06)
-               sect.Align = int32(Thearch.Ptrsize)
-               sect.Vaddr = 0
+       if s != nil && s.Type == obj.STLSBSS {
+               if Iself && (Linkmode == LinkExternal || Debug['d'] == 0) && HEADTYPE != obj.Hopenbsd {
+                       sect = addsection(&Segdata, ".tbss", 06)
+                       sect.Align = int32(Thearch.Ptrsize)
+                       sect.Vaddr = 0
+               } else {
+                       sect = nil
+               }
                datsize = 0
+
                for ; s != nil && s.Type == obj.STLSBSS; s = s.Next {
                        datsize = aligndatsize(datsize, s)
                        s.Sect = sect
-                       s.Value = int64(uint64(datsize) - sect.Vaddr)
+                       s.Value = datsize
                        growdatsize(&datsize, s)
                }
 
-               sect.Length = uint64(datsize)
-       } else {
-               // Might be internal linking but still using cgo.
-               // In that case, the only possible STLSBSS symbol is runtime.tlsg.
-               // Give it offset 0, because it's the only thing here.
-               if s != nil && s.Type == obj.STLSBSS && s.Name == "runtime.tlsg" {
-                       s.Value = 0
-                       s = s.Next
+               if sect != nil {
+                       sect.Length = uint64(datsize)
                }
        }
 
@@ -1690,8 +1689,11 @@ func address() {
        var noptrbss *Section
        var vlen int64
        for s := Segdata.Sect; s != nil; s = s.Next {
+               if Iself && s.Name == ".tbss" {
+                       continue
+               }
                vlen = int64(s.Length)
-               if s.Next != nil {
+               if s.Next != nil && !(Iself && s.Next.Name == ".tbss") {
                        vlen = int64(s.Next.Vaddr - s.Vaddr)
                }
                s.Vaddr = va
index 508f0554c7b9e4429ecb7c478310692d9cb7b9f4..187643e41b71652158560ed11091c2080f4e7c8c 100644 (file)
@@ -1508,7 +1508,9 @@ func elfshbits(sect *Section) *ElfShdr {
        }
        sh.addralign = uint64(sect.Align)
        sh.size = sect.Length
-       sh.off = sect.Seg.Fileoff + sect.Vaddr - sect.Seg.Vaddr
+       if sect.Name != ".tbss" || goos == "android" {
+               sh.off = sect.Seg.Fileoff + sect.Vaddr - sect.Seg.Vaddr
+       }
 
        return sh
 }
@@ -2287,12 +2289,20 @@ func Asmbelf(symo int64) {
                // Do not emit PT_TLS for OpenBSD since ld.so(1) does
                // not currently support it. This is handled
                // appropriately in runtime/cgo.
-               if Ctxt.Tlsoffset != 0 && HEADTYPE != obj.Hopenbsd {
-                       ph := newElfPhdr()
-                       ph.type_ = PT_TLS
-                       ph.flags = PF_R
-                       ph.memsz = uint64(-Ctxt.Tlsoffset)
-                       ph.align = uint64(Thearch.Regsize)
+               if HEADTYPE != obj.Hopenbsd {
+                       tlssize := uint64(0)
+                       for sect := Segdata.Sect; sect != nil; sect = sect.Next {
+                               if sect.Name == ".tbss" {
+                                       tlssize = sect.Length
+                               }
+                       }
+                       if tlssize != 0 {
+                               ph := newElfPhdr()
+                               ph.type_ = PT_TLS
+                               ph.flags = PF_R
+                               ph.memsz = tlssize
+                               ph.align = uint64(Thearch.Regsize)
+                       }
                }
        }
 
@@ -2350,16 +2360,6 @@ elfobj:
                sh.flags = 0
        }
 
-       // generate .tbss section for dynamic internal linking (except for OpenBSD)
-       // external linking generates .tbss in data.c
-       if Linkmode == LinkInternal && Debug['d'] == 0 && HEADTYPE != obj.Hopenbsd {
-               sh := elfshname(".tbss")
-               sh.type_ = SHT_NOBITS
-               sh.addralign = uint64(Thearch.Regsize)
-               sh.size = uint64(-Ctxt.Tlsoffset)
-               sh.flags = SHF_ALLOC | SHF_TLS | SHF_WRITE
-       }
-
        if Debug['s'] == 0 {
                sh := elfshname(".symtab")
                sh.type_ = SHT_SYMTAB
index 2a76e76c29655ceb9dc93b9254ee72508bde6753..f2690c938ece3de1226eb46dbf29bf843cc55047 100644 (file)
@@ -21,3 +21,6 @@
 #define WRAPPER 32
 // This function uses its incoming context register.
 #define NEEDCTXT 64
+// Allocate a word of thread local storage and store the offset from the
+// thread local base to the thread local storage in this variable.
+#define TLSBSS 256