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: ELF external linking puts all symbols in dynamic symbol table #53579

Open
ianlancetaylor opened this issue Jun 27, 2022 · 6 comments
Open
Assignees
Labels
compiler/runtime NeedsFix
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 27, 2022

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

@gopherbot gopherbot commented Jun 27, 2022

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

@tkoeppe
Copy link

@tkoeppe 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
Contributor Author

@ianlancetaylor ianlancetaylor commented Jun 28, 2022

--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 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
Contributor Author

@ianlancetaylor ianlancetaylor commented Jun 28, 2022

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 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 label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime NeedsFix
Projects
Status: Triage Backlog
Development

No branches or pull requests

3 participants