]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/objabi, cmd/link: introduce SymKind helper methods
authorRuss Cox <rsc@golang.org>
Thu, 31 Oct 2024 13:49:47 +0000 (09:49 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 7 Nov 2024 17:47:42 +0000 (17:47 +0000)
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>

26 files changed:
src/cmd/internal/obj/dwarf.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/plist.go
src/cmd/internal/obj/sym.go
src/cmd/internal/objabi/symkind.go
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm/asm.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/dwarf.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/ld.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/macho.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/ld/symtab.go
src/cmd/link/internal/ld/xcoff.go
src/cmd/link/internal/loadelf/ldelf.go
src/cmd/link/internal/loader/loader.go
src/cmd/link/internal/loadmacho/ldmacho.go
src/cmd/link/internal/loadpe/ldpe.go
src/cmd/link/internal/loadxcoff/ldxcoff.go
src/cmd/link/internal/ppc64/asm.go
src/cmd/link/internal/riscv64/asm.go
src/cmd/link/internal/sym/symkind.go
src/cmd/link/internal/x86/asm.go

index 0cf4addb60d4f8a522ebd891d96a5326dfd3f487..dc06660ab384f45a919f48f0f35e3f7ce9d166bb 100644 (file)
@@ -293,7 +293,7 @@ func isDwarf64(ctxt *Link) bool {
 }
 
 func (ctxt *Link) dwarfSym(s *LSym) (dwarfInfoSym, dwarfLocSym, dwarfRangesSym, dwarfAbsFnSym, dwarfDebugLines *LSym) {
-       if s.Type != objabi.STEXT {
+       if !s.Type.IsText() {
                ctxt.Diag("dwarfSym of non-TEXT %v", s)
        }
        fn := s.Func()
index 5ac15b82285052e0d2019831c91df333e1062b40..bc22765abcd91aa7e3c5b9c61395c9b879c78e87 100644 (file)
@@ -896,7 +896,7 @@ func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
                fmt.Fprintf(ctxt.Bso, "asm ")
        }
        fmt.Fprintf(ctxt.Bso, "size=%d", s.Size)
-       if s.Type == objabi.STEXT {
+       if s.Type.IsText() {
                fn := s.Func()
                fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x funcid=%#x align=%#x", uint64(fn.Args), uint64(fn.Locals), uint64(fn.FuncID), uint64(fn.Align))
                if s.Leaf() {
@@ -904,7 +904,7 @@ func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
                }
        }
        fmt.Fprintf(ctxt.Bso, "\n")
-       if s.Type == objabi.STEXT {
+       if s.Type.IsText() {
                for p := s.Func().Text; p != nil; p = p.Link {
                        fmt.Fprintf(ctxt.Bso, "\t%#04x ", uint(int(p.Pc)))
                        if ctxt.Debugasm > 1 {
index 9cf6a20bdb77c54b8b790abb4e695eaf95c4e890..4d4e7eb94b94bd789b545b9d7af889eb7f5d0384 100644 (file)
@@ -250,7 +250,7 @@ func (ctxt *Link) GloblPos(s *LSym, size int64, flag int, pos src.XPos) {
        if flag&RODATA != 0 {
                s.Type = objabi.SRODATA
        } else if flag&NOPTR != 0 {
-               if s.Type == objabi.SDATA {
+               if s.Type.IsDATA() {
                        s.Type = objabi.SNOPTRDATA
                } else {
                        s.Type = objabi.SNOPTRBSS
index ac43a812b91c7323498cf5f118d3a2f134b34e8d..472ca9eee6eacdfd0d20910616229c5dc9f00fce 100644 (file)
@@ -137,13 +137,18 @@ func (ctxt *Link) LookupInit(name string, init func(s *LSym)) *LSym {
        return s
 }
 
+func (ctxt *Link) rodataKind() (suffix string, typ objabi.SymKind) {
+       return "", objabi.SRODATA
+}
+
 func (ctxt *Link) Float32Sym(f float32) *LSym {
+       suffix, typ := ctxt.rodataKind()
        i := math.Float32bits(f)
-       name := fmt.Sprintf("$f32.%08x", i)
+       name := fmt.Sprintf("$f32.%08x%s", i, suffix)
        return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 4
                s.WriteFloat32(ctxt, 0, f)
-               s.Type = objabi.SRODATA
+               s.Type = typ
                s.Set(AttrLocal, true)
                s.Set(AttrContentAddressable, true)
                ctxt.constSyms = append(ctxt.constSyms, s)
@@ -151,12 +156,13 @@ func (ctxt *Link) Float32Sym(f float32) *LSym {
 }
 
 func (ctxt *Link) Float64Sym(f float64) *LSym {
+       suffix, typ := ctxt.rodataKind()
        i := math.Float64bits(f)
-       name := fmt.Sprintf("$f64.%016x", i)
+       name := fmt.Sprintf("$f64.%016x%s", i, suffix)
        return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 8
                s.WriteFloat64(ctxt, 0, f)
-               s.Type = objabi.SRODATA
+               s.Type = typ
                s.Set(AttrLocal, true)
                s.Set(AttrContentAddressable, true)
                ctxt.constSyms = append(ctxt.constSyms, s)
@@ -164,11 +170,12 @@ func (ctxt *Link) Float64Sym(f float64) *LSym {
 }
 
 func (ctxt *Link) Int32Sym(i int64) *LSym {
-       name := fmt.Sprintf("$i32.%08x", uint64(i))
+       suffix, typ := ctxt.rodataKind()
+       name := fmt.Sprintf("$i32.%08x%s", uint64(i), suffix)
        return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 4
                s.WriteInt(ctxt, 0, 4, i)
-               s.Type = objabi.SRODATA
+               s.Type = typ
                s.Set(AttrLocal, true)
                s.Set(AttrContentAddressable, true)
                ctxt.constSyms = append(ctxt.constSyms, s)
@@ -176,11 +183,12 @@ func (ctxt *Link) Int32Sym(i int64) *LSym {
 }
 
 func (ctxt *Link) Int64Sym(i int64) *LSym {
-       name := fmt.Sprintf("$i64.%016x", uint64(i))
+       suffix, typ := ctxt.rodataKind()
+       name := fmt.Sprintf("$i64.%016x%s", uint64(i), suffix)
        return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 8
                s.WriteInt(ctxt, 0, 8, i)
-               s.Type = objabi.SRODATA
+               s.Type = typ
                s.Set(AttrLocal, true)
                s.Set(AttrContentAddressable, true)
                ctxt.constSyms = append(ctxt.constSyms, s)
@@ -188,7 +196,8 @@ func (ctxt *Link) Int64Sym(i int64) *LSym {
 }
 
 func (ctxt *Link) Int128Sym(hi, lo int64) *LSym {
-       name := fmt.Sprintf("$i128.%016x%016x", uint64(hi), uint64(lo))
+       suffix, typ := ctxt.rodataKind()
+       name := fmt.Sprintf("$i128.%016x%016x%s", uint64(hi), uint64(lo), suffix)
        return ctxt.LookupInit(name, func(s *LSym) {
                s.Size = 16
                if ctxt.Arch.ByteOrder == binary.LittleEndian {
@@ -198,7 +207,7 @@ func (ctxt *Link) Int128Sym(hi, lo int64) *LSym {
                        s.WriteInt(ctxt, 0, 8, hi)
                        s.WriteInt(ctxt, 8, 8, lo)
                }
-               s.Type = objabi.SRODATA
+               s.Type = typ
                s.Set(AttrLocal, true)
                s.Set(AttrContentAddressable, true)
                ctxt.constSyms = append(ctxt.constSyms, s)
@@ -406,7 +415,7 @@ func (ctxt *Link) traverseSyms(flag traverseFlag, fn func(*LSym)) {
                        }
                        if flag&traverseAux != 0 {
                                fnNoNil(s.Gotype)
-                               if s.Type == objabi.STEXT {
+                               if s.Type.IsText() {
                                        f := func(parent *LSym, aux *LSym) {
                                                fn(aux)
                                        }
@@ -415,7 +424,7 @@ func (ctxt *Link) traverseSyms(flag traverseFlag, fn func(*LSym)) {
                                        fnNoNil(v.dwarfInfoSym)
                                }
                        }
-                       if flag&traversePcdata != 0 && s.Type == objabi.STEXT {
+                       if flag&traversePcdata != 0 && s.Type.IsText() {
                                fi := s.Func().Pcln
                                fnNoNil(fi.Pcsp)
                                fnNoNil(fi.Pcfile)
@@ -491,7 +500,7 @@ func (ctxt *Link) traverseAuxSyms(flag traverseFlag, fn func(parent *LSym, aux *
                                        fn(s, s.Gotype)
                                }
                        }
-                       if s.Type == objabi.STEXT {
+                       if s.Type.IsText() {
                                ctxt.traverseFuncAux(flag, s, fn, files)
                        } else if v := s.VarInfo(); v != nil && v.dwarfInfoSym != nil {
                                fn(s, v.dwarfInfoSym)
index 463b77689c758771da50cac5bd0d8f6bbbc74ca5..d4ba5f361e1baa1531f918a62b4d9d322a00c23d 100644 (file)
@@ -79,3 +79,19 @@ const (
        SSEHUNWINDINFO
        // Update cmd/link/internal/sym/AbiSymKindToSymKind for new SymKind values.
 )
+
+// IsText reports whether t is one of the text kinds.
+func (t SymKind) IsText() bool {
+       return t == STEXT || t == STEXTFIPS
+}
+
+// IsDATA reports whether t is one of the DATA kinds (SDATA or SDATAFIPS,
+// excluding NOPTRDATA, RODATA, BSS, and so on).
+func (t SymKind) IsDATA() bool {
+       return t == SDATA || t == SDATAFIPS
+}
+
+// IsFIPS reports whether t is one fo the FIPS kinds.
+func (t SymKind) IsFIPS() bool {
+       return t == STEXTFIPS || t == SRODATAFIPS || t == SNOPTRDATAFIPS || t == SDATAFIPS
+}
index 9da0541f5263c26d12740cb279074fa859740f83..9a3af983a37e362416f203a674d643689d88168d 100644 (file)
@@ -263,7 +263,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                return true
 
        case objabi.R_PCREL:
-               if targType == sym.SDYNIMPORT && ldr.SymType(s) == sym.STEXT && target.IsDarwin() {
+               if targType == sym.SDYNIMPORT && ldr.SymType(s).IsText() && target.IsDarwin() {
                        // Loading the address of a dynamic symbol. Rewrite to use GOT.
                        // turn LEAQ symbol address to MOVQ of GOT entry
                        if r.Add() != 0 {
@@ -287,7 +287,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                }
 
        case objabi.R_ADDR:
-               if ldr.SymType(s) == sym.STEXT && target.IsElf() {
+               if ldr.SymType(s).IsText() && target.IsElf() {
                        su := ldr.MakeSymbolUpdater(s)
                        if target.IsSolaris() {
                                addpltsym(target, ldr, syms, targ)
@@ -349,7 +349,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                        // linking, in which case the relocation will be
                        // prepared in the 'reloc' phase and passed to the
                        // external linker in the 'asmb' phase.
-                       if ldr.SymType(s) != sym.SDATA && ldr.SymType(s) != sym.SRODATA {
+                       if t := ldr.SymType(s); !t.IsDATA() && !t.IsRODATA() {
                                break
                        }
                }
index 0443e49197c195cc1eb824b0e668731422ff9b7e..7fd0a99c759bdb4f87369437e61fdc2701b2c588 100644 (file)
@@ -224,7 +224,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                return true
 
        case objabi.R_ADDR:
-               if ldr.SymType(s) != sym.SDATA {
+               if !ldr.SymType(s).IsDATA() {
                        break
                }
                if target.IsElf() {
index 7b85bb3e2615f3ab6d359c5d1ab2c486d372d32d..4ec4b6579366e72d2c77d6b2a182bf71cc995e34 100644 (file)
@@ -305,7 +305,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                return true
 
        case objabi.R_ADDRARM64:
-               if targType == sym.SDYNIMPORT && ldr.SymType(s) == sym.STEXT && target.IsDarwin() {
+               if targType == sym.SDYNIMPORT && ldr.SymType(s).IsText() && target.IsDarwin() {
                        // Loading the address of a dynamic symbol. Rewrite to use GOT.
                        // turn MOVD $sym (adrp+add) into MOVD sym@GOT (adrp+ldr)
                        if r.Add() != 0 {
@@ -339,7 +339,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                }
 
        case objabi.R_ADDR:
-               if ldr.SymType(s) == sym.STEXT && target.IsElf() {
+               if ldr.SymType(s).IsText() && target.IsElf() {
                        // The code is asking for the address of an external
                        // function. We provide it with the address of the
                        // correspondent GOT symbol.
@@ -394,7 +394,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                        // linking, in which case the relocation will be
                        // prepared in the 'reloc' phase and passed to the
                        // external linker in the 'asmb' phase.
-                       if ldr.SymType(s) != sym.SDATA && ldr.SymType(s) != sym.SRODATA {
+                       if t := ldr.SymType(s); !t.IsDATA() && !t.IsRODATA() {
                                break
                        }
                }
@@ -1278,7 +1278,7 @@ func gensymlate(ctxt *ld.Link, ldr *loader.Loader) {
                        continue
                }
                t := ldr.SymType(s)
-               if t == sym.STEXT {
+               if t.IsText() {
                        // Except for Duff's devices (handled above), we don't
                        // target the middle of a function.
                        continue
index 6543208c70fc5944f9727424fec27cdccdbf9a3f..b9a15767e77a86c0cbd97e86b6a943e1ee810ff1 100644 (file)
@@ -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.
index b1cce52ae0f7dff2b3f7358fe94410652bd9a5c5..7599b937ff02d7ab88d93e34a9b9dcbdae2a5b45 100644 (file)
@@ -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
index 52a284ae9a12fadf816e6fb8e7b1f23d5041b279..3a418d3b61ddf2c07b269ee11f2176ed0979e932 100644 (file)
@@ -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)
index 774dc84897bc87587565c8d50ebb8ccc3d860fc4..082aa137e6a04755ecad2c60d77461059125b579 100644 (file)
@@ -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
index e74c96c09dfcc2cc444051fe2836e96d0b7c9d49..f2cf611b20fd67bea192d02b62dca712c4c21efa 100644 (file)
@@ -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))
                        }
                }
index 57b7cd9c4c68d3fa150cb571cc2baf898f5fa2fe..1e7c8629ef4b620305f8e13649219eb33795a3be 100644 (file)
@@ -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)
                        }
                }
index 09867ec7c932875caec4835a9f39bf6b69427e31..d4d6abe153efeb2583654551ac7fec9e4a297631 100644 (file)
@@ -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 {
-               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)
        }
 
index f48e2087c19768087662e713a6ff87227fa01c33..7298af5756cb7a26b90ed8e0d3b65017aeceb71c 100644 (file)
@@ -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)
                }
        }
index 8f566283b11c1ea02d2d09c0b7d8c208cf7c1265..1bce2cf9b6124d41e33ba26385bcd31a8a4e9f9c 100644 (file)
@@ -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.
index 9a560e029f7a884d9c7369320dc7c68968ee3241..e0363b5535ccea3568007e5b0f606103431576e4 100644 (file)
@@ -636,7 +636,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                }
                sb.SetValue(int64(elfsym.value))
                sb.SetSize(int64(elfsym.size))
-               if sectsb.Type() == sym.STEXT {
+               if sectsb.Type().IsText() {
                        if l.AttrExternal(s) && !l.AttrDuplicateOK(s) {
                                return errorf("%s: duplicate symbol definition", sb.Name())
                        }
@@ -674,7 +674,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                if l.SubSym(s) != 0 {
                        sb.SortSub()
                }
-               if sb.Type() == sym.STEXT {
+               if sb.Type().IsText() {
                        if l.AttrOnList(s) {
                                return errorf("symbol %s listed multiple times",
                                        l.SymName(s))
index a391c8ced93bbace4e047113555b07ea3bb094a3..d99dbbd157d035d1ef2a3262ada64fc69c97eb79 100644 (file)
@@ -1623,7 +1623,7 @@ func (l *Loader) Aux(i Sym, j int) Aux {
 // import statement.
 // (https://webassembly.github.io/spec/core/syntax/modules.html#imports)
 func (l *Loader) WasmImportSym(fnSymIdx Sym) Sym {
-       if l.SymType(fnSymIdx) != sym.STEXT {
+       if !l.SymType(fnSymIdx).IsText() {
                log.Fatalf("error: non-function sym %d/%s t=%s passed to WasmImportSym", fnSymIdx, l.SymName(fnSymIdx), l.SymType(fnSymIdx).String())
        }
        return l.aux1(fnSymIdx, goobj.AuxWasmImport)
@@ -1636,7 +1636,7 @@ func (l *Loader) WasmTypeSym(s Sym) Sym {
 // SEHUnwindSym returns the auxiliary SEH unwind symbol associated with
 // a given function symbol.
 func (l *Loader) SEHUnwindSym(fnSymIdx Sym) Sym {
-       if l.SymType(fnSymIdx) != sym.STEXT {
+       if !l.SymType(fnSymIdx).IsText() {
                log.Fatalf("error: non-function sym %d/%s t=%s passed to SEHUnwindSym", fnSymIdx, l.SymName(fnSymIdx), l.SymType(fnSymIdx).String())
        }
 
@@ -1649,7 +1649,7 @@ func (l *Loader) SEHUnwindSym(fnSymIdx Sym) Sym {
 // lookups, e.f. for function with name XYZ we would then look up
 // go.info.XYZ, etc.
 func (l *Loader) GetFuncDwarfAuxSyms(fnSymIdx Sym) (auxDwarfInfo, auxDwarfLoc, auxDwarfRanges, auxDwarfLines Sym) {
-       if l.SymType(fnSymIdx) != sym.STEXT {
+       if !l.SymType(fnSymIdx).IsText() {
                log.Fatalf("error: non-function sym %d/%s t=%s passed to GetFuncDwarfAuxSyms", fnSymIdx, l.SymName(fnSymIdx), l.SymType(fnSymIdx).String())
        }
        r, auxs := l.auxs(fnSymIdx)
@@ -2609,7 +2609,7 @@ func (l *Loader) AssignTextSymbolOrder(libs []*sym.Library, intlibs []bool, exts
                        }
                        osym := r.Sym(i)
                        st := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())]
-                       if st != sym.STEXT {
+                       if !st.IsText() {
                                continue
                        }
                        dupok := osym.Dupok()
index 6e783929e32b945a34928cfc5f3fcd6c1bae79e2..0d2bca28e93c3d0bfc442f19b2282783676185d6 100644 (file)
@@ -645,7 +645,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                if !l.AttrCgoExportDynamic(s) {
                        bld.SetDynimplib("") // satisfy dynimport
                }
-               if l.SymType(outer) == sym.STEXT {
+               if l.SymType(outer).IsText() {
                        if bld.External() && !bld.DuplicateOK() {
                                return errorf("%v: duplicate symbol definition", s)
                        }
@@ -678,7 +678,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                        }
                }
 
-               if bld.Type() == sym.STEXT {
+               if bld.Type().IsText() {
                        if bld.OnList() {
                                return errorf("symbol %s listed multiple times", bld.Name())
                        }
index 1ba6debb4e67b874b267d5743d0c33b4ceb08643..b895ac414941107c3f73b3dba67b8c3a94422c29 100644 (file)
@@ -558,7 +558,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
                l.AddInteriorSym(sectsym, s)
                bld.SetValue(int64(pesym.Value))
                bld.SetSize(4)
-               if l.SymType(sectsym) == sym.STEXT {
+               if l.SymType(sectsym).IsText() {
                        if bld.External() && !bld.DuplicateOK() {
                                return nil, fmt.Errorf("%s: duplicate symbol definition", l.SymName(s))
                        }
@@ -583,7 +583,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
                }
                l.SortSub(s)
                importSymsState.secSyms = append(importSymsState.secSyms, s)
-               if l.SymType(s) == sym.STEXT {
+               if l.SymType(s).IsText() {
                        for ; s != 0; s = l.SubSym(s) {
                                if l.AttrOnList(s) {
                                        return nil, fmt.Errorf("symbol %s listed multiple times", l.SymName(s))
@@ -633,7 +633,7 @@ func PostProcessImports() error {
        arch := importSymsState.arch
        keeprelocneeded := make(map[loader.Sym]loader.Sym)
        for _, s := range importSymsState.secSyms {
-               isText := ldr.SymType(s) == sym.STEXT
+               isText := ldr.SymType(s).IsText()
                relocs := ldr.Relocs(s)
                for i := 0; i < relocs.Count(); i++ {
                        r := relocs.At(i)
index 29d162596a3657d3f2d68c8ce4f1b8c91a45c8c7..fd116d542071333c3613b489155ea247687564ec 100644 (file)
@@ -104,7 +104,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
                s := l.LookupOrCreateSym(sx.Name, 0)
 
                // Text symbol
-               if l.SymType(s) == sym.STEXT {
+               if l.SymType(s).IsText() {
                        if l.AttrOnList(s) {
                                return errorf("symbol %s listed multiple times", l.SymName(s))
                        }
index de5614e92af918c73d10032acb85603f59fac712..94660beba8e648b80255a21ab2fa2227afecbf42 100644 (file)
@@ -272,14 +272,14 @@ func genstubs(ctxt *ld.Link, ldr *loader.Loader) {
                for i := 0; i < relocs.Count(); i++ {
                        switch r := relocs.At(i); r.Type() {
                        case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_REL24), objabi.R_CALLPOWER:
-                               switch ldr.SymType(r.Sym()) {
-                               case sym.SDYNIMPORT:
+                               switch t := ldr.SymType(r.Sym()); {
+                               case t == sym.SDYNIMPORT:
                                        // This call goes through the PLT, generate and call through a PLT stub.
                                        if sym, firstUse := genpltstub(ctxt, ldr, r, i, s); firstUse {
                                                stubs = append(stubs, sym)
                                        }
 
-                               case sym.SXREF:
+                               case t == sym.SXREF:
                                        // Is this an ELF ABI defined function which is (in practice)
                                        // generated by the linker to save/restore callee save registers?
                                        // These are defined similarly for both PPC64 ELF and ELFv2.
@@ -289,7 +289,7 @@ func genstubs(ctxt *ld.Link, ldr *loader.Loader) {
                                                        abifuncs = append(abifuncs, sym)
                                                }
                                        }
-                               case sym.STEXT:
+                               case t.IsText():
                                        targ := r.Sym()
                                        if (ldr.AttrExternal(targ) && ldr.SymLocalentry(targ) != 1) || !ldr.AttrExternal(targ) {
                                                // All local symbols share the same TOC pointer. This caller has a valid TOC
@@ -308,18 +308,18 @@ func genstubs(ctxt *ld.Link, ldr *loader.Loader) {
                                // GOPPC64 and -buildmode.
                                fallthrough
                        case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_REL24_NOTOC):
-                               switch ldr.SymType(r.Sym()) {
-                               case sym.SDYNIMPORT:
+                               switch rt := ldr.SymType(r.Sym()); {
+                               case rt == sym.SDYNIMPORT:
                                        // This call goes through the PLT, generate and call through a PLT stub.
                                        if sym, firstUse := genpltstub(ctxt, ldr, r, i, s); firstUse {
                                                stubs = append(stubs, sym)
                                        }
 
-                               case sym.SXREF:
+                               case rt == sym.SXREF:
                                        // TODO: This is not supported yet.
                                        ldr.Errorf(s, "Unsupported NOTOC external reference call into %s", ldr.SymName(r.Sym()))
 
-                               case sym.STEXT:
+                               case rt.IsText():
                                        targ := r.Sym()
                                        if (ldr.AttrExternal(targ) && ldr.SymLocalentry(targ) <= 1) || (!ldr.AttrExternal(targ) && (!ldr.AttrShared(targ) || hasPCrel)) {
                                                // This is NOTOC to NOTOC call (st_other is 0 or 1). No call stub is needed.
@@ -334,14 +334,14 @@ func genstubs(ctxt *ld.Link, ldr *loader.Loader) {
                        // Handle objects compiled with -fno-plt. Rewrite local calls to avoid indirect calling.
                        // These are 0 sized relocs. They mark the mtctr r12, or bctrl + ld r2,24(r1).
                        case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_PLTSEQ):
-                               if ldr.SymType(r.Sym()) == sym.STEXT {
+                               if ldr.SymType(r.Sym()).IsText() {
                                        // This should be an mtctr instruction. Turn it into a nop.
                                        su := ldr.MakeSymbolUpdater(s)
                                        const MASK_OP_MTCTR = 63<<26 | 0x3FF<<11 | 0x1FF<<1
                                        rewritetonop(&ctxt.Target, ldr, su, int64(r.Off()), MASK_OP_MTCTR, OP_MTCTR)
                                }
                        case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_PLTCALL):
-                               if ldr.SymType(r.Sym()) == sym.STEXT {
+                               if ldr.SymType(r.Sym()).IsText() {
                                        // This relocation should point to a bctrl followed by a ld r2, 24(41)
                                        // Convert the bctrl into a bl.
                                        su := ldr.MakeSymbolUpdater(s)
@@ -631,7 +631,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
        case objabi.ElfRelocOffset + objabi.RelocType(elf.R_PPC64_GOT_PCREL34):
                su := ldr.MakeSymbolUpdater(s)
                su.SetRelocType(rIdx, objabi.R_ADDRPOWER_PCREL34)
-               if targType != sym.STEXT {
+               if !targType.IsText() {
                        ld.AddGotSym(target, ldr, syms, targ, uint32(elf.R_PPC64_GLOB_DAT))
                        su.SetRelocSym(rIdx, syms.GOT)
                        su.SetRelocAdd(rIdx, r.Add()+int64(ldr.SymGot(targ)))
@@ -757,7 +757,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
                        ld.AddGotSym(target, ldr, syms, targ, uint32(elf.R_PPC64_GLOB_DAT))
                        su.SetRelocSym(rIdx, syms.GOT)
                        su.SetRelocAdd(rIdx, r.Add()+int64(ldr.SymGot(targ)))
-               } else if targType == sym.STEXT {
+               } else if targType.IsText() {
                        if isPLT16_LO_DS {
                                // Expect an ld opcode to nop
                                rewritetonop(target, ldr, su, int64(r.Off()), MASK_OP_LD, OP_LD)
@@ -779,7 +779,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
 
        switch r.Type() {
        case objabi.R_ADDR:
-               if ldr.SymType(s) == sym.STEXT {
+               if ldr.SymType(s).IsText() {
                        log.Fatalf("R_ADDR relocation in text symbol %s is unsupported\n", ldr.SymName(s))
                }
                if target.IsPIE() && target.IsInternal() {
@@ -825,7 +825,7 @@ func addelfdynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s lo
                        // linking, in which case the relocation will be
                        // prepared in the 'reloc' phase and passed to the
                        // external linker in the 'asmb' phase.
-                       if ldr.SymType(s) != sym.SDATA && ldr.SymType(s) != sym.SRODATA {
+                       if t := ldr.SymType(s); !t.IsDATA() && !t.IsRODATA() {
                                break
                        }
                }
@@ -1441,7 +1441,7 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
                // local call offsets for externally generated objects are accounted for when converting into golang relocs.
                if !hasPCrel && !ldr.AttrExternal(rs) && ldr.AttrShared(rs) && tgtName != "runtime.duffzero" && tgtName != "runtime.duffcopy" {
                        // Furthermore, only apply the offset if the target looks like the start of a function call.
-                       if r.Add() == 0 && ldr.SymType(rs) == sym.STEXT {
+                       if r.Add() == 0 && ldr.SymType(rs).IsText() {
                                t += 8
                        }
                }
index 73a8815459dee15da9c6131c282f03983f64a439..587b10f5128cfe8d049a6246a624108c7ce88061 100644 (file)
@@ -174,7 +174,7 @@ func genSymsLate(ctxt *ld.Link, ldr *loader.Loader) {
                                r.Type() != objabi.R_RISCV_PCREL_STYPE && r.Type() != objabi.R_RISCV_TLS_IE {
                                continue
                        }
-                       if r.Off() == 0 && ldr.SymType(s) == sym.STEXT {
+                       if r.Off() == 0 && ldr.SymType(s).IsText() {
                                // Use the symbol for the function instead of creating
                                // an overlapping symbol.
                                continue
@@ -206,7 +206,7 @@ func findHI20Symbol(ctxt *ld.Link, ldr *loader.Loader, val int64) loader.Sym {
        if idx >= len(ctxt.Textp) {
                return 0
        }
-       if s := ctxt.Textp[idx]; ldr.SymValue(s) == val && ldr.SymType(s) == sym.STEXT {
+       if s := ctxt.Textp[idx]; ldr.SymValue(s) == val && ldr.SymType(s).IsText() {
                return s
        }
        return 0
index 69d0d0ae2f187b433226aa9e2b2ae3e6d0ad4d67..19c62bca8cc019568f331df4b8de03e1a163247b 100644 (file)
@@ -206,11 +206,31 @@ var RelROMap = map[SymKind]SymKind{
        SFUNCTAB:  SFUNCTABRELRO,
 }
 
-// IsData returns true if the type is a data type.
+// IsText returns true if t is a text type.
+func (t SymKind) IsText() bool {
+       return STEXT <= t && t <= STEXTEND
+}
+
+// IsData returns true if t is any kind of data type.
 func (t SymKind) IsData() bool {
-       return t == SDATA || t == SNOPTRDATA || t == SBSS || t == SNOPTRBSS
+       return SNOPTRDATA <= t && t <= SNOPTRBSS
+}
+
+// IsDATA returns true if t is one of the SDATA types.
+func (t SymKind) IsDATA() bool {
+       return SDATA <= t && t <= SDATAEND
+}
+
+// IsRODATA returns true if t is one of the SRODATA types.
+func (t SymKind) IsRODATA() bool {
+       return SRODATA <= t && t <= SRODATAEND
+}
+
+// IsNOPTRDATA returns true if t is one of the SNOPTRDATA types.
+func (t SymKind) IsNOPTRDATA() bool {
+       return SNOPTRDATA <= t && t <= SNOPTRDATAEND
 }
 
 func (t SymKind) IsDWARF() bool {
-       return t >= SDWARFSECT && t <= SDWARFLINES
+       return SDWARFSECT <= t && t <= SDWARFLINES
 }
index 876dbd984fcacfb81568dd09add93413d0b22231..d535e5fb4d0889feaff098c81bfe73a1f563839d 100644 (file)
@@ -294,7 +294,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
                return true
 
        case objabi.R_ADDR:
-               if ldr.SymType(s) != sym.SDATA {
+               if !ldr.SymType(s).IsDATA() {
                        break
                }
                if target.IsElf() {