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

[SR-8960] Emit a symbol reference to ensure swiftrt.o is linked on Linux/Windows #51465

Open
jckarter opened this issue Oct 10, 2018 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers Linux Platform: Linux runtime The Swift Runtime

Comments

@jckarter
Copy link
Member

Previous ID SR-8960
Radar None
Original Reporter @jckarter
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Linux, Runtime, StarterBug
Assignee None
Priority Medium

md5: 7f33519b3b36a320eb441265efc7bc17

Issue Description:

On Linux and Windows, Swift binaries rely on a small stub object file to inject a static constructor necessary to register with the Swift runtime on load. When Swift object files are incorporated with other language object files and build systems, it's easy to forget to explicitly link this object file, which can appear to work at first but leads to surprising behavior when the metadata for the binary cannot be found at runtime. We can have the linker help us out with this problem, by having swiftrt.o define a dummy absolute symbol with a conspicuous name, and having the Swift compiler emit a dummy reference to this symbol if the generated IR includes any data structures that require runtime registration, so that linking without including swiftrt.o fails.

It should be possible to do this in such a way that the resulting symbols get dead-stripped because they wouldn't in reality be used anywhere by the final linked image.

@compnerd
Copy link
Collaborator

Hmm, I've not tried this, but, the idea that comes to mind on Windows is to use the auto-linking to inject the actual object file name into the linker invocation. It should result in the linker searching and finding it. Once the lld implementation for the auto linking on ELF is complete, we could extend it to that as well. Note that the swift driver already explicitly links it, so this is for those cases where people are doing things that they should not be doing (i.e. invoking tools without the driver). But, then again, we were bit by this even knowing the details (oops!)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers Linux Platform: Linux runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

2 participants