aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2024-10-31 09:49:47 -0400
committerGopher Robot <gobot@golang.org>2024-11-07 17:47:42 +0000
commit4582f239c3e4589d73dc9e273368f17a196bc09e (patch)
tree8428029b87c2216453c17b848df883f3a715afe3 /src/cmd/link/internal/ld
parent43f889b9e5c45ed53af84419380e8cb69db7c103 (diff)
downloadgo-4582f239c3e4589d73dc9e273368f17a196bc09e.tar.xz
cmd/internal/objabi, cmd/link: introduce SymKind helper methods
These will be necessary when we start using the new FIPS symbols. Split into a separate CL so that these refactoring changes can be tested separate from any FIPS-specific changes. Passes golang.org/x/tools/cmd/toolstash/buildall. Change-Id: I73e5873fcb677f1f572f0668b4dc6f3951d822bc Reviewed-on: https://go-review.googlesource.com/c/go/+/625996 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/link/internal/ld')
-rw-r--r--src/cmd/link/internal/ld/deadcode.go2
-rw-r--r--src/cmd/link/internal/ld/dwarf.go5
-rw-r--r--src/cmd/link/internal/ld/elf.go6
-rw-r--r--src/cmd/link/internal/ld/ld.go2
-rw-r--r--src/cmd/link/internal/ld/lib.go4
-rw-r--r--src/cmd/link/internal/ld/macho.go4
-rw-r--r--src/cmd/link/internal/ld/pe.go10
-rw-r--r--src/cmd/link/internal/ld/symtab.go16
-rw-r--r--src/cmd/link/internal/ld/xcoff.go10
9 files changed, 30 insertions, 29 deletions
diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go
index 6543208c70..b9a15767e7 100644
--- a/src/cmd/link/internal/ld/deadcode.go
+++ b/src/cmd/link/internal/ld/deadcode.go
@@ -50,7 +50,7 @@ func (d *deadcodePass) init() {
n := d.ldr.NDef()
for i := 1; i < n; i++ {
s := loader.Sym(i)
- if d.ldr.SymType(s) == sym.STEXT && d.ldr.SymSize(s) == 0 {
+ if d.ldr.SymType(s).IsText() && d.ldr.SymSize(s) == 0 {
// Zero-sized text symbol is a function deadcoded by the
// compiler. It doesn't really get compiled, and its
// metadata may be missing.
diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go
index b1cce52ae0..7599b937ff 100644
--- a/src/cmd/link/internal/ld/dwarf.go
+++ b/src/cmd/link/internal/ld/dwarf.go
@@ -1965,8 +1965,9 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
continue
}
t := d.ldr.SymType(idx)
- switch t {
- case sym.SRODATA, sym.SDATA, sym.SNOPTRDATA, sym.STYPE, sym.SBSS, sym.SNOPTRBSS, sym.STLSBSS:
+ switch {
+ case t.IsRODATA(), t.IsDATA(), t.IsNOPTRDATA(),
+ t == sym.STYPE, t == sym.SBSS, t == sym.SNOPTRBSS, t == sym.STLSBSS:
// ok
default:
continue
diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go
index 52a284ae9a..3a418d3b61 100644
--- a/src/cmd/link/internal/ld/elf.go
+++ b/src/cmd/link/internal/ld/elf.go
@@ -2414,7 +2414,7 @@ func elfadddynsym(ldr *loader.Loader, target *Target, syms *ArchSyms, s loader.S
/* type */
var t uint8
- if cgoexp && st == sym.STEXT {
+ if cgoexp && st.IsText() {
t = elf.ST_INFO(elf.STB_GLOBAL, elf.STT_FUNC)
} else {
t = elf.ST_INFO(elf.STB_GLOBAL, elf.STT_OBJECT)
@@ -2464,9 +2464,9 @@ func elfadddynsym(ldr *loader.Loader, target *Target, syms *ArchSyms, s loader.S
var t uint8
// TODO(mwhudson): presumably the behavior should actually be the same on both arm and 386.
- if target.Arch.Family == sys.I386 && cgoexp && st == sym.STEXT {
+ if target.Arch.Family == sys.I386 && cgoexp && st.IsText() {
t = elf.ST_INFO(elf.STB_GLOBAL, elf.STT_FUNC)
- } else if target.Arch.Family == sys.ARM && cgoeDynamic && st == sym.STEXT {
+ } else if target.Arch.Family == sys.ARM && cgoeDynamic && st.IsText() {
t = elf.ST_INFO(elf.STB_GLOBAL, elf.STT_FUNC)
} else {
t = elf.ST_INFO(elf.STB_GLOBAL, elf.STT_OBJECT)
diff --git a/src/cmd/link/internal/ld/ld.go b/src/cmd/link/internal/ld/ld.go
index 774dc84897..082aa137e6 100644
--- a/src/cmd/link/internal/ld/ld.go
+++ b/src/cmd/link/internal/ld/ld.go
@@ -221,7 +221,7 @@ func PrepareAddmoduledata(ctxt *Link) (*loader.SymbolBuilder, loader.Sym) {
return nil, 0
}
amd := ctxt.loader.LookupOrCreateSym("runtime.addmoduledata", 0)
- if ctxt.loader.SymType(amd) == sym.STEXT && ctxt.BuildMode != BuildModePlugin {
+ if ctxt.loader.SymType(amd).IsText() && ctxt.BuildMode != BuildModePlugin {
// we're linking a module containing the runtime -> no need for
// an init function
return nil, 0
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index e74c96c09d..f2cf611b20 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -2748,7 +2748,7 @@ func Entryvalue(ctxt *Link) int64 {
if st == 0 {
return *FlagTextAddr
}
- if !ctxt.IsAIX() && st != sym.STEXT {
+ if !ctxt.IsAIX() && !st.IsText() {
ldr.Errorf(s, "entry not text")
}
return ldr.SymValue(s)
@@ -2768,7 +2768,7 @@ func (ctxt *Link) callgraph() {
if rs == 0 {
continue
}
- if r.Type().IsDirectCall() && ldr.SymType(rs) == sym.STEXT {
+ if r.Type().IsDirectCall() && ldr.SymType(rs).IsText() {
ctxt.Logf("%s calls %s\n", ldr.SymName(s), ldr.SymName(rs))
}
}
diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go
index 57b7cd9c4c..1e7c8629ef 100644
--- a/src/cmd/link/internal/ld/macho.go
+++ b/src/cmd/link/internal/ld/macho.go
@@ -866,7 +866,7 @@ func collectmachosyms(ctxt *Link) {
if !*FlagS {
if !ctxt.DynlinkingGo() {
s := ldr.Lookup("runtime.text", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
addsym(s)
}
}
@@ -880,7 +880,7 @@ func collectmachosyms(ctxt *Link) {
}
if !ctxt.DynlinkingGo() {
s := ldr.Lookup("runtime.etext", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
addsym(s)
}
}
diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go
index 09867ec7c9..d4d6abe153 100644
--- a/src/cmd/link/internal/ld/pe.go
+++ b/src/cmd/link/internal/ld/pe.go
@@ -736,7 +736,7 @@ func (f *peFile) mapToPESection(ldr *loader.Loader, s loader.Sym, linkmode LinkM
if linkmode != LinkExternal {
return f.dataSect.index, int64(v), nil
}
- if ldr.SymType(s) == sym.SDATA {
+ if ldr.SymType(s).IsDATA() {
return f.dataSect.index, int64(v), nil
}
// Note: although address of runtime.edata (type sym.SDATA) is at the start of .bss section
@@ -793,8 +793,8 @@ func (f *peFile) writeSymbols(ctxt *Link) {
name = mangleABIName(ctxt, ldr, s, name)
var peSymType uint16 = IMAGE_SYM_TYPE_NULL
- switch t {
- case sym.STEXT, sym.SDYNIMPORT, sym.SHOSTOBJ, sym.SUNDEFEXT:
+ switch {
+ case t.IsText(), t == sym.SDYNIMPORT, t == sym.SHOSTOBJ, t == sym.SUNDEFEXT:
// Microsoft's PE documentation is contradictory. It says that the symbol's complex type
// is stored in the pesym.Type most significant byte, but MSVC, LLVM, and mingw store it
// in the 4 high bits of the less significant byte. Also, the PE documentation says that
@@ -828,11 +828,11 @@ func (f *peFile) writeSymbols(ctxt *Link) {
// Add special runtime.text and runtime.etext symbols.
s := ldr.Lookup("runtime.text", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
addsym(s)
}
s = ldr.Lookup("runtime.etext", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
addsym(s)
}
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index f48e2087c1..7298af5756 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -158,7 +158,7 @@ func putelfsym(ctxt *Link, x loader.Sym, typ elf.SymType, curbind elf.SymBind) {
sname = strings.Replace(sname, "ยท", ".", -1)
}
- if ctxt.DynlinkingGo() && bind == elf.STB_GLOBAL && curbind == elf.STB_LOCAL && ldr.SymType(x) == sym.STEXT {
+ if ctxt.DynlinkingGo() && bind == elf.STB_GLOBAL && curbind == elf.STB_LOCAL && ldr.SymType(x).IsText() {
// When dynamically linking, we want references to functions defined
// in this module to always be to the function object, not to the
// PLT. We force this by writing an additional local symbol for every
@@ -202,7 +202,7 @@ func genelfsym(ctxt *Link, elfbind elf.SymBind) {
if s == 0 {
break
}
- if ldr.SymType(s) != sym.STEXT {
+ if !ldr.SymType(s).IsText() {
panic("unexpected type for runtime.text symbol")
}
putelfsym(ctxt, s, elf.STT_FUNC, elfbind)
@@ -215,7 +215,7 @@ func genelfsym(ctxt *Link, elfbind elf.SymBind) {
// runtime.etext marker symbol.
s = ldr.Lookup("runtime.etext", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
putelfsym(ctxt, s, elf.STT_FUNC, elfbind)
}
@@ -315,11 +315,11 @@ func asmbPlan9Sym(ctxt *Link) {
// Add special runtime.text and runtime.etext symbols.
s := ldr.Lookup("runtime.text", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
putplan9sym(ctxt, ldr, s, TextSym)
}
s = ldr.Lookup("runtime.etext", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
putplan9sym(ctxt, ldr, s, TextSym)
}
@@ -871,8 +871,8 @@ func mangleABIName(ctxt *Link, ldr *loader.Loader, x loader.Sym, name string) st
return name
}
- if ldr.SymType(x) == sym.STEXT && ldr.SymVersion(x) != sym.SymVerABIInternal && ldr.SymVersion(x) < sym.SymVerStatic {
- if s2 := ldr.Lookup(name, sym.SymVerABIInternal); s2 != 0 && ldr.SymType(s2) == sym.STEXT {
+ if ldr.SymType(x).IsText() && ldr.SymVersion(x) != sym.SymVerABIInternal && ldr.SymVersion(x) < sym.SymVerStatic {
+ if s2 := ldr.Lookup(name, sym.SymVerABIInternal); s2 != 0 && ldr.SymType(s2).IsText() {
name = fmt.Sprintf("%s.abi%d", name, ldr.SymVersion(x))
}
}
@@ -883,7 +883,7 @@ func mangleABIName(ctxt *Link, ldr *loader.Loader, x loader.Sym, name string) st
// except symbols that are exported to C. Type symbols are always
// ABIInternal so they are not mangled.
if ctxt.IsShared() {
- if ldr.SymType(x) == sym.STEXT && ldr.SymVersion(x) == sym.SymVerABIInternal && !ldr.AttrCgoExport(x) && !strings.HasPrefix(name, "type:") {
+ if ldr.SymType(x).IsText() && ldr.SymVersion(x) == sym.SymVerABIInternal && !ldr.AttrCgoExport(x) && !strings.HasPrefix(name, "type:") {
name = fmt.Sprintf("%s.abiinternal", name)
}
}
diff --git a/src/cmd/link/internal/ld/xcoff.go b/src/cmd/link/internal/ld/xcoff.go
index 8f566283b1..1bce2cf9b6 100644
--- a/src/cmd/link/internal/ld/xcoff.go
+++ b/src/cmd/link/internal/ld/xcoff.go
@@ -1056,7 +1056,7 @@ func (f *xcoffFile) asmaixsym(ctxt *Link) {
// These symbols won't show up in the first loop below because we
// skip sym.STEXT symbols. Normal sym.STEXT symbols are emitted by walking textp.
s := ldr.Lookup("runtime.text", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
// We've already included this symbol in ctxt.Textp on AIX with external linker.
// See data.go:/textaddress
if !ctxt.IsExternal() {
@@ -1075,14 +1075,14 @@ func (f *xcoffFile) asmaixsym(ctxt *Link) {
if s == 0 {
break
}
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
putaixsym(ctxt, s, TextSym)
}
n++
}
s = ldr.Lookup("runtime.etext", 0)
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
// We've already included this symbol in ctxt.Textp
// on AIX with external linker.
// See data.go:/textaddress
@@ -1255,7 +1255,7 @@ func Xcoffadddynrel(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader
break
}
}
- } else if t := ldr.SymType(s); t == sym.SDATA || t == sym.SNOPTRDATA || t == sym.SBUILDINFO || t == sym.SXCOFFTOC {
+ } else if t := ldr.SymType(s); t.IsDATA() || t.IsNOPTRDATA() || t == sym.SBUILDINFO || t == sym.SXCOFFTOC {
switch ldr.SymSect(targ).Seg {
default:
ldr.Errorf(s, "unknown segment for .loader relocation with symbol %s", ldr.SymName(targ))
@@ -1327,7 +1327,7 @@ func (ctxt *Link) doxcoff() {
panic("cgo_export on static symbol")
}
- if ldr.SymType(s) == sym.STEXT {
+ if ldr.SymType(s).IsText() {
// On AIX, an exported function must have two symbols:
// - a .text symbol which must start with a ".".
// - a .data symbol which is a function descriptor.