Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cmd/loopvec-toolexec/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,17 @@ func tryRewrite(tool string, args []string) (out []string, ok bool) {
return nil, false
}

// A package and its test variant are compiled concurrently under the same
// import path, so every compile gets its own directory.
dir, err := os.MkdirTemp(b.dir, strings.NewReplacer("/", "_", ".", "_").Replace(c.pkg)+"-")
if err != nil {
// The rewritten files go in the compile's own object directory, where the
// go command writes the importcfg: a package and its test variant are
// compiled concurrently under the same import path, so each needs its own
// place, and the go command trims that directory from file names with
// -trimpath. The file names end up in the export data, so the archive must
// not depend on where the directory is: the go command can compile a
// package twice in one build (with PGO, once for each test binary) and use
// one archive to compile its importers and the other to link them, and the
// linker rejects two archives that differ.
dir := filepath.Join(filepath.Dir(args[c.importcfg]), "loopvec")
if err := os.MkdirAll(dir, 0o755); err != nil {
return nil, false
}
newArgs := append([]string(nil), args...)
Expand Down
28 changes: 28 additions & 0 deletions testdata/toolexec_reproducible.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The wrapper compiles rewritten files from a directory of its own, and their
# names end up in the export data. Building the same package twice must still
# give the same archive: the go command can compile a package twice in one build
# (with PGO, once for each test binary that needs it), compile its importers
# against one copy and link the other, and the linker rejects two copies that
# differ.

env GOEXPERIMENT=simd
env LOOPVEC_TOOLEXEC_LOG=$WORK/log
env GOCACHE=$WORK/gocache1
exec go build -buildmode=archive -toolexec=$LOOPVEC_TOOLEXEC -o a1.a .
env GOCACHE=$WORK/gocache2
exec go build -buildmode=archive -toolexec=$LOOPVEC_TOOLEXEC -o a2.a .
grep -count=2 '^rewrote 1 loop\(s\) in example\.com/lib$' log
cmp a1.a a2.a

-- go.mod --
module example.com/lib

go 1.27.1
-- lib.go --
package lib

func Add(dst, a, b []float32) {
for i := range dst {
dst[i] = a[i] + b[i]
}
}
Loading