Skip to content

cmd/link: ELF external linking puts all symbols in dynamic symbol table #53579

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

Closed
ianlancetaylor opened this issue Jun 27, 2022 · 6 comments
Closed
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Member

Currently external linking on ELF systems passes -rdynamic to the external linker, which tells it to put all exported symbols into the dynamic symbol table. This is unnecessary in the normal case. It wastes space in the executable, and effectively disables garbage collection in the external linker. We should instead only export symbols that may need to be exported.

I have a patch for this which we can try for the 1.20 release.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 27, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.20 milestone Jun 27, 2022
@ianlancetaylor ianlancetaylor self-assigned this Jun 27, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/414654 mentions this issue: cmd/link: don't export all symbols for ELF external linking

@tkoeppe
Copy link

tkoeppe commented Jun 28, 2022

Interesting that there are so many linkers that don't have --export-dynamic-symbol. Do they perhaps offer some other way of selectively exporting symbols?

@ianlancetaylor
Copy link
Member Author

--export-dynamic-symbol was added to GNU ld in the 2.35 release (mid-2020). The gold linker has had it since 2012. lld has it; I don't know when it was added but it has probably always had it.

I think we're just seeing builders using older versions of the GNU linker. I don't think the GNU linker provides any other mechanism.

@tkoeppe
Copy link

tkoeppe commented Jun 28, 2022

Re "how long can the command line get": instead of --export-dynamic-symbol we have also been using --dynamic-list and put all the to-be-exported symbols in a file. That flag too might not be universally available, though.

@ianlancetaylor
Copy link
Member Author

I don't think we can safely use --dynamic-list, as it is documented to set the complete list of dynamic symbols. That is, symbols not in the list are not put in the dynamic symbol table. We aren't going to know what symbols in C code should be in the dynamic symbol table.

@tkoeppe
Copy link

tkoeppe commented Jun 28, 2022

Fair enough. I think with lld the various flags can be combined and the symbol lists are merged, but I also don't find the documentation entirely clear.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@mknyszek mknyszek moved this to Triage Backlog in Go Compiler / Runtime Jul 15, 2022
@mknyszek mknyszek moved this from Triage Backlog to Todo in Go Compiler / Runtime Nov 23, 2022
@github-project-automation github-project-automation bot moved this from Todo to Done in Go Compiler / Runtime Jan 25, 2023
@dmitshur dmitshur modified the milestones: Go1.20, Go1.21 Jul 17, 2023
@golang golang locked and limited conversation to collaborators Jul 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants