aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/loader
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2022-05-06 13:52:23 -0400
committerCherry Mui <cherryyz@google.com>2022-05-12 18:45:57 +0000
commite3f7816f0eae375d261e35d0b541a61c463c9111 (patch)
treecd5194c4cbabf328c778118a683b129cd60e48c7 /src/cmd/link/internal/loader
parentc4c9c80e4f20ca825e66eed254142b1623706b68 (diff)
downloadgo-e3f7816f0eae375d261e35d0b541a61c463c9111.tar.xz
cmd/link: remove name expansion logic
Now both the compiler and the assembler require the -p flag and emit full package path in symbol names, we no longer need to do the name expansion in the linker. Delete it. Change-Id: I771d4d97987a0a17414881b52806d600ef4cc351 Reviewed-on: https://go-review.googlesource.com/c/go/+/404300 Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/link/internal/loader')
-rw-r--r--src/cmd/link/internal/loader/loader.go38
-rw-r--r--src/cmd/link/internal/loader/loader_test.go2
2 files changed, 6 insertions, 34 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index a069540035..0cf9551fae 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -358,9 +358,6 @@ func (l *Loader) addObj(pkg string, r *oReader) Sym {
i := Sym(len(l.objSyms))
l.start[r] = i
l.objs = append(l.objs, objIdx{r, i})
- if r.NeedNameExpansion() && !r.FromAssembly() {
- panic("object compiled without -p")
- }
return i
}
@@ -749,17 +746,7 @@ func (l *Loader) NReachableSym() int {
return l.attrReachable.Count()
}
-// Returns the raw (unpatched) name of the i-th symbol.
-func (l *Loader) RawSymName(i Sym) string {
- if l.IsExternal(i) {
- pp := l.getPayload(i)
- return pp.name
- }
- r, li := l.toLocal(i)
- return r.Sym(li).Name(r.Reader)
-}
-
-// Returns the (patched) name of the i-th symbol.
+// Returns the name of the i-th symbol.
func (l *Loader) SymName(i Sym) string {
if l.IsExternal(i) {
pp := l.getPayload(i)
@@ -769,11 +756,7 @@ func (l *Loader) SymName(i Sym) string {
if r == nil {
return "?"
}
- name := r.Sym(li).Name(r.Reader)
- if !r.NeedNameExpansion() {
- return name
- }
- return strings.Replace(name, "\"\".", r.pkgprefix, -1)
+ return r.Sym(li).Name(r.Reader)
}
// Returns the version of the i-th symbol.
@@ -1012,7 +995,7 @@ func (l *Loader) AttrExternal(i Sym) bool {
// symbol (see AttrExternal).
func (l *Loader) SetAttrExternal(i Sym, v bool) {
if !l.IsExternal(i) {
- panic(fmt.Sprintf("tried to set external attr on non-external symbol %q", l.RawSymName(i)))
+ panic(fmt.Sprintf("tried to set external attr on non-external symbol %q", l.SymName(i)))
}
if v {
l.attrExternal.Set(l.extIndex(i))
@@ -2131,7 +2114,6 @@ func (st *loadState) preloadSyms(r *oReader, kind int) {
panic("preloadSyms: bad kind")
}
l.growAttrBitmaps(len(l.objSyms) + int(end-start))
- needNameExpansion := r.NeedNameExpansion()
loadingRuntimePkg := r.unit.Lib.Pkg == "runtime"
for i := start; i < end; i++ {
osym := r.Sym(i)
@@ -2139,9 +2121,6 @@ func (st *loadState) preloadSyms(r *oReader, kind int) {
var v int
if kind != hashed64Def && kind != hashedDef { // we don't need the name, etc. for hashed symbols
name = osym.Name(r.Reader)
- if needNameExpansion {
- name = strings.Replace(name, "\"\".", r.pkgprefix, -1)
- }
v = abiToVer(osym.ABI(), r.version)
}
gi := st.addSym(name, v, r, i, kind, osym)
@@ -2205,13 +2184,9 @@ func (l *Loader) LoadSyms(arch *sys.Arch) {
func loadObjRefs(l *Loader, r *oReader, arch *sys.Arch) {
// load non-package refs
ndef := uint32(r.NAlldef())
- needNameExpansion := r.NeedNameExpansion()
for i, n := uint32(0), uint32(r.NNonpkgref()); i < n; i++ {
osym := r.Sym(ndef + i)
name := osym.Name(r.Reader)
- if needNameExpansion {
- name = strings.Replace(name, "\"\".", r.pkgprefix, -1)
- }
v := abiToVer(osym.ABI(), r.version)
r.syms[ndef+i] = l.LookupOrCreateSym(name, v)
gi := r.syms[ndef+i]
@@ -2264,7 +2239,7 @@ func abiToVer(abi uint16, localSymVersion int) int {
// anonymous aux or sub-symbol containing some sub-part or payload of
// another symbol.
func (l *Loader) TopLevelSym(s Sym) bool {
- return topLevelSym(l.RawSymName(s), l.SymType(s))
+ return topLevelSym(l.SymName(s), l.SymType(s))
}
// topLevelSym tests a symbol name and kind to determine whether
@@ -2299,9 +2274,6 @@ func (l *Loader) cloneToExternal(symIdx Sym) {
r, li := l.toLocal(symIdx)
osym := r.Sym(li)
sname := osym.Name(r.Reader)
- if r.NeedNameExpansion() {
- sname = strings.Replace(sname, "\"\".", r.pkgprefix, -1)
- }
sver := abiToVer(osym.ABI(), r.version)
skind := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())]
@@ -2432,7 +2404,7 @@ func (l *Loader) UndefinedRelocTargets(limit int) []Sym {
for ri := 0; ri < relocs.Count(); ri++ {
r := relocs.At(ri)
rs := r.Sym()
- if rs != 0 && l.SymType(rs) == sym.SXREF && l.RawSymName(rs) != ".got" {
+ if rs != 0 && l.SymType(rs) == sym.SXREF && l.SymName(rs) != ".got" {
result = append(result, rs)
if limit != -1 && len(result) >= limit {
break
diff --git a/src/cmd/link/internal/loader/loader_test.go b/src/cmd/link/internal/loader/loader_test.go
index 15ae830dc9..b22e2136bb 100644
--- a/src/cmd/link/internal/loader/loader_test.go
+++ b/src/cmd/link/internal/loader/loader_test.go
@@ -198,7 +198,7 @@ func TestAddMaterializedSymbol(t *testing.T) {
}
// Nameless symbol should still be nameless.
- es3name := ldr.RawSymName(es3)
+ es3name := ldr.SymName(es3)
if "" != es3name {
t.Errorf("expected es3 name of '', got '%s'", es3name)
}