From 9b0140a6954d65e7a83a7d45a72995ca87301f69 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Fri, 1 Sep 2023 13:12:49 -0700 Subject: [PATCH] cmd/link: type alias sym.LoaderSym and loader.Sym Rather than making these two different types, we can type alias them together. This will ease converting cmd/internal/dwarf to use generics in a subsequent CL. The one unfortunate quirk is that while we'd currently like loader.Sym to be the authoritative type, to break the cycle we have to instead make loader.Sym an alias of sym.LoaderSym. Change-Id: I6dde0d492ca89a478c2470c426bb4eed3393d680 Reviewed-on: https://go-review.googlesource.com/c/go/+/525195 Auto-Submit: Matthew Dempsky Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/cmd/link/internal/ld/dwarf.go | 16 +++------------- src/cmd/link/internal/loader/loader.go | 2 +- src/cmd/link/internal/sym/compilation_unit.go | 2 +- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 36e11cc0d2..19db1b5573 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1513,16 +1513,6 @@ const ( COMPUNITHEADERSIZE = 4 + 2 + 4 + 1 ) -// appendSyms appends the syms from 'src' into 'syms' and returns the -// result. This can go away once we do away with sym.LoaderSym -// entirely. -func appendSyms(syms []loader.Sym, src []sym.LoaderSym) []loader.Sym { - for _, s := range src { - syms = append(syms, loader.Sym(s)) - } - return syms -} - func (d *dwctxt) writeUnitInfo(u *sym.CompilationUnit, abbrevsym loader.Sym, infoEpilog loader.Sym) []loader.Sym { syms := []loader.Sym{} if len(u.Textp) == 0 && u.DWInfo.Child == nil && len(u.VarDIEs) == 0 { @@ -1551,12 +1541,12 @@ func (d *dwctxt) writeUnitInfo(u *sym.CompilationUnit, abbrevsym loader.Sym, inf // This is an under-estimate; more will be needed for type DIEs. cu := make([]loader.Sym, 0, len(u.AbsFnDIEs)+len(u.FuncDIEs)) cu = append(cu, s) - cu = appendSyms(cu, u.AbsFnDIEs) - cu = appendSyms(cu, u.FuncDIEs) + cu = append(cu, u.AbsFnDIEs...) + cu = append(cu, u.FuncDIEs...) if u.Consts != 0 { cu = append(cu, loader.Sym(u.Consts)) } - cu = appendSyms(cu, u.VarDIEs) + cu = append(cu, u.VarDIEs...) var cusize int64 for _, child := range cu { cusize += int64(len(d.ldr.Data(child))) diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 4d0b497d8e..617c6ba65a 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -27,7 +27,7 @@ var _ = fmt.Print // Sym encapsulates a global symbol index, used to identify a specific // Go symbol. The 0-valued Sym is corresponds to an invalid symbol. -type Sym uint32 +type Sym = sym.LoaderSym // Relocs encapsulates the set of relocations on a given symbol; an // instance of this type is returned by the Loader Relocs() method. diff --git a/src/cmd/link/internal/sym/compilation_unit.go b/src/cmd/link/internal/sym/compilation_unit.go index 3bad5bf3f4..3d6cc3cf93 100644 --- a/src/cmd/link/internal/sym/compilation_unit.go +++ b/src/cmd/link/internal/sym/compilation_unit.go @@ -8,7 +8,7 @@ import "cmd/internal/dwarf" // LoaderSym holds a loader.Sym value. We can't refer to this // type from the sym package since loader imports sym. -type LoaderSym int +type LoaderSym uint32 // A CompilationUnit represents a set of source files that are compiled // together. Since all Go sources in a Go package are compiled together, -- 2.48.1