]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate fallback code for missing -p flag
authorMatthew Dempsky <mdempsky@google.com>
Sun, 27 Aug 2023 20:55:47 +0000 (13:55 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 29 Aug 2023 18:31:08 +0000 (18:31 +0000)
cmd/compile has required the -p flag since go.dev/cl/391014. It's safe
to eliminate the fallback code that tried to cope without.

Change-Id: I9a62ff829e34a6fa5bfe6ae6a836610cc3f0cd33
Reviewed-on: https://go-review.googlesource.com/c/go/+/523337
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/dwarfgen/dwarf.go
src/cmd/compile/internal/noder/import.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/types/size.go
src/cmd/compile/internal/walk/order.go

index 24f7ea237fdcc106b917bd430126a290ab37be8d..dfb1cfc0d36c0c7902f9f50a19d1face324e7cbb 100644 (file)
@@ -524,9 +524,7 @@ func createComplexVar(fnsym *obj.LSym, fn *ir.Func, varID ssa.VarID) *dwarf.Var
 // in the DWARF info.
 func RecordFlags(flags ...string) {
        if base.Ctxt.Pkgpath == "" {
-               // We can't record the flags if we don't know what the
-               // package name is.
-               return
+               panic("missing pkgpath")
        }
 
        type BoolFlag interface {
index b7008ac5e8b565001c9ee26780d0647edfe63a8e..e9bb1e313b65303641e6d544179c1715b1fb3d37 100644 (file)
@@ -133,7 +133,10 @@ func resolveImportPath(path string) (string, error) {
                return "", errors.New("cannot import \"main\"")
        }
 
-       if base.Ctxt.Pkgpath != "" && path == base.Ctxt.Pkgpath {
+       if base.Ctxt.Pkgpath == "" {
+               panic("missing pkgpath")
+       }
+       if path == base.Ctxt.Pkgpath {
                return "", fmt.Errorf("import %q while compiling that package (import cycle)", path)
        }
 
index 25a6ba7c8893839c82712e3ac79045256531a6cf..4ffc3715beff099be679fed6c42344ddfce48ced 100644 (file)
@@ -265,8 +265,7 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P
                        // user didn't provide one.
                        target = objabi.PathToPrefix(base.Ctxt.Pkgpath) + "." + f[1]
                } else {
-                       p.error(syntax.Error{Pos: pos, Msg: "//go:linkname requires linkname argument or -p compiler flag"})
-                       break
+                       panic("missing pkgpath")
                }
                p.linknames = append(p.linknames, linkname{pos, f[1], target})
 
index 223ba1b7ba36fc90de1cc3dd3afe9a802e2155d8..add708c03fe8dd81b001744f984aabd779566216 100644 (file)
@@ -432,13 +432,7 @@ func dgopkgpath(s *obj.LSym, ot int, pkg *types.Pkg) int {
        }
 
        if pkg == types.LocalPkg && base.Ctxt.Pkgpath == "" {
-               // If we don't know the full import path of the package being compiled
-               // (i.e. -p was not passed on the compiler command line), emit a reference to
-               // type:.importpath.""., which the linker will rewrite using the correct import path.
-               // Every package that imports this one directly defines the symbol.
-               // See also https://groups.google.com/forum/#!topic/golang-dev/myb9s53HxGQ.
-               ns := base.Ctxt.Lookup(`type:.importpath."".`)
-               return objw.SymPtr(s, ot, ns, 0)
+               panic("missing pkgpath")
        }
 
        dimportpath(pkg)
@@ -451,13 +445,7 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int {
                return objw.Uint32(s, ot, 0)
        }
        if pkg == types.LocalPkg && base.Ctxt.Pkgpath == "" {
-               // If we don't know the full import path of the package being compiled
-               // (i.e. -p was not passed on the compiler command line), emit a reference to
-               // type:.importpath.""., which the linker will rewrite using the correct import path.
-               // Every package that imports this one directly defines the symbol.
-               // See also https://groups.google.com/forum/#!topic/golang-dev/myb9s53HxGQ.
-               ns := base.Ctxt.Lookup(`type:.importpath."".`)
-               return objw.SymPtrOff(s, ot, ns)
+               panic("missing pkgpath")
        }
 
        dimportpath(pkg)
@@ -546,7 +534,9 @@ func dname(name, tag string, pkg *types.Pkg, exported, embedded bool) *obj.LSym
                        }
                }
        } else {
-               sname = fmt.Sprintf(`%s"".%d`, sname, dnameCount)
+               // TODO(mdempsky): We should be able to share these too (except
+               // maybe when dynamic linking).
+               sname = fmt.Sprintf("%s%s.%d", sname, types.LocalPkg.Prefix, dnameCount)
                dnameCount++
        }
        if embedded {
index 59cf97079573b995a924e300de3df8b79e259c2e..9e38b8c0d106662a2c5027ef600896084d169ce9 100644 (file)
@@ -195,8 +195,10 @@ func calcStructOffset(t *Type, fields []*Field, offset int64) int64 {
 }
 
 func isAtomicStdPkg(p *Pkg) bool {
-       return (p.Prefix == "sync/atomic" || p.Prefix == `""` && base.Ctxt.Pkgpath == "sync/atomic") ||
-               (p.Prefix == "runtime/internal/atomic" || p.Prefix == `""` && base.Ctxt.Pkgpath == "runtime/internal/atomic")
+       if p.Prefix == `""` {
+               panic("bad package prefix")
+       }
+       return p.Prefix == "sync/atomic" || p.Prefix == "runtime/internal/atomic"
 }
 
 // CalcSize calculates and stores the size and alignment for t.
index f8b755c946c504179fdfd1b260ca3f770483d9ac..11c1e21e1714b4fa17c4900748b28f0b90b8aa39 100644 (file)
@@ -1507,7 +1507,7 @@ func isFuncPCIntrinsic(n *ir.CallExpr) bool {
        }
        fn := n.X.(*ir.Name).Sym()
        return (fn.Name == "FuncPCABI0" || fn.Name == "FuncPCABIInternal") &&
-               (fn.Pkg.Path == "internal/abi" || fn.Pkg == types.LocalPkg && base.Ctxt.Pkgpath == "internal/abi")
+               fn.Pkg.Path == "internal/abi"
 }
 
 // isIfaceOfFunc returns whether n is an interface conversion from a direct reference of a func.