mirror of
https://github.com/golang/go.git
synced 2024-09-22 02:48:50 +00:00
cmd/asm: require -p flag
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>
This commit is contained in:
parent
b89a194889
commit
6e03de7b83
@ -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")
|
||||
)
|
||||
|
@ -282,7 +282,7 @@ 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
|
||||
_ // was ObjFlagNeedNameExpansion
|
||||
ObjFlagFromAssembly // object is from asm src, not go
|
||||
ObjFlagUnlinkable // unlinkable package (linker will emit an error)
|
||||
)
|
||||
@ -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 }
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user