Skip to content

cmd/link: unused runtime-internal exported methods aren't getting deadcoded #70670

Open

Description

@randall77

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

Activity

  1. thanm commented on Dec 4, 2024

    @thanm
    Contributor

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

  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Dec 4, 2024
  3. added this to the Go1.24 milestone on Dec 4, 2024
  4. rsc commented on Dec 4, 2024

    @rsc
    Contributor

    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.

  5. 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[/+] on Dec 4, 2024
  6. rsc commented on Dec 4, 2024

    @rsc
    Contributor

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

  7. randall77 commented on Dec 4, 2024

    @randall77
    ContributorAuthor

    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
  8. modified the milestones: Go1.24, Go1.25 on Dec 4, 2024
  9. rsc commented on Dec 4, 2024

    @rsc
    Contributor

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

  10. nightlyone commented on Feb 14, 2025

    @nightlyone
    Contributor

    Or turn it from method into a function if it never needs to satisfy any interface.

  11. modified the milestones: Go1.25, Go1.26 on Aug 12, 2025
  12. modified the milestones: Go1.26, Go1.27 on Feb 10, 2026
  13. modified the milestones: Go1.27, Go1.28 on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions