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: linker cannot discard unused but runtime-initialized global variables #6330

Open
nigeltao opened this issue Sep 4, 2013 · 4 comments
Milestone

Comments

@nigeltao
Copy link
Contributor

nigeltao commented Sep 4, 2013

The code.google.com/p/go.text/encoding/charmap package contains variable pairs like:

var CodePage437 encoding.Encoding = &codePage437
var codePage437 = charmap{ /* a data table */ }

encoding.Encoding is an interface, so that the CodePage437 variable currently requires a
convT2I call, in a package init function. (issue #6289 is possibly related, but even if
that was fixed, suppose for argument's sake that CodePage437 was initialized by a
constructed-at-runtime composite literal.)

Because CodePage437 is implicitly referenced by a package init function, the linker
considers it used by any program that imports that package, even if it otherwise doesn't
refer to CodePage437. The linker thus can't drop the unused data table (and maybe other
related metadata like pclntab??), and likewise for the N other encoding.Encoding
implementations in that package.
@rsc
Copy link
Contributor

rsc commented Sep 5, 2013

Comment 1:

The real answer is to have fewer runtime-initialized globals.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/ld: linker cannot discard unused but runtime-initialized global variables cmd/link: linker cannot discard unused but runtime-initialized global variables Jun 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants