Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8960

Emit a symbol reference to ensure swiftrt.o is linked on Linux/Windows

    XMLWordPrintable

    Details

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jckarter Joe Groff
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: