[SR-8960] Emit a symbol reference to ensure swiftrt.o is linked on Linux/Windows
#51.465 aperta il 10 ott 2018
Metriche repository
- Star
- (69.989 star)
- Metriche merge PR
- (Merge medio 8g 17h) (510 PR mergiate in 30 g)
Descrizione
| Previous ID | SR-8960 |
| Radar | None |
| Original Reporter | @jckarter |
| Type | Bug |
| 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.