]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: remove name expansion logic
authorCherry Mui <cherryyz@google.com>
Fri, 6 May 2022 17:52:23 +0000 (13:52 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 12 May 2022 18:45:57 +0000 (18:45 +0000)
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>

src/cmd/internal/goobj/objfile.go
src/cmd/link/internal/ld/go.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/loader/loader.go
src/cmd/link/internal/loader/loader_test.go
src/cmd/link/internal/loadmacho/ldmacho.go

index 34c5bb97f8b1ca4fa64df68971e8687e4e6f70b4..39b86b0f8fef7b0d901f7f70e0dcae8021c94721 100644 (file)
@@ -872,7 +872,6 @@ func (r *Reader) Flags() uint32 {
        return r.h.Flags
 }
 
-func (r *Reader) Shared() bool            { return r.Flags()&ObjFlagShared != 0 }
-func (r *Reader) NeedNameExpansion() bool { return false } // TODO: delete
-func (r *Reader) FromAssembly() bool      { return r.Flags()&ObjFlagFromAssembly != 0 }
-func (r *Reader) Unlinkable() bool        { return r.Flags()&ObjFlagUnlinkable != 0 }
+func (r *Reader) Shared() bool       { return r.Flags()&ObjFlagShared != 0 }
+func (r *Reader) FromAssembly() bool { return r.Flags()&ObjFlagFromAssembly != 0 }
+func (r *Reader) Unlinkable() bool   { return r.Flags()&ObjFlagUnlinkable != 0 }
index fc63b30c80f1b8a6dd5c31fe1e9ad503efd2a7ff..1affe24916593e51be3679dec9a43a5c72ff9628 100644 (file)
@@ -26,11 +26,6 @@ import (
 
 // go-specific code shared across loaders (5l, 6l, 8l).
 
-// replace all "". with pkg.
-func expandpkg(t0 string, pkg string) string {
-       return strings.Replace(t0, `"".`, pkg+".", -1)
-}
-
 // TODO:
 //     generate debugging section in binary.
 //     once the dust settles, try to move some code to
@@ -146,7 +141,6 @@ func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string, host
                                continue
                        }
 
-                       local = expandpkg(local, pkg)
                        q := ""
                        if i := strings.Index(remote, "#"); i >= 0 {
                                remote, q = remote[:i], remote[i+1:]
@@ -193,7 +187,6 @@ func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string, host
                        if len(f) > 2 {
                                remote = f[2]
                        }
-                       local = expandpkg(local, pkg)
                        // The compiler adds a fourth argument giving
                        // the definition ABI of function symbols.
                        abi := obj.ABI0
index 8633222ee332fbd9cb717a49acff6af2c15bb2cf..e7fd1cde9748b2bbfaa8503d9a3532b40fee9c07 100644 (file)
@@ -920,7 +920,7 @@ func collectmachosyms(ctxt *Link) {
                if ldr.AttrNotInSymbolTable(s) {
                        return false
                }
-               name := ldr.RawSymName(s) // TODO: try not to read the name
+               name := ldr.SymName(s) // TODO: try not to read the name
                if name == "" || name[0] == '.' {
                        return false
                }
@@ -1019,7 +1019,7 @@ func machoShouldExport(ctxt *Link, ldr *loader.Loader, s loader.Sym) bool {
        if ctxt.BuildMode == BuildModePlugin && strings.HasPrefix(ldr.SymExtname(s), objabi.PathToPrefix(*flagPluginPath)) {
                return true
        }
-       name := ldr.RawSymName(s)
+       name := ldr.SymName(s)
        if strings.HasPrefix(name, "go.itab.") {
                return true
        }
index b7d413e9a9eb00a3886fbf39874ed840ee48bea4..6d1cd7283ac2a20726981a7202e606d5a27bf569 100644 (file)
@@ -780,7 +780,7 @@ func (f *peFile) writeSymbols(ctxt *Link) {
                if ldr.AttrNotInSymbolTable(s) {
                        return false
                }
-               name := ldr.RawSymName(s) // TODO: try not to read the name
+               name := ldr.SymName(s) // TODO: try not to read the name
                if name == "" || name[0] == '.' {
                        return false
                }
index 63e140aa7181aa85ea3ed4e951cd468e8c3d8283..cc6a2c0e10714a6f3843c1108df34d966d8fee34 100644 (file)
@@ -329,7 +329,7 @@ func asmbPlan9Sym(ctxt *Link) {
                if ldr.AttrNotInSymbolTable(s) {
                        return false
                }
-               name := ldr.RawSymName(s) // TODO: try not to read the name
+               name := ldr.SymName(s) // TODO: try not to read the name
                if name == "" || name[0] == '.' {
                        return false
                }
index a069540035a542b1c856113b87aedd42f91be5c5..0cf9551faeee7e2f793e74fe296fe7d0dcca83f2 100644 (file)
@@ -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
index 15ae830dc948af487c7a3313bed61367b52181df..b22e2136bbfa39410122adfc01d2b1a433bb98e3 100644 (file)
@@ -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)
        }
index 5402ecd74848522e9a23131796b7081631c9badb..6e783929e32b945a34928cfc5f3fcd6c1bae79e2 100644 (file)
@@ -686,7 +686,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                        textp = append(textp, s)
                        for s1 := bld.Sub(); s1 != 0; s1 = l.SubSym(s1) {
                                if l.AttrOnList(s1) {
-                                       return errorf("symbol %s listed multiple times", l.RawSymName(s1))
+                                       return errorf("symbol %s listed multiple times", l.SymName(s1))
                                }
                                l.SetAttrOnList(s1, true)
                                textp = append(textp, s1)