Proposal: Improve dead code ilimination when using CGO #38135
Labels
FrozenDueToAge
Proposal
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Build an executable that uses a large C library statically linked.
What did you expect to see?
A smaller executable
What did you see instead?
A kind-of large executable.
I'm not completely sure about this, but when Go links, either statically or dynamically, I think it includes a reference to all C functions wrapped with CGO in the resulting executable, even if those functions are never called.
It would help to only include required C symbols. This could in theory help the C compiler do dead code ilimination with static libraries. Adding the CFLAGS -ffunction-sections -fdata-sections, and LDFLAGS -Wl,-gc-sections could also do something.
Thanks.
The text was updated successfully, but these errors were encountered: