Skip to content

Commit

Permalink
cmd/compile: require -p flag
Browse files Browse the repository at this point in the history
The -p flag specifies the import path of the package being compiled.
This CL makes it required when invoking the compiler and
adjusts tests that invoke the compiler directly to conform to this
new requirement. The go command already passes the flag, so it
is unmodified in this CL. It is expected that any other Go build systems
also already pass -p, or else they will need to arrange to do so before
updating to Go 1.19. Of particular note, Bazel already does for rules
with an importpath= attribute, which includes all Gazelle-generated rules.

There is more cleanup possible now in cmd/compile, cmd/link,
and other consumers of Go object files, but that is left to future CLs.

Additional historical background follows but can be ignored.

Long ago, before the go command, or modules, or any kind of
versioning, symbols in Go archive files were named using just the
package name, so that for example func F in math/rand and func F in
crypto/rand would both be the object file symbol 'rand.F'. This led to
collisions even in small source trees, which made certain packages
unusable in the presence of other packages and generally was a problem
for Go's goal of scaling to very large source trees.

Fixing this problem required changing from package names to import
paths in symbol names, which was mostly straightforward. One wrinkle,
though, is that the compiler did not know the import path of the
package being compiled; it only knew the package name. At the time,
there was no go command, just Makefiles that people had invoking 6g
(now “go tool compile”) and then copying the resulting object file to
an importable location. That is, everyone had a custom build setup for
Go, because there was no standard one. So it was not particularly
attractive to change how the compiler was invoked, since that would
break approximately every Go user at the time. Instead, we arranged
for the compiler to emit, and other tools reading object files to
recognize, a special import path (the empty string, it turned out)
denoting “the import path of this object file”. This worked well
enough at the time and maintained complete command-line compatibility
with existing Go usage.

The changes implementing this transition can be found by searching
the Git history for “package global name space”, which is what they
eliminated. In particular, CL 190076 (a6736fa), CL 186263 (758f2bc),
CL 193080 (1cecac8), CL 194053 (1912632), and CL 194071 (531e6b7)
did the bulk of this transformation in January 2010.

Later, in September 2011, we added the -p flag to the compiler for
diagnostic purposes. The problem was that it was easy to create import
cycles, especially in tests, and these could not be diagnosed until
link time. You'd really want the compiler to diagnose these, for
example if the compilation of package sort noticed it was importing a
package that itself imported "sort". But the compilation of package
sort didn't know its own import path, and so it could not tell whether
it had found itself as a transitive dependency. Adding the -p flag
solved this problem, and its use was optional, since the linker would
still diagnose the import cycle in builds that had not updated to
start passing -p. This was CL 4972057 (1e480cd).

There was still no go command at this point, but when we introduced
the go command we made it pass -p, which it has for many years at this
point.

Over time, parts of the compiler began to depend on the presence of
the -p flag for various reasonable purposes. For example:

In CL 6497074 (041fc8b; Oct 2012), the race detector used -p to
detect packages that should not have race annotations, such as
runtime/race and sync/atomic.

In CL 13367052 (7276c02; Sep 2013), a bug fix used -p to detect the
compilation of package reflect.

In CL 30539 (8aadcc5; Oct 2016), the compiler started using -p to
identify package math, to be able to intrinsify calls to Sqrt inside
that package.

In CL 61019 (9daee93; Sep 2017), CL 71430 (2c1d2e0; Oct 2017), and
later related CLs, the compiler started using the -p value when
creating various DWARF debugging information.

In CL 174657 (cc5eaf9; May 2019), the compiler started writing
symbols without the magic empty string whenever -p was used, to reduce
the amount of work required in the linker.

In CL 179861 (dde7c77; Jun 2019), the compiler made the second
argument to //go:linkname optional when -p is used, because in that
case the compiler can derive an appropriate default.

There are more examples. Today it is impossible to compile the Go
standard library without using -p, and DWARF debug information is
incomplete without using -p.

All known Go build systems pass -p. In particular, the go command
does, which is what nearly all Go developers invoke to build Go code.
And Bazel does, for go_library rules that set the importpath
attribute, which is all rules generated by Gazelle.

Gccgo has an equivalent of -p and has required its use in order to
disambiguate packages with the same name but different import paths
since 2010.

