Skip to content

Commit 645847b

Browse files
committed
cmd/go: make sure the linker for shared doesn't include tempdir path
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!
1 parent ad6ee21 commit 645847b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/cmd/go/internal/work/gc.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,10 @@ func (gcToolchain) ldShared(b *Builder, root *Action, toplevelactions []*Action,
714714
}
715715
ldflags = append(ldflags, d.Package.ImportPath+"="+d.Target)
716716
}
717-
return b.Shell(root).run(".", targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
717+
718+
// Same reason in (*gcToolchain).ld
719+
dir, targetPath := filepath.Split(targetPath)
720+
return b.Shell(root).run(dir, targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
718721
}
719722

720723
func (gcToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[!buildmode:shared] skip
2+
[short] skip
3+
[!cgo] skip '-buildmode=shared requires external linking'
4+
[!GOOS:linux] skip
5+
6+
env GO111MODULE=off
7+
env CGO_ENABLED=1
8+
go install -a -trimpath -buildvcs=false -buildmode=shared -pkgdir=pkgdir1 runtime
9+
go install -a -trimpath -buildvcs=false -buildmode=shared -pkgdir=pkgdir2 runtime
10+
[GOOS:linux] cmp -q pkgdir1/libruntime.so pkgdir2/libruntime.so

0 commit comments

Comments
 (0)