]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: replace SSUB with an attribute bit
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Fri, 28 Apr 2017 01:01:03 +0000 (13:01 +1200)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 24 Oct 2017 23:06:28 +0000 (23:06 +0000)
There is some stuff I don't understand very well involved in SSUB, better words
for the documentation gratefully accepted.

As this is the last use of a bit in SMASK, kill that off too.

Change-Id: Iddff1c9b2af02c9dfb12ac8e668d004e4642f997
Reviewed-on: https://go-review.googlesource.com/42026
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

12 files changed:
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/ld/ar.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/loadelf/ldelf.go
src/cmd/link/internal/loadmacho/ldmacho.go
src/cmd/link/internal/loadpe/ldpe.go
src/cmd/link/internal/sym/attribute.go
src/cmd/link/internal/sym/symkind.go
src/cmd/link/internal/x86/asm.go

index ca652f835342bf40840d6d6e2de64d2950134069..4f426d7bb6f473a36dd56c86e7c4284b2a47ef48 100644 (file)
@@ -348,7 +348,8 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
                        ld.Adddynsym(ctxt, targ)
 
                        got := ctxt.Syms.Lookup(".got", 0)
-                       s.Type = got.Type | sym.SSUB
+                       s.Type = got.Type
+                       s.Attr |= sym.AttrSubSymbol
                        s.Outer = got
                        s.Sub = got.Sub
                        got.Sub = s
