From bf21c67b1e2d5a3268749c25024df9f401b35b65 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 31 Oct 2017 15:14:49 -0400 Subject: [PATCH] cmd/go: trim objdir, not just workdir, from object files Otherwise the new numbered directories like b028/ appear in the objects, and they can change from run to run. Fixes #22514. Change-Id: I8d0cf65f3622e48b2547d5757febe0ee1301e2ed Reviewed-on: https://go-review.googlesource.com/74791 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor Reviewed-by: David Crawshaw --- src/cmd/go/internal/work/gc.go | 11 +++++++++-- src/runtime/race/output_test.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index e76f9ba798..651d20c21c 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -106,7 +106,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, a } } - args := []interface{}{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", b.WorkDir, gcflags, gcargs, "-D", p.Internal.LocalPrefix} + args := []interface{}{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", trimDir(a.Objdir), gcflags, gcargs, "-D", p.Internal.LocalPrefix} if importcfg != nil { if err := b.writeFile(objdir+"importcfg", importcfg); err != nil { return "", nil, err @@ -204,11 +204,18 @@ CheckFlags: return c } +func trimDir(dir string) string { + if len(dir) > 1 && dir[len(dir)-1] == filepath.Separator { + dir = dir[:len(dir)-1] + } + return dir +} + func (gcToolchain) asm(b *Builder, a *Action, sfiles []string) ([]string, error) { p := a.Package // Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files. inc := filepath.Join(cfg.GOROOT, "pkg", "include") - args := []interface{}{cfg.BuildToolexec, base.Tool("asm"), "-trimpath", b.WorkDir, "-I", a.Objdir, "-I", inc, "-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch, buildAsmflags} + args := []interface{}{cfg.BuildToolexec, base.Tool("asm"), "-trimpath", trimDir(a.Objdir), "-I", a.Objdir, "-I", inc, "-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch, buildAsmflags} if p.ImportPath == "runtime" && cfg.Goarch == "386" { for _, arg := range buildAsmflags { if arg == "-dynlink" { diff --git a/src/runtime/race/output_test.go b/src/runtime/race/output_test.go index f5b6fea43e..ee6bf6b035 100644 --- a/src/runtime/race/output_test.go +++ b/src/runtime/race/output_test.go @@ -263,7 +263,7 @@ Previous write at 0x[0-9,a-f]+ by goroutine [0-9]: main\.goCallback\(\) .*/main\.go:27 \+0x[0-9,a-f]+ main._cgoexpwrap_[0-9a-z]+_goCallback\(\) - .*/_cgo_gotypes\.go:[0-9]+ \+0x[0-9,a-f]+ + .*_cgo_gotypes\.go:[0-9]+ \+0x[0-9,a-f]+ Goroutine [0-9] \(running\) created at: runtime\.newextram\(\) -- 2.48.1