Skip to content

Proposal: Improve dead code ilimination when using CGO #38135

@Keithcat1

Description

@Keithcat1

What version of Go are you using (go version)?

$ go version
go version go1.14.1 windows/amd64                                                                                              

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions