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/link: unused runtime-internal exported methods aren't getting deadcoded #70670

Open
randall77 opened this issue Dec 3, 2024 · 5 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@randall77
Copy link
Contributor

For example, internal/abi.(*SwissMapType).NeedKeyUpdate. It has a 3-instruction body and gets inlined everywhere. There is no reference to it from any code. But it still exists in the binary.
Probably this is because it is exported (starts with a capital letter), and the type *SwissMapType is reachable somehow.

Kind of anecdotal at the moment, but this may be the cause of part of the binary size increase since 1.23.

@cherrymui

A few other examples:

internal/chacha8rand.(*State).Next
sync.(*noCopy).Lock
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 3, 2024
@thanm
Copy link
Contributor

thanm commented Dec 4, 2024

Interesting problem. Output from "-ldflags=-dumpdep" seems to say

type:*internal/abi.SwissMapType <UsedInIface> -> internal/abi.(*SwissMapType).NeedKeyUpdate

I wonder if we need a new "only exported within the runtime" flavor of "exported".

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 4, 2024
@mknyszek mknyszek added this to the Go1.24 milestone Dec 4, 2024
@rsc
Copy link
Contributor

rsc commented Dec 4, 2024

It would be easy to change cmd/compile/internal/noder/lex.go to respect //go:nointerface in runtime packages, and then mark the methods with //go:nointerface.

@rsc rsc changed the title cmd/link: unused functions aren't getting deadcoded from the binary cmd/link: unused runtime-internal exported methods aren't getting deadcoded Dec 4, 2024
@rsc
Copy link
Contributor

rsc commented Dec 4, 2024

(Or we could try to figure out why SwissMapType is used in an interface.)

@randall77
Copy link
Contributor Author

It would be easy to change cmd/compile/internal/noder/lex.go to respect //go:nointerface in runtime packages, and then mark the methods with //go:nointerface.

Sure, I just worry that

  • There might be a lot of them
  • People will forget to add that annotation as new methods/types are added

@rsc
Copy link
Contributor

rsc commented Dec 4, 2024

We could also try making all the runtime packages nointerface by default and see what breaks. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants