Skip to content

IRGen: make the autolink work better in COFF environments #14493

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

Merged
merged 1 commit into from
Feb 11, 2018

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Feb 8, 2018

This was obscured due to local workarounds. Because the reference is
cross-module, and the symbol itself will be rebased, it cannot serve as
a constant initializer (the value is not known until runtime). However,
using a function pointer is permissible. The linker will materialize a
thunk for the function itself and cause the module to be force linked.
This also works on ELF and MachO as well. The overhead associated with
this is pretty minimal as the function itself has an empty body, and
flags will differentiate between a function and data symbol. The slight
penalty in size (on the order of 2-4 bytes) allows for the same pattern
to be used across all the targets.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Member Author

compnerd commented Feb 8, 2018

CC: @aschwaighofer

@compnerd
Copy link
Member Author

compnerd commented Feb 8, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 9, 2018

Build failed
Swift Test OS X Platform
Git Sha - e99c4a23bfdde5494fece560d37e6da647675f5c

@jrose-apple
Copy link
Contributor

Yeah, this is probably worth it, especially since it'll end up in the text section anyway. If we can think of anything even better to force linking, we can switch to that later.

This was obscured due to local workarounds.  Because the reference is
cross-module, and the symbol itself will be rebased, it cannot serve as
a constant initializer (the value is not known until runtime).  However,
using a function pointer is permissible.  The linker will materialize a
thunk for the function itself and cause the module to be force linked.
This also works on ELF and MachO as well.  The overhead associated with
this is pretty minimal as the function itself has an empty body, and
flags will differentiate between a function and data symbol.  The slight
penalty in size (on the order of 2-4 bytes) allows for the same pattern
to be used across all the targets.
@compnerd
Copy link
Member Author

@swift-ci please test and merge

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

Successfully merging this pull request may close these issues.

3 participants