From 50479b79bcd5920bcbca9698f6a382660bb53179 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 17 Mar 2023 11:40:25 -0400 Subject: [PATCH] cmd/go: make sure linker -o for plugin doesn't include tempdir path There is already a case that when buildmode=shared passes only the basename of the -o argument to the link command to the linker (and runs in the directory of that argument) to avoid having that (temporary) directory of the file be included in the LC_ID_DYLIB load command. Extend the case to buildmode=plugin, because the same thing can happen there. This can only happen on darwin: the -o command can be embedded into Mach-O and PE binaries, but plugin isn't supported on Windows. For #58557 Change-Id: I7a4a5627148e77c6906ac4583af3d9f053d5b249 Reviewed-on: https://go-review.googlesource.com/c/go/+/477296 Run-TryBot: Michael Matloob Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Michael Matloob --- src/cmd/go/internal/work/gc.go | 2 +- .../go/testdata/script/build_plugin_reproducible.txt | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/build_plugin_reproducible.txt diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index ec01798e09..c144413f85 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -684,7 +684,7 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string) // On Windows, DLL file name is recorded in PE file // export section, so do like on OS X. dir := "." - if (cfg.Goos == "darwin" || cfg.Goos == "windows") && cfg.BuildBuildmode == "c-shared" { + if (cfg.Goos == "darwin" || cfg.Goos == "windows") && (cfg.BuildBuildmode == "c-shared" || cfg.BuildBuildmode == "plugin") { dir, out = filepath.Split(out) } diff --git a/src/cmd/go/testdata/script/build_plugin_reproducible.txt b/src/cmd/go/testdata/script/build_plugin_reproducible.txt new file mode 100644 index 0000000000..b19f0eaa0d --- /dev/null +++ b/src/cmd/go/testdata/script/build_plugin_reproducible.txt @@ -0,0 +1,11 @@ +[!buildmode:plugin] skip +[short] skip + +go build -trimpath -buildvcs=false -buildmode=plugin -o a.so main.go +go build -trimpath -buildvcs=false -buildmode=plugin -o b.so main.go +cmp a.so b.so + +-- main.go -- +package main + +func main() {} \ No newline at end of file