dir := t.TempDir()
gopath := filepath.Join(dir, "GOPATH")
- env := append(os.Environ(), "GOPATH="+gopath)
+ gopathEnv := "GOPATH=" + gopath
+ env := append(os.Environ(), gopathEnv)
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module elf_test\n"), 0666); err != nil {
t.Fatal(err)
t.Fatal(err)
}
- goTool := testenv.GoToolPath(t)
cc, cflags := getCCAndCCFLAGS(t, env)
asmObj := filepath.Join(dir, "x.o")
t.Fatal(err)
}
- cmd := testenv.Command(t, goTool, "build")
+ cmd := goCmd(t, "build")
cmd.Dir = dir
- cmd.Env = env
- t.Logf("%s build", goTool)
+ cmd.Env = append(cmd.Env, gopathEnv)
+ t.Logf("%s build", testenv.GoToolPath(t))
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
dir := t.TempDir()
gopath := filepath.Join(dir, "GOPATH")
- env := append(os.Environ(), "GOPATH="+gopath)
+ gopathEnv := "GOPATH=" + gopath
+ env := append(os.Environ(), gopathEnv)
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module elf_test\n"), 0666); err != nil {
t.Fatal(err)
}
- goTool := testenv.GoToolPath(t)
cc, cflags := getCCAndCCFLAGS(t, env)
objs := []string{}
t.Fatal(err)
}
- t.Logf("%s build", goTool)
- cmd := testenv.Command(t, goTool, "build")
+ t.Logf("%s build", testenv.GoToolPath(t))
+ cmd := goCmd(t, "build")
cmd.Dir = dir
- cmd.Env = env
+ cmd.Env = append(cmd.Env, gopathEnv)
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
exe := filepath.Join(tmpdir, test.name)
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-buildid="+gobuildid+" "+test.ldflags, "-o", exe, goFile)
+ cmd := goCmd(t, "build", "-ldflags=-buildid="+gobuildid+" "+test.ldflags, "-o", exe, goFile)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
}
t.Fatal(err)
}
outFile := filepath.Join(t.TempDir(), "notes.exe")
- goTool := testenv.GoToolPath(t)
// sha1sum of "gopher"
id := "0xf4e8cd51ce8bae2996dc3b74639cdeaa1f7fee5f"
- cmd := testenv.Command(t, goTool, "build", "-o", outFile, "-ldflags",
- "-B "+id, goFile)
+ cmd := goCmd(t, "build", "-o", outFile, "-ldflags", "-B "+id, goFile)
cmd.Dir = t.TempDir()
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
binpie += linkmode
build := func(bin, mode string) error {
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", bin, "-buildmode="+mode, "-ldflags=-linkmode="+linkmode)
+ cmd := goCmd(t, "build", "-o", bin, "-buildmode="+mode, "-ldflags=-linkmode="+linkmode)
cmd.Args = append(cmd.Args, "pie.go")
cmd.Dir = dir
t.Logf("%v", cmd.Args)
t.Fatal(err)
}
outFile := filepath.Join(td, "issue51939.exe")
- goTool := testenv.GoToolPath(t)
- cmd := testenv.Command(t, goTool, "build", "-o", outFile, goFile)
+ cmd := goCmd(t, "build", "-o", outFile, goFile)
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
exe := filepath.Join(tmpdir, "x.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-R=0x100000", "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags=-R=0x100000", "-o", exe, src)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build failed: %v, output:\n%s", err, out)
}
ldflags += " -R=" + roundQuantum
}
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags="+ldflags, "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags="+ldflags, "-o", exe, src)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build failed: %v, output:\n%s", err, out)
}
ldflags += " -R=" + roundQuantum
}
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags="+ldflags, "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags="+ldflags, "-o", exe, src)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("expected build to fail with unaligned data address, but it succeeded")
}
exe := filepath.Join(tmpdir, "x.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-toolexec", os.Args[0], "-ldflags=-linkmode=internal", "-o", exe, src)
- cmd = testenv.CleanCmdEnv(cmd)
- cmd.Env = append(cmd.Env, "LINK_TEST_TOOLEXEC=1")
+ cmd := goCmd(t, "build", "-ldflags=-linkmode=internal", "-o", exe, src)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build failed: %v, output:\n%s", err, out)
}
"cmd/internal/sys"
)
+// TestMain allows this test binary to run as a -toolexec wrapper for
+// the 'go' command. If LINK_TEST_TOOLEXEC is set, TestMain runs the
+// binary as if it were cmd/link, and otherwise runs the requested
+// tool as a subprocess.
+//
+// This allows the test to verify the behavior of the current contents of the
+// cmd/link package even if the installed cmd/link binary is stale.
+func TestMain(m *testing.M) {
+ // Are we running as a toolexec wrapper? If so then run either
+ // the correct tool or this executable itself (for the linker).
+ // Running as toolexec wrapper.
+ if os.Getenv("LINK_TEST_TOOLEXEC") != "" {
+ if strings.TrimSuffix(filepath.Base(os.Args[1]), ".exe") == "link" {
+ // Running as a -toolexec linker, and the tool is cmd/link.
+ // Substitute this test binary for the linker.
+ os.Args = os.Args[1:]
+ main()
+ os.Exit(0)
+ }
+ // Running some other tool.
+ cmd := exec.Command(os.Args[1], os.Args[2:]...)
+ cmd.Stdin = os.Stdin
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ if err := cmd.Run(); err != nil {
+ os.Exit(1)
+ }
+ os.Exit(0)
+ }
+
+ // Are we being asked to run as the linker (without toolexec)?
+ // If so then kick off main.
+ if os.Getenv("LINK_TEST_EXEC_LINKER") != "" {
+ main()
+ os.Exit(0)
+ }
+
+ if testExe, err := os.Executable(); err == nil {
+ // on wasm, some phones, we expect an error from os.Executable()
+ testLinker = testExe
+ }
+
+ // Not running as a -toolexec wrapper or as a linker executable.
+ // Just run the tests.
+ os.Exit(m.Run())
+}
+
+// testLinker is the path of the test executable being run.
+// This is used by [TestScript].
+var testLinker string
+
+// goCmd returns a [*exec.Cmd] that runs the go tool using
+// the current linker sources rather than the installed linker.
+// The first element of the args parameter should be the go subcommand
+// to run, such as "build" or "run". It must be a subcommand that
+// takes the go command's build flags.
+func goCmd(t *testing.T, args ...string) *exec.Cmd {
+ goArgs := []string{args[0], "-toolexec", testenv.Executable(t)}
+ args = append(goArgs, args[1:]...)
+ cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
+ cmd = testenv.CleanCmdEnv(cmd)
+ cmd.Env = append(cmd.Env, "LINK_TEST_TOOLEXEC=1")
+ return cmd
+}
+
+// linkCmd returns a [*exec.Cmd] that runs the linker built from
+// the current sources. This is like "go tool link", but runs the
+// current linker rather than the installed one.
+func linkCmd(t *testing.T, args ...string) *exec.Cmd {
+ // Set up the arguments that TestMain looks for.
+ args = append([]string{"link"}, args...)
+ cmd := testenv.Command(t, testenv.Executable(t), args...)
+ cmd = testenv.CleanCmdEnv(cmd)
+ cmd.Env = append(cmd.Env, "LINK_TEST_TOOLEXEC=1")
+ return cmd
+}
+
var AuthorPaidByTheColumnInch struct {
fog int `text:"London. Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln’s Inn Hall. Implacable November weather. As much mud in the streets as if the waters had but newly retired from the face of the earth, and it would not be wonderful to meet a Megalosaurus, forty feet long or so, waddling like an elephantine lizard up Holborn Hill. Smoke lowering down from chimney-pots, making a soft black drizzle, with flakes of soot in it as big as full-grown snowflakes—gone into mourning, one might imagine, for the death of the sun. Dogs, undistinguishable in mire. Horses, scarcely better; splashed to their very blinkers. Foot passengers, jostling one another’s umbrellas in a general infection of ill temper, and losing their foot-hold at street-corners, where tens of thousands of other foot passengers have been slipping and sliding since the day broke (if this day ever broke), adding new deposits to the crust upon crust of mud, sticking at those points tenaciously to the pavement, and accumulating at compound interest. Fog everywhere. Fog up the river, where it flows among green aits and meadows; fog down the river, where it rolls defiled among the tiers of shipping and the waterside pollutions of a great (and dirty) city. Fog on the Essex marshes, fog on the Kentish heights. Fog creeping into the cabooses of collier-brigs; fog lying out on the yards and hovering in the rigging of great ships; fog drooping on the gunwales of barges and small boats. Fog in the eyes and throats of ancient Greenwich pensioners, wheezing by the firesides of their wards; fog in the stem and bowl of the afternoon pipe of the wrathful skipper, down in his close cabin; fog cruelly pinching the toes and fingers of his shivering little ‘prentice boy on deck. Chance people on the bridges peeping over the parapets into a nether sky of fog, with fog all round them, as if they were up in a balloon and hanging in the misty clouds. Gas looming through the fog in divers places in the streets, much as the sun may, from the spongey fields, be seen to loom by husbandman and ploughboy. Most of the shops lighted two hours before their time—as the gas seems to know, for it has a haggard and unwilling look. The raw afternoon is rawest, and the dense fog is densest, and the muddy streets are muddiest near that leaden-headed old obstruction, appropriate ornament for the threshold of a leaden-headed old corporation, Temple Bar. And hard by Temple Bar, in Lincoln’s Inn Hall, at the very heart of the fog, sits the Lord High Chancellor in his High Court of Chancery."`
t.Fatalf("failed to compile main.go: %v, output: %s\n", err, out)
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "main.o")
+ cmd = linkCmd(t, "-importcfg="+importcfgfile, "main.o")
cmd.Dir = tmpdir
out, err = cmd.CombinedOutput()
if err != nil {
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
- if len(args) >= 2 && args[1] == "link" && runtime.GOOS == "android" && runtime.GOARCH == "arm64" {
- testenv.SkipFlaky(t, 58806)
- }
t.Fatalf("'go %s' failed: %v, output: %s",
strings.Join(args, " "), err, out)
}
// Verify that the linker does not attempt
// to compile the extra section.
- runGo("tool", "link", "-importcfg="+importcfgfile, "main.a")
+ cmd := linkCmd(t, "-importcfg="+importcfgfile, "main.a")
+ cmd.Dir = tmpdir
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ if runtime.GOOS == "android" && runtime.GOARCH == "arm64" {
+ testenv.SkipFlaky(t, 58806)
+ }
+ t.Fatalf("linker failed: %v, output %s", err, out)
+ }
}
func TestUnresolved(t *testing.T) {
MOVD ·zero(SB), AX
RET
`)
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build")
+ cmd := goCmd(t, "build")
cmd.Dir = tmpdir
- cmd.Env = append(os.Environ(),
+ cmd.Env = append(cmd.Env,
"GOARCH=amd64", "GOOS=linux", "GOPATH="+filepath.Join(tmpdir, "_gopath"))
out, err := cmd.CombinedOutput()
if err == nil {
runGo("tool", "pack", "c", "x.a", "x1.o", "x2.o", "x3.o")
// Now attempt to link using the internal linker.
- cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-linkmode=internal", "x.a")
+ cmd := linkCmd(t, "-importcfg="+importcfgfile, "-linkmode=internal", "x.a")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err == nil {
tmpDir := t.TempDir()
ar := filepath.Join(tmpDir, "lib.a")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode=c-archive", "-o", ar, lib)
+ cmd := goCmd(t, "build", "-buildmode=c-archive", "-o", ar, lib)
env := []string{
"CGO_ENABLED=1",
"GOOS=ios",
"CGO_CFLAGS=", // ensure CGO_CFLAGS does not contain any flags. Issue #35459
"CGO_LDFLAGS=" + strings.Join(CGO_LDFLAGS, " "),
}
- cmd.Env = append(os.Environ(), env...)
+ cmd.Env = append(cmd.Env, env...)
t.Logf("%q %v", env, cmd)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
t.Fatal(err)
}
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-X=main.X=meow", "-o", filepath.Join(tmpdir, "main"), src)
+ cmd := goCmd(t, "build", "-ldflags=-X=main.X=meow", "-o", filepath.Join(tmpdir, "main"), src)
if out, err := cmd.CombinedOutput(); err != nil {
t.Errorf("%v: %v:\n%s", cmd.Args, err, out)
}
}
exe := filepath.Join(tmpdir, "main")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-linkmode=internal", "-o", exe, src)
- cmd.Env = append(os.Environ(),
+ cmd := goCmd(t, "build", "-ldflags=-linkmode=internal", "-o", exe, src)
+ cmd.Env = append(cmd.Env,
"CGO_ENABLED=0",
"GOOS=darwin",
"GOARCH=amd64",
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
exe := filepath.Join(tmpdir, test.name)
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags="+test.ldflags, "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags="+test.ldflags, "-o", exe, src)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v: %v:\n%s", cmd.Args, err, out)
}
t.Fatal(err)
}
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-strictdups=1")
+ cmd := goCmd(t, "build", "-ldflags=-strictdups=1")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("unexpected output:\n%s", out)
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-strictdups=2")
+ cmd = goCmd(t, "build", "-ldflags=-strictdups=2")
cmd.Dir = tmpdir
out, err = cmd.CombinedOutput()
if err == nil {
t.Fatal(err)
}
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", "falign")
+ cmd := goCmd(t, "build", "-o", "falign")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
alignTest := func(align uint64) {
exeName := "falign.exe"
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-funcalign="+strconv.FormatUint(align, 10), "-o", exeName, "falign.go")
+ cmd := goCmd(t, "build", "-ldflags=-funcalign="+strconv.FormatUint(align, 10), "-o", exeName, "falign.go")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
exe := filepath.Join(tmpdir, "hello.exe")
for _, mode := range buildmodes {
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
+ cmd := goCmd(t, "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build (%s) failed: %v\n%s", mode, err, out)
exe := filepath.Join(tmpdir, "hello.exe")
for _, mode := range buildmodes {
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
+ cmd := goCmd(t, "build", "-buildmode="+mode, "-ldflags=-debugtramp=2", "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build (%s) failed: %v\n%s", mode, err, out)
if !testenv.CanInternalLink(true) {
continue
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "build", "-buildmode="+mode, "-ldflags=-debugtramp=2 -linkmode=internal", "-o", exe, src)
+ cmd = goCmd(t, "build", "-buildmode="+mode, "-ldflags=-debugtramp=2 -linkmode=internal", "-o", exe, src)
out, err = cmd.CombinedOutput()
if err != nil {
t.Fatalf("build (%s) failed: %v\n%s", mode, err, out)
if err != nil {
t.Fatalf("compiling main.go failed: %v\n%s", err, out)
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
+ cmd = linkCmd(t, "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
t.Log(cmd)
out, err = cmd.CombinedOutput()
if err != nil {
if err != nil {
t.Fatalf("compiling a.go failed: %v\n%s", err, out)
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
+ cmd = linkCmd(t, "-importcfg="+importcfgWithAFile, "-L", tmpdir, "-o", exe, mObj)
t.Log(cmd)
out, err = cmd.CombinedOutput()
if err == nil {
pkgdir := filepath.Join("testdata", "pe-binutils")
exe := filepath.Join(tmpdir, "a.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe)
+ cmd := goCmd(t, "build", "-o", exe)
cmd.Dir = pkgdir
// cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64") // uncomment if debugging in a cross-compiling environment
out, err := cmd.CombinedOutput()
pkgdir := filepath.Join("testdata", "pe-llvm")
exe := filepath.Join(tmpdir, "a.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe)
+ cmd := goCmd(t, "build", "-o", exe)
cmd.Dir = pkgdir
// cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64") // uncomment if debugging in a cross-compiling environment
out, err := cmd.CombinedOutput()
t.Parallel()
src := filepath.Join("testdata", "testHashedSyms", "p.go")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
+ cmd := goCmd(t, "run", src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("command %s failed: %v\n%s", cmd, err, out)
t.Parallel()
src := filepath.Join("testdata", "testRO", "x.go")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
+ cmd := goCmd(t, "run", src)
out, err := cmd.CombinedOutput()
if err == nil {
t.Errorf("running test program did not fail. output:\n%s", out)
t.Fatalf("failed to write source file: %v", err)
}
exe := filepath.Join(tmpdir, "x.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
+ cmd := goCmd(t, "build", "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed: %v\n%s", err, out)
t.Fatalf("failed to write source file: %v", err)
}
exe := filepath.Join(tmpdir, "main.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-gcflags=-race", "-o", exe, src)
+ cmd := goCmd(t, "build", "-gcflags=-race", "-o", exe, src)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("build unexpectedly succeeded")
if err != nil {
t.Fatalf("failed to write source file: %v", err)
}
- cmd := testenv.Command(t, testenv.GoToolPath(t), "run", src)
+ cmd := goCmd(t, "run", src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("build failed: %v. output:\n%s", err, out)
}
if testenv.HasCGO() { // currently all targets that support cgo can external link
- cmd = testenv.Command(t, testenv.GoToolPath(t), "run", "-ldflags=-linkmode=external", src)
+ cmd = goCmd(t, "run", "-ldflags=-linkmode=external", src)
out, err = cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed: %v. output:\n%s", err, out)
if err != nil {
t.Fatalf("compile x.go failed: %v. output:\n%s", err, out)
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-o", exe, xObj)
+ cmd = linkCmd(t, "-importcfg="+importcfgfile, "-o", exe, xObj)
out, err = cmd.CombinedOutput()
if err == nil {
t.Fatalf("link did not fail")
t.Fatalf("compile failed: %v. output:\n%s", err, out)
}
- cmd = testenv.Command(t, testenv.GoToolPath(t), "tool", "link", "-importcfg="+importcfgfile, "-o", exe, xObj)
+ cmd = linkCmd(t, "-importcfg="+importcfgfile, "-o", exe, xObj)
out, err = cmd.CombinedOutput()
if err != nil {
t.Errorf("link failed: %v. output:\n%s", err, out)
ldflags := "-ldflags=-v -linkmode=external -tmpdir=" + linktmp
var out0 []byte
for i := 0; i < 5; i++ {
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", ldflags, "-o", exe, src)
+ cmd := goCmd(t, "build", ldflags, "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed: %v, output:\n%s", err, out)
t.Fatal(err)
}
+ // We don't use goCmd here, as -toolexec doesn't use response files.
+ // This test is more for the go command than the linker anyhow.
+
cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", "output", "x.go")
cmd.Dir = tmpdir
src := filepath.Join("testdata", "dynimportvar", "main.go")
for _, mode := range []string{"internal", "external"} {
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-linkmode="+mode, "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags=-linkmode="+mode, "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build (linkmode=%s) failed: %v\n%s", mode, err, out)
syms := []string{"main.main", "main.X", "main.Y"}
for _, mode := range modes {
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-s -linkmode="+mode, "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags=-s -linkmode="+mode, "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build (linkmode=%s) failed: %v\n%s", mode, err, out)
var syms [2]string
for i, seed := range []string{"123", "456"} {
exe := filepath.Join(tmpdir, "hello"+seed+".exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-ldflags=-randlayout="+seed, "-o", exe, src)
+ cmd := goCmd(t, "build", "-ldflags=-randlayout="+seed, "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("seed=%v: build failed: %v\n%s", seed, err, out)
t.Parallel()
src := "./testdata/linkname/" + test.src
exe := filepath.Join(tmpdir, test.src+".exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
+ cmd := goCmd(t, "build", "-o", exe, src)
out, err := cmd.CombinedOutput()
if test.ok && err != nil {
t.Errorf("build failed unexpectedly: %v:\n%s", err, out)
src := filepath.Join("testdata", "linkname", "sched.go")
exe := filepath.Join(tmpdir, "sched.exe")
- cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
+ cmd := goCmd(t, "build", "-o", exe, src)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed unexpectedly: %v:\n%s", err, out)