On top of all this, various parts of code generation for generics
are made more complicated by needing to cope with the case where -p
is not specified, even though it's essentially always specified.

In summary, the current state is:

 - Use of the -p flag with cmd/compile is required for building
   the standard library, and for complete DWARF information,
   and to enable certain linker speedups.

 - The go command and Bazel, which we expect account for just
   about 100% of Go builds, both invoke cmd/compile with -p.

 - The code in cmd/compile to support builds without -p is
   complex and has become more complex with generics, but it is
   almost always dead code and therefore not worth maintaining.

 - Gccgo already requires its equivalent of -p in any build
   where two packages have the same name.

All this supports the change in this CL, which makes -p required
and adjusts tests that invoke cmd/compile to add -p appropriately.

Future CLs will be able to remove all the code dealing with the
possibility of -p not having been specified.

Change-Id: I6b95b9d4cffe59c7bac82eb273ef6c4a67bb0e43
Reviewed-on: https://go-review.googlesource.com/c/go/+/391014
Trust: Russ Cox <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
  • Loading branch information
rsc committed Mar 9, 2022
1 parent b8248fa commit a987aaf
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 114 deletions.
4 changes: 4 additions & 0 deletions src/cmd/compile/internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func ParseFlags() {
Exit(2)
}

if *Flag.LowerP == "" {
log.Fatalf("-p is required")
}

if Flag.LowerO == "" {
p := flag.Arg(0)
if i := strings.LastIndex(p, "/"); i >= 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/importer/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func compile(t *testing.T, dirname, filename, outdirname string) string {
}
basename := filepath.Base(filename)
outname := filepath.Join(outdirname, basename[:len(basename)-2]+"o")
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", outname, filename)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-o", outname, filename)
cmd.Dir = dirname
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/logopt/logopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func s15a8(x *[15]int64) [15]int64 {
}

func testLogOpt(t *testing.T, flag, src, outfile string) (string, error) {
run := []string{testenv.GoToolPath(t), "tool", "compile", flag, "-o", outfile, src}
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", flag, "-o", outfile, src}
t.Log(run)
cmd := exec.Command(run[0], run[1:]...)
out, err := cmd.CombinedOutput()
Expand All @@ -236,7 +236,7 @@ func testLogOpt(t *testing.T, flag, src, outfile string) (string, error) {

func testLogOptDir(t *testing.T, dir, flag, src, outfile string) (string, error) {
// Notice the specified import path "x"
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p", "x", flag, "-o", outfile, src}
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=x", flag, "-o", outfile, src}
t.Log(run)
cmd := exec.Command(run[0], run[1:]...)
cmd.Dir = dir
Expand All @@ -247,7 +247,7 @@ func testLogOptDir(t *testing.T, dir, flag, src, outfile string) (string, error)

func testCopy(t *testing.T, dir, goarch, goos, src, outfile string) (string, error) {
// Notice the specified import path "x"
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p", "x", "-json=0,file://log/opt", "-o", outfile, src}
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=x", "-json=0,file://log/opt", "-o", outfile, src}
t.Log(run)
cmd := exec.Command(run[0], run[1:]...)
cmd.Dir = dir
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/test/fixedbugs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestIssue16214(t *testing.T) {
t.Fatalf("could not write file: %v", err)
}

cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "-S", "-o", filepath.Join(dir, "out.o"), src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("go tool compile: %v\n%s", err, out)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/test/lang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestInvalidLang(t *testing.T) {
}

func testLang(t *testing.T, lang, src, outfile string) error {
run := []string{testenv.GoToolPath(t), "tool", "compile", "-lang", lang, "-o", outfile, src}
run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", "-lang", lang, "-o", outfile, src}
t.Log(run)
out, err := exec.Command(run[0], run[1:]...).CombinedOutput()
t.Logf("%s", out)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/test/reproduciblebuilds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestReproducibleBuilds(t *testing.T) {
for i := 0; i < iters; i++ {
// Note: use -c 2 to expose any nondeterminism which is the result
// of the runtime scheduler.
out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-c", "2", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput()
out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-c", "2", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput()
if err != nil {
t.Fatalf("failed to compile: %v\n%s", err, out)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestIssue38068(t *testing.T) {
s := &scenarios[i]
s.libpath = filepath.Join(tmpdir, s.tag+".a")
// Note: use of "-p" required in order for DWARF to be generated.
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-trimpath", "-p=issue38068", "-buildid=", s.args, "-o", s.libpath, src)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=issue38068", "-buildid=", s.args, "-o", s.libpath, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/internal/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func buildGoobj() error {
go1src := filepath.Join("testdata", "go1.go")
go2src := filepath.Join("testdata", "go2.go")

out, err := exec.Command(gotool, "tool", "compile", "-o", go1obj, go1src).CombinedOutput()
out, err := exec.Command(gotool, "tool", "compile", "-p=p", "-o", go1obj, go1src).CombinedOutput()
if err != nil {
return fmt.Errorf("go tool compile -o %s %s: %v\n%s", go1obj, go1src, err, out)
}
out, err = exec.Command(gotool, "tool", "compile", "-o", go2obj, go2src).CombinedOutput()
out, err = exec.Command(gotool, "tool", "compile", "-p=p", "-o", go2obj, go2src).CombinedOutput()
if err != nil {
return fmt.Errorf("go tool compile -o %s %s: %v\n%s", go2obj, go2src, err, out)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/internal/obj/objfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestSymbolTooLarge(t *testing.T) { // Issue 42054
t.Fatalf("failed to write source file: %v\n", err)
}
obj := filepath.Join(tmpdir, "p.o")
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", obj, src)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-o", obj, src)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("did not fail\noutput: %s", out)
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/link/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {}
t.Fatalf("failed to write main.go: %v\n", err)
}

cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "main.go")
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "main.go")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestIssue28429(t *testing.T) {

// Compile a main package.
write("main.go", "package main; func main() {}")
runGo("tool", "compile", "-p", "main", "main.go")
runGo("tool", "compile", "-p=main", "main.go")
runGo("tool", "pack", "c", "main.a", "main.o")

// Add an extra section with a short, non-.o name.
Expand Down Expand Up @@ -236,7 +236,7 @@ void foo() {

// Compile, assemble and pack the Go and C code.
runGo("tool", "asm", "-gensymabis", "-o", "symabis", "x.s")
runGo("tool", "compile", "-symabis", "symabis", "-p", "main", "-o", "x1.o", "main.go")
runGo("tool", "compile", "-symabis", "symabis", "-p=main", "-o", "x1.o", "main.go")
runGo("tool", "asm", "-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")
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestIssue34788Android386TLSSequence(t *testing.T) {
}

obj := filepath.Join(tmpdir, "blah.o")
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", obj, src)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=blah", "-o", obj, src)
cmd.Env = append(os.Environ(), "GOARCH=386", "GOOS=android")
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("failed to compile blah.go: %v, output: %s\n", err, out)
Expand Down Expand Up @@ -765,13 +765,13 @@ func TestIndexMismatch(t *testing.T) {
exe := filepath.Join(tmpdir, "main.exe")

// Build a program with main package importing package a.
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", aObj, aSrc)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=a", "-o", aObj, aSrc)
t.Log(cmd)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("compiling a.go failed: %v\n%s", err, out)
}
cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-I", tmpdir, "-o", mObj, mSrc)
cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=main", "-I", tmpdir, "-o", mObj, mSrc)
t.Log(cmd)
out, err = cmd.CombinedOutput()
if err != nil {
Expand All @@ -786,7 +786,7 @@ func TestIndexMismatch(t *testing.T) {

// Now, overwrite a.o with the object of b.go. This should
// result in an index mismatch.
cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", aObj, bSrc)
cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=a", "-o", aObj, bSrc)
t.Log(cmd)
out, err = cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/objdump/objdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestDisasmGoobj(t *testing.T) {
mustHaveDisasm(t)

hello := filepath.Join(tmp, "hello.o")
args := []string{"tool", "compile", "-o", hello}
args := []string{"tool", "compile", "-p=main", "-o", hello}
args = append(args, "testdata/fmthello.go")
out, err := exec.Command(testenv.GoToolPath(t), args...).CombinedOutput()
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/pack/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestHello(t *testing.T) {

goBin := testenv.GoToolPath(t)
run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "hello.go")
run(goBin, "tool", "compile", "-p=main", "hello.go")
run("./pack", "grc", "hello.a", "hello.o")
run(goBin, "tool", "link", "-o", "a.out", "hello.a")
out := run("./a.out")
Expand Down Expand Up @@ -246,9 +246,9 @@ func TestLargeDefs(t *testing.T) {

goBin := testenv.GoToolPath(t)
run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "large.go")
run(goBin, "tool", "compile", "-p=large", "large.go")
run("./pack", "grc", "large.a", "large.o")
run(goBin, "tool", "compile", "-I", ".", "main.go")
run(goBin, "tool", "compile", "-p=main", "-I", ".", "main.go")
run(goBin, "tool", "link", "-L", ".", "-o", "a.out", "main.o")
out := run("./a.out")
if out != "ok\n" {
Expand Down Expand Up @@ -281,9 +281,9 @@ func TestIssue21703(t *testing.T) {

goBin := testenv.GoToolPath(t)
run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "a.go")
run(goBin, "tool", "compile", "-p=a", "a.go")
run("./pack", "c", "a.a", "a.o")
run(goBin, "tool", "compile", "-I", ".", "b.go")
run(goBin, "tool", "compile", "-p=b", "-I", ".", "b.go")
}

// Test the "c" command can "see through" the archive generated by the compiler.
Expand All @@ -305,7 +305,7 @@ func TestCreateWithCompilerObj(t *testing.T) {

goBin := testenv.GoToolPath(t)
run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "-pack", "-o", "p.a", "p.go")
run(goBin, "tool", "compile", "-pack", "-p=p", "-o", "p.a", "p.go")
run("./pack", "c", "packed.a", "p.a")
fi, err := os.Stat(filepath.Join(dir, "p.a"))
if err != nil {
Expand All @@ -323,7 +323,7 @@ func TestCreateWithCompilerObj(t *testing.T) {
}

// Test -linkobj flag as well.
run(goBin, "tool", "compile", "-linkobj", "p2.a", "-o", "p.x", "p.go")
run(goBin, "tool", "compile", "-p=p", "-linkobj", "p2.a", "-o", "p.x", "p.go")
run("./pack", "c", "packed2.a", "p2.a")
fi, err = os.Stat(filepath.Join(dir, "p2.a"))
if err != nil {
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestRWithNonexistentFile(t *testing.T) {

goBin := testenv.GoToolPath(t)
run(goBin, "build", "cmd/pack") // writes pack binary to dir
run(goBin, "tool", "compile", "-o", "p.o", "p.go")
run(goBin, "tool", "compile", "-p=p", "-o", "p.o", "p.go")
run("./pack", "r", "p.a", "p.o") // should succeed
}

Expand Down
2 changes: 1 addition & 1 deletion src/go/internal/gcimporter/gcimporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func compile(t *testing.T, dirname, filename, outdirname string) string {
}
basename := filepath.Base(filename)
outname := filepath.Join(outdirname, basename[:len(basename)-2]+"o")
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", outname, filename)
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-o", outname, filename)
cmd.Dir = dirname
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestFuncPCCompileError(t *testing.T) {
}

// compile go code.
cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-symabis", symabi, "-o", obj, goSrc)
cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-p=p", "-symabis", symabi, "-o", obj, goSrc)
out, err = cmd.CombinedOutput()
if err == nil {
t.Fatalf("go tool compile did not fail")
Expand Down
2 changes: 1 addition & 1 deletion test/const7.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func testProg(dir, name string, length int, ok bool) {
log.Fatal(err)
}

cmd := exec.Command("go", "tool", "compile", filename)
cmd := exec.Command("go", "tool", "compile", "-p=p", filename)
cmd.Dir = dir
output, err := cmd.CombinedOutput()

Expand Down
4 changes: 2 additions & 2 deletions test/fixedbugs/bug302.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func main() {
}
defer os.RemoveAll(tmpDir)

run("go", "tool", "compile", filepath.Join(fb, "bug302.dir", "p.go"))
run("go", "tool", "compile", "-p=p", filepath.Join(fb, "bug302.dir", "p.go"))
run("go", "tool", "pack", "grc", "pp.a", "p.o")
run("go", "tool", "compile", "-I", ".", filepath.Join(fb, "bug302.dir", "main.go"))
run("go", "tool", "compile", "-p=main", "-I", ".", filepath.Join(fb, "bug302.dir", "main.go"))
}

func run(cmd string, args ...string) {
Expand Down
6 changes: 3 additions & 3 deletions test/fixedbugs/bug369.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func main() {
return filepath.Join(tmpDir, name)
}

run("go", "tool", "compile", "-N", "-o", tmp("slow.o"), "pkg.go")
run("go", "tool", "compile", "-o", tmp("fast.o"), "pkg.go")
run("go", "tool", "compile", "-D", tmpDir, "-o", tmp("main.o"), "main.go")
run("go", "tool", "compile", "-p=pkg", "-N", "-o", tmp("slow.o"), "pkg.go")
run("go", "tool", "compile", "-p=pkg", "-o", tmp("fast.o"), "pkg.go")
run("go", "tool", "compile", "-p=main", "-D", tmpDir, "-o", tmp("main.o"), "main.go")
run("go", "tool", "link", "-o", tmp("a.exe"), tmp("main.o"))
run(tmp("a.exe"))
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue11771.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func x() {
log.Fatal(err)
}

cmd := exec.Command("go", "tool", "compile", "x.go")
cmd := exec.Command("go", "tool", "compile", "-p=p", "x.go")
cmd.Dir = dir
output, err := cmd.CombinedOutput()
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue21317.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
defer os.RemoveAll(f.Name())

// compile and test output
cmd := exec.Command("go", "tool", "compile", f.Name())
cmd := exec.Command("go", "tool", "compile", "-p=main", f.Name())
out, err := cmd.CombinedOutput()
if err == nil {
log.Fatalf("expected cmd/compile to fail")
Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue22660.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
log.Fatal(err)
}

out, err := exec.Command("go", "tool", "compile", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput()
out, err := exec.Command("go", "tool", "compile", "-p=p", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput()
if err == nil {
log.Fatalf("expected compiling %s to fail", f.Name())
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue22662b.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
log.Fatal(err)
}

out, err := exec.Command("go", "tool", "compile", f.Name()).CombinedOutput()
out, err := exec.Command("go", "tool", "compile", "-p=p", f.Name()).CombinedOutput()
if err == nil {
log.Fatalf("expected compiling\n---\n%s\n---\nto fail", test.src)
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixedbugs/issue26411.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bar :
log.Printf("#%d: failed to create file %s", i, filename)
continue
}
output, _ := exec.Command("go", "tool", "compile", filename).CombinedOutput()
output, _ := exec.Command("go", "tool", "compile", "-p=p", filename).CombinedOutput()

// remove each matching error from the output
for _, err := range test.errors {
Expand Down
3 changes: 2 additions & 1 deletion test/fixedbugs/issue30908.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// rundir -P -ldflags -strictdups=2 -w=0
// rundir -ldflags -strictdups=2 -w=0

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !nacl && !js
// +build !nacl,!js

package ignored
2 changes: 1 addition & 1 deletion test/fixedbugs/issue9355.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
}
f.Close()

out := run("go", "tool", "compile", "-o", f.Name(), "-S", "a.go")
out := run("go", "tool", "compile", "-p=p", "-o", f.Name(), "-S", "a.go")
os.Remove(f.Name())

// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
Expand Down
5 changes: 3 additions & 2 deletions test/interface/embed1.dir/embed0.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
package p

type T int

func (t T) m() {}

type I interface { m() }
type J interface { I }
type I interface{ m() }
type J interface{ I }

func main() {
var i I
Expand Down
8 changes: 4 additions & 4 deletions test/linkmain_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ func main() {
}

// helloworld.go is package main
run("go tool compile -o", tmp("linkmain.o"), "helloworld.go")
run("go tool compile -pack -o", tmp("linkmain.a"), "helloworld.go")
run("go tool compile -p=main -o", tmp("linkmain.o"), "helloworld.go")
run("go tool compile -p=main -pack -o", tmp("linkmain.a"), "helloworld.go")
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.o"))
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.a"))

// linkmain.go is not
run("go tool compile -o", tmp("linkmain1.o"), "linkmain.go")
run("go tool compile -pack -o", tmp("linkmain1.a"), "linkmain.go")
run("go tool compile -p=notmain -o", tmp("linkmain1.o"), "linkmain.go")
run("go tool compile -p=notmain -pack -o", tmp("linkmain1.a"), "linkmain.go")
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.o"))
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.a"))
cleanup()
Expand Down
Loading

0 comments on commit a987aaf

Please sign in to comment.