Skip to content

Commit

Permalink
cmd/go: make sure the linker for shared doesn't include tempdir path
Browse files Browse the repository at this point in the history
This is similar to CL 478196 and CL 477296,
but this is for -buildmode=shared.

When using "go install -buildmode=shared std",
because the gold linker is used by default on Linux arm64,
it will cause temporary paths to be included in libstd.so.

Based on the changes of CL 478196,
I speculate that this may also have issues on other platforms.
So, this change is for all platform.

But I don't have any other platforms and
don't know what the file name for verification,
so the test cases are only for the Linux platform.
I hope someone can improve this testcase. Thanks!
  • Loading branch information
And-ZJ committed Sep 11, 2024
1 parent ad6ee21 commit 645847b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cmd/go/internal/work/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,10 @@ func (gcToolchain) ldShared(b *Builder, root *Action, toplevelactions []*Action,
}
ldflags = append(ldflags, d.Package.ImportPath+"="+d.Target)
}
return b.Shell(root).run(".", targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)

// Same reason in (*gcToolchain).ld
dir, targetPath := filepath.Split(targetPath)
return b.Shell(root).run(dir, targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
}

func (gcToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {
Expand Down
10 changes: 10 additions & 0 deletions src/cmd/go/testdata/script/build_shared_reproducible.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[!buildmode:shared] skip
[short] skip
[!cgo] skip '-buildmode=shared requires external linking'
[!GOOS:linux] skip

env GO111MODULE=off
env CGO_ENABLED=1
go install -a -trimpath -buildvcs=false -buildmode=shared -pkgdir=pkgdir1 runtime
go install -a -trimpath -buildvcs=false -buildmode=shared -pkgdir=pkgdir2 runtime
[GOOS:linux] cmp -q pkgdir1/libruntime.so pkgdir2/libruntime.so

0 comments on commit 645847b

Please sign in to comment.