Skip to content

Swift Runtime on WebAssembly #11

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 8 commits into from
Nov 8, 2019

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Nov 8, 2019

This PR enables Swift's runtime support on WebAssembly.

What Changed

stdlib/public/runtime/SwiftRT-WASM.cpp

I changed to emit start and end address of sections prefixed with swift5_ such as swift5_protocol_conformances.
wasm-ld supports this feature since llvm/llvm-project@4bce63a

To handle the case when compiler doesn't emit the sections, creates dummy symbol located in the section.

lib/IRGen/MetadataRequest.cpp

__swift_instantiateConcreteTypeFromMangledName was designed to use relative pointer, so I changed to use absolute pointer only when WebAssembly.

Misc

  • Use latest version of llvm-ar and llvm-ranlib instead of ar and ranlib bundled in Xcode because they doesn't support linking section of WebAssembly object file.
  • Build ImageInspectionShared even on macOS environment only when targeting WebAssembly

Copy link

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit 👍

@MaxDesiatov MaxDesiatov merged commit ba958a2 into swiftwasm:swiftwasm Nov 8, 2019
MaxDesiatov pushed a commit that referenced this pull request Nov 14, 2019
* [WASM] Build ImageInspectionShared even on macOS
ImageInspectionShared was built only if host OS is Linux. But it's
necessary when primary sdk is WASM.
* [WASM] Use llvm-ar instead of ranlib on macOS
Specify ar binary through extra-cmake-options
* [WASM] Install llvm through HomeBrew to use llvm-ar
* [WASM] Use llvm-ranlib instead of ranlib of Xcode
* [WASM] Read offset as pointer when target is wasm
Because WASM doesn't support relative pointer, compiler emit direct
address instead of offset from current address.
* [WASM] Copy SwiftRT-ELF.cpp into SwiftRT-WASM.cpp
* [WASM] Emit empty swift5 sections if there aren't
* [WASM] Remove swift_end and swift_start files
@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Nov 17, 2019
MaxDesiatov pushed a commit that referenced this pull request Dec 14, 2019
This PR fixed my runtime implementation in SwiftRT.
I've inserted dummy `char` data in each metadata sections to ensure that all start/stop symbols are generated in #11. But of cource this dummy data can be inserted anywhere in the section, so metadata sections were broken by this 1 byte.

I changed to link these start/stop symbols weakly. Non-generated start/stop variables get to be uninitialized. So `stop-start` results 0 length, and runtime library can avoid to load empty section.

After this and #6 are merged, `print("Hello")` will work again! 🎉
kateinoigakukun added a commit to kateinoigakukun/swift that referenced this pull request Dec 14, 2019
This PR fixed my runtime implementation in SwiftRT.
I've inserted dummy `char` data in each metadata sections to ensure that all start/stop symbols are generated in swiftwasm#11. But of cource this dummy data can be inserted anywhere in the section, so metadata sections were broken by this 1 byte.

I changed to link these start/stop symbols weakly. Non-generated start/stop variables get to be uninitialized. So `stop-start` results 0 length, and runtime library can avoid to load empty section.

After this and swiftwasm#6 are merged, `print("Hello")` will work again! 🎉
kateinoigakukun added a commit that referenced this pull request Dec 15, 2019
* [WASM] Build ImageInspectionShared even on macOS
ImageInspectionShared was built only if host OS is Linux. But it's
necessary when primary sdk is WASM.
* [WASM] Use llvm-ar instead of ranlib on macOS
Specify ar binary through extra-cmake-options
* [WASM] Install llvm through HomeBrew to use llvm-ar
* [WASM] Use llvm-ranlib instead of ranlib of Xcode
* [WASM] Read offset as pointer when target is wasm
Because WASM doesn't support relative pointer, compiler emit direct
address instead of offset from current address.
* [WASM] Copy SwiftRT-ELF.cpp into SwiftRT-WASM.cpp
* [WASM] Emit empty swift5 sections if there aren't
* [WASM] Remove swift_end and swift_start files
kateinoigakukun added a commit to kateinoigakukun/swift that referenced this pull request Jan 11, 2020
This PR fixed my runtime implementation in SwiftRT.
I've inserted dummy `char` data in each metadata sections to ensure that all start/stop symbols are generated in swiftwasm#11. But of cource this dummy data can be inserted anywhere in the section, so metadata sections were broken by this 1 byte.

I changed to link these start/stop symbols weakly. Non-generated start/stop variables get to be uninitialized. So `stop-start` results 0 length, and runtime library can avoid to load empty section.

After this and swiftwasm#6 are merged, `print("Hello")` will work again! 🎉
kateinoigakukun added a commit that referenced this pull request Jan 11, 2020
* [WASM] Build ImageInspectionShared even on macOS
ImageInspectionShared was built only if host OS is Linux. But it's
necessary when primary sdk is WASM.
* [WASM] Use llvm-ar instead of ranlib on macOS
Specify ar binary through extra-cmake-options
* [WASM] Install llvm through HomeBrew to use llvm-ar
* [WASM] Use llvm-ranlib instead of ranlib of Xcode
* [WASM] Read offset as pointer when target is wasm
Because WASM doesn't support relative pointer, compiler emit direct
address instead of offset from current address.
* [WASM] Copy SwiftRT-ELF.cpp into SwiftRT-WASM.cpp
* [WASM] Emit empty swift5 sections if there aren't
* [WASM] Remove swift_end and swift_start files
kateinoigakukun added a commit to kateinoigakukun/swift that referenced this pull request Jan 24, 2020
This PR fixed my runtime implementation in SwiftRT.
I've inserted dummy `char` data in each metadata sections to ensure that all start/stop symbols are generated in swiftwasm#11. But of cource this dummy data can be inserted anywhere in the section, so metadata sections were broken by this 1 byte.

I changed to link these start/stop symbols weakly. Non-generated start/stop variables get to be uninitialized. So `stop-start` results 0 length, and runtime library can avoid to load empty section.

After this and swiftwasm#6 are merged, `print("Hello")` will work again! 🎉
kateinoigakukun added a commit to kateinoigakukun/swift that referenced this pull request Jan 25, 2020
This PR fixed my runtime implementation in SwiftRT.
I've inserted dummy `char` data in each metadata sections to ensure that all start/stop symbols are generated in swiftwasm#11. But of cource this dummy data can be inserted anywhere in the section, so metadata sections were broken by this 1 byte.

I changed to link these start/stop symbols weakly. Non-generated start/stop variables get to be uninitialized. So `stop-start` results 0 length, and runtime library can avoid to load empty section.

After this and swiftwasm#6 are merged, `print("Hello")` will work again! 🎉
@kateinoigakukun kateinoigakukun deleted the katei/wasm-runtime branch January 28, 2020 12:42
MaxDesiatov pushed a commit that referenced this pull request Jan 29, 2020
* [WASM] Build ImageInspectionShared even on macOS
ImageInspectionShared was built only if host OS is Linux. But it's
necessary when primary sdk is WASM.
* [WASM] Use llvm-ar instead of ranlib on macOS
Specify ar binary through extra-cmake-options
* [WASM] Install llvm through HomeBrew to use llvm-ar
* [WASM] Use llvm-ranlib instead of ranlib of Xcode
* [WASM] Read offset as pointer when target is wasm
Because WASM doesn't support relative pointer, compiler emit direct
address instead of offset from current address.
* [WASM] Copy SwiftRT-ELF.cpp into SwiftRT-WASM.cpp
* [WASM] Emit empty swift5 sections if there aren't
* [WASM] Remove swift_end and swift_start files
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants