[SR-8960] Emit a symbol reference to ensure swiftrt.o is linked on Linux/Windows #51465
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
good first issue
Good for newcomers
Linux
Platform: Linux
runtime
The Swift Runtime
Additional Detail from JIRA
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.
The text was updated successfully, but these errors were encountered: