]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: require -p flag
authorCherry Mui <cherryyz@google.com>
Thu, 5 May 2022 21:45:27 +0000 (17:45 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 11 May 2022 22:59:46 +0000 (22:59 +0000)
CL 391014 requires the compiler to be invoked with the -p flag, to
specify the package path. Later, CL 394217 makes the compiler to
produce an unlinkable object file, so "go tool compile x.go" can
still be used on the command line. This CL does the same for the
assembler, requiring -p, otherwise generating an unlinkable object.

No special case for the main package, as the main package cannot
be only assembly code, and there is no way to tell if it is the
main package from an assembly file.

Now we guarantee that we always have an expanded package path in
the object file. A later CL will delete the name expansion code
in the linker.

Change-Id: I8c10661aaea2ff794614924ead958d80e7e2487d
Reviewed-on: https://go-review.googlesource.com/c/go/+/404298
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/asm/internal/flags/flags.go
src/cmd/internal/goobj/objfile.go
src/cmd/internal/obj/objfile.go
src/cmd/link/link_test.go
test/run.go

index 273d422370907057814438d0c3b84dd802d5bc66..1c8b908860203b658e45749c27acd2615cf6831f 100644 (file)
@@ -6,6 +6,7 @@
 package flags
 
 import (
+       "cmd/internal/obj"
        "cmd/internal/objabi"
        "flag"
        "fmt"
@@ -23,7 +24,7 @@ var (
        Linkshared       = flag.Bool("linkshared", false, "generate code that will be linked against Go shared libraries")
        AllErrors        = flag.Bool("e", false, "no limit on number of errors reported")
        SymABIs          = flag.Bool("gensymabis", false, "write symbol ABI information to output file, don't assemble")
-       Importpath       = flag.String("p", "", "set expected package import to path")
+       Importpath       = flag.String("p", obj.UnlinkablePkg, "set expected package import to path")
        Spectre          = flag.String("spectre", "", "enable spectre mitigations in `list` (all, ret)")
        CompilingRuntime = flag.Bool("compiling-runtime", false, "source to be compiled is part of the Go runtime")
 )
index 665fa41475dd377ea4b45c7c5a0a0471d9830f8a..34c5bb97f8b1ca4fa64df68971e8687e4e6f70b4 100644 (file)
@@ -281,10 +281,10 @@ const SymSize = stringRefSize + 2 + 1 + 1 + 1 + 4 + 4
 const SymABIstatic = ^uint16(0)
 
 const (
-       ObjFlagShared            = 1 << iota // this object is built with -shared
-       ObjFlagNeedNameExpansion             // the linker needs to expand `"".` to package path in symbol names
-       ObjFlagFromAssembly                  // object is from asm src, not go
-       ObjFlagUnlinkable                    // unlinkable package (linker will emit an error)
+       ObjFlagShared       = 1 << iota // this object is built with -shared
+       _                               // was ObjFlagNeedNameExpansion
+       ObjFlagFromAssembly             // object is from asm src, not go
+       ObjFlagUnlinkable               // unlinkable package (linker will emit an error)
 )
 
 // Sym.Flag
@@ -873,6 +873,6 @@ func (r *Reader) Flags() uint32 {
 }
 
 func (r *Reader) Shared() bool            { return r.Flags()&ObjFlagShared != 0 }
-func (r *Reader) NeedNameExpansion() bool { return r.Flags()&ObjFlagNeedNameExpansion != 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 }
index d31afda703b7a07f85c1ec97aa49ff9f176e0952..89339b0147c147e70a3e1590c80cd5395046c564 100644 (file)
@@ -51,7 +51,7 @@ func WriteObjFile(ctxt *Link, b *bio.Writer) {
                flags |= goobj.ObjFlagUnlinkable
        }
        if w.pkgpath == "" {
-               flags |= goobj.ObjFlagNeedNameExpansion
+               log.Fatal("empty package path")
        }
        if ctxt.IsAsm {
                flags |= goobj.ObjFlagFromAssembly
index ac68008d8ddc6696512d3f9c224d33916fc0bfdc..d86f81fac8b4460a8cb53c406c10628605eb26dd 100644 (file)
@@ -235,9 +235,9 @@ void foo() {
        cflags := strings.Fields(runGo("env", "GOGCCFLAGS"))
 
        // Compile, assemble and pack the Go and C code.
-       runGo("tool", "asm", "-gensymabis", "-o", "symabis", "x.s")
+       runGo("tool", "asm", "-p=main", "-gensymabis", "-o", "symabis", "x.s")
        runGo("tool", "compile", "-symabis", "symabis", "-p=main", "-o", "x1.o", "main.go")
-       runGo("tool", "asm", "-o", "x2.o", "x.s")
+       runGo("tool", "asm", "-p=main", "-o", "x2.o", "x.s")
        run(cc, append(cflags, "-c", "-o", "x3.o", "x.c")...)
        runGo("tool", "pack", "c", "x.a", "x1.o", "x2.o", "x3.o")
 
index 27e16f689235ffb01049893f1314a68a32c80ffc..00f869bc2baaf3485befab0e338687d6c9e0227a 100644 (file)
@@ -1024,7 +1024,7 @@ func (t *test) run() {
                                t.err = fmt.Errorf("write empty go_asm.h: %s", err)
                                return
                        }
-                       cmd := []string{goTool(), "tool", "asm", "-gensymabis", "-o", "symabis"}
+                       cmd := []string{goTool(), "tool", "asm", "-p=main", "-gensymabis", "-o", "symabis"}
                        cmd = append(cmd, asms...)
                        _, err = runcmd(cmd...)
                        if err != nil {
@@ -1045,7 +1045,7 @@ func (t *test) run() {
                }
                objs = append(objs, "go.o")
                if len(asms) > 0 {
-                       cmd = []string{goTool(), "tool", "asm", "-e", "-I", ".", "-o", "asm.o"}
+                       cmd = []string{goTool(), "tool", "asm", "-p=main", "-e", "-I", ".", "-o", "asm.o"}
                        cmd = append(cmd, asms...)
                        _, err = runcmd(cmd...)
                        if err != nil {