aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj
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/internal/obj
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/internal/obj')
-rw-r--r--src/cmd/internal/obj/dwarf.go2
-rw-r--r--src/cmd/internal/obj/objfile.go4
-rw-r--r--src/cmd/internal/obj/plist.go2
-rw-r--r--src/cmd/internal/obj/sym.go35
4 files changed, 26 insertions, 17 deletions
diff --git a/src/cmd/internal/obj/dwarf.go b/src/cmd/internal/obj/dwarf.go
index 0cf4addb60..dc06660ab3 100644
--- a/src/cmd/internal/obj/dwarf.go
+++ b/src/cmd/internal/obj/dwarf.go
@@ -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()
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 5ac15b8228..bc22765abc 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -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 {
diff --git a/src/cmd/internal/obj/plist.go b/src/cmd/internal/obj/plist.go
index 9cf6a20bdb..4d4e7eb94b 100644
--- a/src/cmd/internal/obj/plist.go
+++ b/src/cmd/internal/obj/plist.go
@@ -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
diff --git a/src/cmd/internal/obj/sym.go b/src/cmd/internal/obj/sym.go
index ac43a812b9..472ca9eee6 100644
--- a/src/cmd/internal/obj/sym.go
+++ b/src/cmd/internal/obj/sym.go
@@ -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)