From e8534640557939755917edc3e6afc16d93b2e70b Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Mon, 21 Mar 2022 13:45:50 -0400 Subject: 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 Reviewed-by: Matthew Dempsky Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/link/internal/loader/loader.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/cmd/link/internal/loader/loader.go') diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index dfaad10143..6f2d41aa78 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -2083,6 +2083,10 @@ func (l *Loader) Preload(localSymVersion int, f *bio.Reader, lib *sym.Library, u objidx: uint32(len(l.objs)), } + if r.Unlinkable() { + log.Fatalf("link: unlinkable object (from package %s) - compiler requires -p flag", lib.Pkg) + } + // Autolib lib.Autolib = append(lib.Autolib, r.Autolib()...) -- cgit v1.3