golang/go

cmd/go: make cache keys for libraries in GOROOT insensitive to `-trimpath`

Open

#57,346 opened on Dec 15, 2022

View on GitHub
 (6 comments) (2 reactions) (0 assignees)Go (19,008 forks)batch import
GoCommandNeedsInvestigationhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

In CL 380915 we observed that libraries in GOROOT contain the literal string $GOROOT instead of their absolute paths, even when -trimpath is not set.

As a result, we should (theoretically) compile the same bytes for those libraries regardless of whether -trimpath is set. We can therefore omit -trimpath from the cache key, allowing object files already in the cache to be reused in more cases.

We should add a script test that verifies that the library object files really don't depend on the -trimpath flag, make the flags passed to the compiler ignore cfg.BuildTrimpath for those libraries, and then update cmd/go/internal/work to omit it from the cache key.

(Note that we cannot omit it from the cache key for executables, since those are stamped with the actual GOROOT or GOROOT_FINAL during linking.)

Contributor guide