index 13e29aa1a3f38e30471ee87f5a95c0923e488f0f..4b513041a377dbf9cfa07bc50a20ce2abf815fb6 100644 (file)
@@ -106,7 +106,7 @@ func hostArchive(ctxt *Link, name string) {
                var load []uint64
                for _, s := range ctxt.Syms.Allsym {
                        for _, r := range s.R {
-                               if r.Sym != nil && r.Sym.Type&sym.SMASK == sym.SXREF {
+                               if r.Sym != nil && r.Sym.Type == sym.SXREF {
                                        if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
                                                load = append(load, off)
                                                loaded[off] = true
index cb824811aa1d7af5f8bb1ac91bd61002a5a7313d..3572d7309dbce0da1abe97ff2e3509e4108d6aec 100644 (file)
@@ -122,7 +122,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
                        continue
                }
 
-               if r.Sym != nil && ((r.Sym.Type == 0 && !r.Sym.Attr.VisibilityHidden()) || r.Sym.Type&sym.SMASK == sym.SXREF) {
+               if r.Sym != nil && ((r.Sym.Type == 0 && !r.Sym.Attr.VisibilityHidden()) || r.Sym.Type == sym.SXREF) {
                        // When putting the runtime but not main into a shared library
                        // these symbols are undefined and that's OK.
                        if ctxt.BuildMode == BuildModeShared {
@@ -148,7 +148,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
 
                // We need to be able to reference dynimport symbols when linking against
                // shared libraries, and Solaris needs it always
-               if ctxt.HeadType != objabi.Hsolaris && r.Sym != nil && r.Sym.Type == sym.SDYNIMPORT && !ctxt.DynlinkingGo() {
+               if ctxt.HeadType != objabi.Hsolaris && r.Sym != nil && r.Sym.Type == sym.SDYNIMPORT && !ctxt.DynlinkingGo() && !r.Sym.Attr.SubSymbol() {
                        if !(ctxt.Arch.Family == sys.PPC64 && ctxt.LinkMode == LinkExternal && r.Sym.Name == ".TOC.") {
                                Errorf(s, "unhandled relocation for %s (type %d (%s) rtype %d (%s))", r.Sym.Name, r.Sym.Type, r.Sym.Type, r.Type, sym.RelocName(ctxt.Arch, r.Type))
                        }
@@ -650,7 +650,7 @@ func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
 
 func blk(ctxt *Link, syms []*sym.Symbol, addr, size int64, pad []byte) {
        for i, s := range syms {
-               if s.Type&sym.SSUB == 0 && s.Value >= addr {
+               if !s.Attr.SubSymbol() && s.Value >= addr {
                        syms = syms[i:]
                        break
                }
@@ -658,7 +658,7 @@ func blk(ctxt *Link, syms []*sym.Symbol, addr, size int64, pad []byte) {
 
        eaddr := addr + size
        for _, s := range syms {
-               if s.Type&sym.SSUB != 0 {
+               if s.Attr.SubSymbol() {
                        continue
                }
                if s.Value >= eaddr {
@@ -1052,7 +1052,7 @@ func (ctxt *Link) dodata() {
        // Collect data symbols by type into data.
        var data [sym.SXREF][]*sym.Symbol
        for _, s := range ctxt.Syms.Allsym {
-               if !s.Attr.Reachable() || s.Attr.Special() {
+               if !s.Attr.Reachable() || s.Attr.Special() || s.Attr.SubSymbol() {
                        continue
                }
                if s.Type <= sym.STEXT || s.Type >= sym.SXREF {
@@ -1813,7 +1813,7 @@ func (ctxt *Link) textaddress() {
 // will not need to create new text sections, and so no need to return sect and n.
 func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint64, isTramp bool) (*sym.Section, int, uint64) {
        s.Sect = sect
-       if s.Type&sym.SSUB != 0 {
+       if s.Attr.SubSymbol() {
                return sect, n, va
        }
        if s.Align != 0 {
index 230b0aa5df18bb1d4f96b37ebaae62946b3a380b..d56a2359d3876d2f66770904dd1d9bc45c4992d0 100644 (file)
@@ -2262,7 +2262,7 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) {
                /* type */
                t := STB_GLOBAL << 4
 
-               if s.Attr.CgoExport() && s.Type&sym.SMASK == sym.STEXT {
+               if s.Attr.CgoExport() && s.Type == sym.STEXT {
                        t |= STT_FUNC
                } else {
                        t |= STT_OBJECT
@@ -2317,9 +2317,9 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) {
                t := STB_GLOBAL << 4
 
                // TODO(mwhudson): presumably the behavior should actually be the same on both arm and 386.
-               if ctxt.Arch.Family == sys.I386 && s.Attr.CgoExport() && s.Type&sym.SMASK == sym.STEXT {
+               if ctxt.Arch.Family == sys.I386 && s.Attr.CgoExport() && s.Type == sym.STEXT {
                        t |= STT_FUNC
-               } else if ctxt.Arch.Family == sys.ARM && s.Attr.CgoExportDynamic() && s.Type&sym.SMASK == sym.STEXT {
+               } else if ctxt.Arch.Family == sys.ARM && s.Attr.CgoExportDynamic() && s.Type == sym.STEXT {
                        t |= STT_FUNC
                } else {
                        t |= STT_OBJECT
index 083c56c13104687da1ce71412b3fe12af00dcf44..26ce209f1c87a30d1322bbfeaaa079e13b038d15 100644 (file)
@@ -508,7 +508,7 @@ func (ctxt *Link) loadlib() {
                any := false
                for _, s := range ctxt.Syms.Allsym {
                        for _, r := range s.R {
-                               if r.Sym != nil && r.Sym.Type&sym.SMASK == sym.SXREF && r.Sym.Name != ".got" {
+                               if r.Sym != nil && r.Sym.Type == sym.SXREF && r.Sym.Name != ".got" {
                                        any = true
                                        break
                                }
@@ -2006,7 +2006,7 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6
                if (s.Name == "" || s.Name[0] == '.') && s.Version == 0 && s.Name != ".rathole" && s.Name != ".TOC." {
                        continue
                }
-               switch s.Type & sym.SMASK {
+               switch s.Type {
                case sym.SCONST,
                        sym.SRODATA,
                        sym.SSYMTAB,
index f870d5d917048c5992d8c692b70974fc6f715602..550ffc1659f4edd714ea4bf0bf831d6bc2158233 100644 (file)
@@ -1033,7 +1033,8 @@ func initdynimport(ctxt *Link) *Dll {
                dynamic.Type = sym.SWINDOWS
                for d := dr; d != nil; d = d.next {
                        for m = d.ms; m != nil; m = m.next {
-                               m.s.Type = sym.SWINDOWS | sym.SSUB
+                               m.s.Type = sym.SWINDOWS
+                               m.s.Attr |= sym.AttrSubSymbol
                                m.s.Sub = dynamic.Sub
                                dynamic.Sub = m.s
                                m.s.Value = dynamic.Size
index 5cae1070ceae95c7e689f1c061fcc453f33c3bc0..793fd961d12b4cbe26ad4cf3932acf51e15be600 100644 (file)
@@ -795,7 +795,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i
 
                s.Sub = sect.sym.Sub
                sect.sym.Sub = s
-               s.Type = sect.sym.Type | s.Type&^sym.SMASK | sym.SSUB
+               s.Type = sect.sym.Type
+               s.Attr |= sym.AttrSubSymbol
                if !s.Attr.CgoExportDynamic() {
                        s.Dynimplib = "" // satisfy dynimport
                }
index bcea6c731aee0fee7b756cb6e8b43587ca5c7411..e6b0f70e3822a54f7f25298c0b739953109b457e 100644 (file)
@@ -637,7 +637,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i
                        return errorf("duplicate symbol reference: %s in both %s and %s", s.Name, s.Outer.Name, sect.sym.Name)
                }
 
-               s.Type = outer.Type | sym.SSUB
+               s.Type = outer.Type
+               s.Attr |= sym.AttrSubSymbol
                s.Sub = outer.Sub
                outer.Sub = s
                s.Outer = outer
index 5f62760c2088b80406fbe5773a891dc7c0b1db92..09c9e31c2e3518ff7caa46a3e7af0faf3345d014 100644 (file)
@@ -350,7 +350,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, leng
                sectsym := sectsyms[sect]
                s.Sub = sectsym.Sub
                sectsym.Sub = s
-               s.Type = sectsym.Type | sym.SSUB
+               s.Type = sectsym.Type
+               s.Attr |= sym.AttrSubSymbol
                s.Value = int64(pesym.Value)
                s.Size = 4
                s.Outer = sectsym
index 1a14c932d5f15178f8ed3a353c4b999bab8d1ecc..45a7939d677947513def73081664bfe580d0b935 100644 (file)
@@ -5,7 +5,7 @@
 package sym
 
 // Attribute is a set of common symbol attributes.
-type Attribute uint16
+type Attribute int32
 
 const (
        // AttrDuplicateOK marks a symbol that can be present in multiple object
@@ -57,10 +57,25 @@ const (
        // the final executable. Only relevant when internally linking
        // on an ELF platform.
        AttrVisibilityHidden
+       // AttrSubSymbol mostly means that the symbol appears on the Sub list of some
+       // other symbol.  Unfortunately, it's not 100% reliable; at least, it's not set
+       // correctly for the .TOC. symbol in Link.dodata.  Usually the Outer field of the
+       // symbol points to the symbol whose list it is on, but that it is not set for the
+       // symbols added to .windynamic in initdynimport in pe.go.
+       //
+       // TODO(mwhudson): fix the inconsistencies noticed above.
+       //
+       // Sub lists are used when loading host objects (sections from the host object
+       // become regular linker symbols and symbols go on the Sub list of their section)
+       // and for constructing the global offset table when internally linking a dynamic
+       // executable.
+       //
+       // TOOD(mwhudson): perhaps a better name for this is AttrNonGoSymbol.
+       AttrSubSymbol
        // AttrContainer is set on text symbols that are present as the .Outer for some
        // other symbol.
        AttrContainer
-       // 16 attributes defined so far.
+       // 17 attributes defined so far.
 )
 
 func (a Attribute) DuplicateOK() bool      { return a&AttrDuplicateOK != 0 }
@@ -78,6 +93,7 @@ func (a Attribute) ReflectMethod() bool    { return a&AttrReflectMethod != 0 }
 func (a Attribute) MakeTypelink() bool     { return a&AttrMakeTypelink != 0 }
 func (a Attribute) Shared() bool           { return a&AttrShared != 0 }
 func (a Attribute) VisibilityHidden() bool { return a&AttrVisibilityHidden != 0 }
+func (a Attribute) SubSymbol() bool        { return a&AttrSubSymbol != 0 }
 func (a Attribute) Container() bool        { return a&AttrContainer != 0 }
 
 func (a Attribute) CgoExport() bool {
index 4b92917846f7df1a99eeaf8036e727110452b090..68522a39d2128b6085706330fe13160b4a9dd655 100644 (file)
@@ -105,8 +105,6 @@ const (
        SDWARFINFO
        SDWARFRANGE
        SDWARFLOC
-       SSUB       = SymKind(1 << 8)
-       SMASK      = SymKind(SSUB - 1)
 )
 
 // AbiSymKindToSymKind maps values read from object files (which are
index 2230384303ee7c25e4b35979fc081d7e72a19de6..56d502c2dd1c3e5c93056e2775cb3f8658912cb5 100644 (file)
@@ -330,7 +330,8 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
                        ld.Adddynsym(ctxt, targ)
 
                        got := ctxt.Syms.Lookup(".got", 0)
-                       s.Type = got.Type | sym.SSUB
+                       s.Type = got.Type
+                       s.Attr |= sym.AttrSubSymbol
                        s.Outer = got
                        s.Sub = got.Sub
                        got.Sub = s