Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bcmills opened this issue Dec 15, 2022 · 6 comments
Open
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Dec 15, 2022

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.)

@bcmills bcmills added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Dec 15, 2022
@bcmills bcmills added this to the Backlog milestone Dec 15, 2022
@bcmills
Copy link
Contributor Author

bcmills commented Dec 15, 2022

(This issue was noticed while investigating #57328.)

@juliandanciu
Copy link

Saw the help wanted tag on this issue. May I try my hand at it? It would be my first. (@mvdan , does the 👍🏼 ❤️ on the initial comment mean you are already working on it?)

@mvdan
Copy link
Member

mvdan commented Dec 21, 2022

My reactions are only in support. In general, if anyone was working on it, it would be assigned.

@quantonganh
Copy link
Contributor

We should add a script test that verifies that the library object files really don't depend on the -trimpath flag

An expanded build ID has the following format:

actionID(binary)/actionID(main.a)/contentID(main.a)/contentID(binary)

Given 2 builds with and without -trimpath:

$ go tool buildid a.out
jeyy1T5dc2drVv2G8FBq/-gUKbztC4KAaY-khMcPo/LpRHUI2WYOhYr4OcEpMe/pBhAE-qkrmmJf4qPqOn1

$ go tool buildid b.out
OkMoPTcQGbTbAGdw-pcM/-gUKbztC4KAaY-khMcPo/LpRHUI2WYOhYr4OcEpMe/5KJVugRnLU7aFU9NZsNL

Is it possible to just compare actionID(main.a) and actionID(main.b) (-gUKbztC4KAaY-khMcPo in this case) using testscript?

@quantonganh
Copy link
Contributor

I found a way to do it:

go build -o a.out
go tool buildid a.out
cp stdout a-buildid.txt
exec awk -F/ '{print $2}' a-buildid.txt
cp stdout a-actionid.txt

go build -x -o b.out -trimpath
go tool buildid b.out
cp stdout b-buildid.txt
exec awk -F/ '{print $2}' b-buildid.txt
cp stdout b-actionid.txt
cmp a-actionid.txt b-actionid.txt

@gopherbot
Copy link

Change https://go.dev/cl/542435 mentions this issue: cmd/go: omit -trimpath from the cache key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants