mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile, cmd/link: produce unlinkable object when compile without -p
CL 391014 requires the compiler to be invoked with the -p flag, to specify the package path. People are used to run "go tool compile" from the command line with the -p flag. This is mostly for simple testing, or debugging the compiler. The produced object file is almost never intended to be linked. This CL makes the compiler allow "go tool compile" without the -p flag again. It will produce an unlinkable object. If the linker sees such an object it will error out. Change-Id: I7bdb162c3cad61dadd5c456d903b92493a3df20f Reviewed-on: https://go-review.googlesource.com/c/go/+/394217 Trust: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
63ea27e9e0
commit
e853464055
5 changed files with 41 additions and 1 deletions
|
|
@ -23,6 +23,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const UnlinkablePkg = "<unlinkable>" // invalid package path, used when compiled without -p flag
|
||||
|
||||
// Entry point of writing new object file.
|
||||
func WriteObjFile(ctxt *Link, b *bio.Writer) {
|
||||
|
||||
|
|
@ -45,6 +47,9 @@ func WriteObjFile(ctxt *Link, b *bio.Writer) {
|
|||
if ctxt.Flag_shared {
|
||||
flags |= goobj.ObjFlagShared
|
||||
}
|
||||
if w.pkgpath == UnlinkablePkg {
|
||||
flags |= goobj.ObjFlagUnlinkable
|
||||
}
|
||||
if w.pkgpath == "" {
|
||||
flags |= goobj.ObjFlagNeedNameExpansion
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue