Commit 1b8987f1 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

cmd/link: replace SSUB with an attribute bit

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: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1643d4f3
...@@ -348,7 +348,8 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { ...@@ -348,7 +348,8 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
ld.Adddynsym(ctxt, targ) ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0) got := ctxt.Syms.Lookup(".got", 0)
s.Type = got.Type | sym.SSUB s.Type = got.Type
s.Attr |= sym.AttrSubSymbol
s.Outer = got s.Outer = got
s.Sub = got.Sub s.Sub = got.Sub
got.Sub = s got.Sub = s
......
...@@ -106,7 +106,7 @@ func hostArchive(ctxt *Link, name string) { ...@@ -106,7 +106,7 @@ func hostArchive(ctxt *Link, name string) {
var load []uint64 var load []uint64
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R { 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] { if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
load = append(load, off) load = append(load, off)
loaded[off] = true loaded[off] = true
......
...@@ -122,7 +122,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) { ...@@ -122,7 +122,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
continue 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 // When putting the runtime but not main into a shared library
// these symbols are undefined and that's OK. // these symbols are undefined and that's OK.
if ctxt.BuildMode == BuildModeShared { if ctxt.BuildMode == BuildModeShared {
...@@ -148,7 +148,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) { ...@@ -148,7 +148,7 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
// We need to be able to reference dynimport symbols when linking against // We need to be able to reference dynimport symbols when linking against
// shared libraries, and Solaris needs it always // 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.") { 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)) 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) { ...@@ -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) { func blk(ctxt *Link, syms []*sym.Symbol, addr, size int64, pad []byte) {
for i, s := range syms { for i, s := range syms {
if s.Type&sym.SSUB == 0 && s.Value >= addr { if !s.Attr.SubSymbol() && s.Value >= addr {
syms = syms[i:] syms = syms[i:]
break break
} }
...@@ -658,7 +658,7 @@ func blk(ctxt *Link, syms []*sym.Symbol, addr, size int64, pad []byte) { ...@@ -658,7 +658,7 @@ func blk(ctxt *Link, syms []*sym.Symbol, addr, size int64, pad []byte) {
eaddr := addr + size eaddr := addr + size
for _, s := range syms { for _, s := range syms {
if s.Type&sym.SSUB != 0 { if s.Attr.SubSymbol() {
continue continue
} }
if s.Value >= eaddr { if s.Value >= eaddr {
...@@ -1052,7 +1052,7 @@ func (ctxt *Link) dodata() { ...@@ -1052,7 +1052,7 @@ func (ctxt *Link) dodata() {
// Collect data symbols by type into data. // Collect data symbols by type into data.
var data [sym.SXREF][]*sym.Symbol var data [sym.SXREF][]*sym.Symbol
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
if !s.Attr.Reachable() || s.Attr.Special() { if !s.Attr.Reachable() || s.Attr.Special() || s.Attr.SubSymbol() {
continue continue
} }
if s.Type <= sym.STEXT || s.Type >= sym.SXREF { if s.Type <= sym.STEXT || s.Type >= sym.SXREF {
...@@ -1813,7 +1813,7 @@ func (ctxt *Link) textaddress() { ...@@ -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. // 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) { func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint64, isTramp bool) (*sym.Section, int, uint64) {
s.Sect = sect s.Sect = sect
if s.Type&sym.SSUB != 0 { if s.Attr.SubSymbol() {
return sect, n, va return sect, n, va
} }
if s.Align != 0 { if s.Align != 0 {
......
...@@ -2262,7 +2262,7 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) { ...@@ -2262,7 +2262,7 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) {
/* type */ /* type */
t := STB_GLOBAL << 4 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 t |= STT_FUNC
} else { } else {
t |= STT_OBJECT t |= STT_OBJECT
...@@ -2317,9 +2317,9 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) { ...@@ -2317,9 +2317,9 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) {
t := STB_GLOBAL << 4 t := STB_GLOBAL << 4
// TODO(mwhudson): presumably the behavior should actually be the same on both arm and 386. // 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 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 t |= STT_FUNC
} else { } else {
t |= STT_OBJECT t |= STT_OBJECT
......
...@@ -508,7 +508,7 @@ func (ctxt *Link) loadlib() { ...@@ -508,7 +508,7 @@ func (ctxt *Link) loadlib() {
any := false any := false
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R { 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 any = true
break break
} }
...@@ -2006,7 +2006,7 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6 ...@@ -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." { if (s.Name == "" || s.Name[0] == '.') && s.Version == 0 && s.Name != ".rathole" && s.Name != ".TOC." {
continue continue
} }
switch s.Type & sym.SMASK { switch s.Type {
case sym.SCONST, case sym.SCONST,
sym.SRODATA, sym.SRODATA,
sym.SSYMTAB, sym.SSYMTAB,
......
...@@ -1033,7 +1033,8 @@ func initdynimport(ctxt *Link) *Dll { ...@@ -1033,7 +1033,8 @@ func initdynimport(ctxt *Link) *Dll {
dynamic.Type = sym.SWINDOWS dynamic.Type = sym.SWINDOWS
for d := dr; d != nil; d = d.next { for d := dr; d != nil; d = d.next {
for m = d.ms; m != nil; m = m.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 m.s.Sub = dynamic.Sub
dynamic.Sub = m.s dynamic.Sub = m.s
m.s.Value = dynamic.Size m.s.Value = dynamic.Size
......
...@@ -795,7 +795,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i ...@@ -795,7 +795,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i
s.Sub = sect.sym.Sub s.Sub = sect.sym.Sub
sect.sym.Sub = s 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() { if !s.Attr.CgoExportDynamic() {
s.Dynimplib = "" // satisfy dynimport s.Dynimplib = "" // satisfy dynimport
} }
......
...@@ -637,7 +637,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i ...@@ -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) 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 s.Sub = outer.Sub
outer.Sub = s outer.Sub = s
s.Outer = outer s.Outer = outer
......
...@@ -350,7 +350,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, leng ...@@ -350,7 +350,8 @@ func Load(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, leng
sectsym := sectsyms[sect] sectsym := sectsyms[sect]
s.Sub = sectsym.Sub s.Sub = sectsym.Sub
sectsym.Sub = s sectsym.Sub = s
s.Type = sectsym.Type | sym.SSUB s.Type = sectsym.Type
s.Attr |= sym.AttrSubSymbol
s.Value = int64(pesym.Value) s.Value = int64(pesym.Value)
s.Size = 4 s.Size = 4
s.Outer = sectsym s.Outer = sectsym
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package sym package sym
// Attribute is a set of common symbol attributes. // Attribute is a set of common symbol attributes.
type Attribute uint16 type Attribute int32
const ( const (
// AttrDuplicateOK marks a symbol that can be present in multiple object // AttrDuplicateOK marks a symbol that can be present in multiple object
...@@ -57,10 +57,25 @@ const ( ...@@ -57,10 +57,25 @@ const (
// the final executable. Only relevant when internally linking // the final executable. Only relevant when internally linking
// on an ELF platform. // on an ELF platform.
AttrVisibilityHidden 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 // AttrContainer is set on text symbols that are present as the .Outer for some
// other symbol. // other symbol.
AttrContainer AttrContainer
// 16 attributes defined so far. // 17 attributes defined so far.
) )
func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 } func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 }
...@@ -78,6 +93,7 @@ func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 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) MakeTypelink() bool { return a&AttrMakeTypelink != 0 }
func (a Attribute) Shared() bool { return a&AttrShared != 0 } func (a Attribute) Shared() bool { return a&AttrShared != 0 }
func (a Attribute) VisibilityHidden() bool { return a&AttrVisibilityHidden != 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) Container() bool { return a&AttrContainer != 0 }
func (a Attribute) CgoExport() bool { func (a Attribute) CgoExport() bool {
......
...@@ -105,8 +105,6 @@ const ( ...@@ -105,8 +105,6 @@ const (
SDWARFINFO SDWARFINFO
SDWARFRANGE SDWARFRANGE
SDWARFLOC SDWARFLOC
SSUB = SymKind(1 << 8)
SMASK = SymKind(SSUB - 1)
) )
// AbiSymKindToSymKind maps values read from object files (which are // AbiSymKindToSymKind maps values read from object files (which are
......
...@@ -330,7 +330,8 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { ...@@ -330,7 +330,8 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
ld.Adddynsym(ctxt, targ) ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0) got := ctxt.Syms.Lookup(".got", 0)
s.Type = got.Type | sym.SSUB s.Type = got.Type
s.Attr |= sym.AttrSubSymbol
s.Outer = got s.Outer = got
s.Sub = got.Sub s.Sub = got.Sub
got.Sub = s got.Sub = s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment