Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

WIP: [Swift+WASM] patches to support compiling Swift to WebAssembly #155

Draft
wants to merge 8 commits into
base: stable
Choose a base branch
from

Conversation

zhuowei
Copy link

@zhuowei zhuowei commented May 10, 2019

These are the LLVM changes required to cross-compile Swift programs to WebAssembly.

List of changes:

  • support -gmodules (debugging information in precompiled headers), used by Clang when compiling stdlib
  • enable Swift calling convention for webassembly
  • Support alias symbols with offsets
  • cherry-pick wasm linking info v2 patch from LLVM master:

See apple/swift#24684 for more information.

We're planning to upstream the required patches to upstream LLVM.

@compnerd
Copy link
Collaborator

These should be sent to llvm.org, not be merged into the swift repos.

@zhuowei
Copy link
Author

zhuowei commented May 17, 2019

@compnerd Thanks! Yes, we're planning to upstream these.

zhuowei and others added 8 commits October 22, 2019 11:30
Like Patcheng's https://reviews.llvm.org/D42233 but for Custom Sections instead

padding for the padding gods.
Also try hard to extract a symbol from a MCExpr when writing relocations

I doubt this is the right way, but hey it emits an object now
I actually do need to know what's breaking.
Swift uses aliased symbols to refer to offsets within metadata structures.

eg

```
@"$s12SwiftPrivate28_stdlib_ShardedAtomicCounterVN" = alias %swift.type, bitcast (i32* getelementptr inbounds (<{ i8**, i32, <{ i32, i32, i32, i32, i32, i32, i32 }>*, i32, i32 }>, <{ i8**, i32, <{ i32, i32, i32, i32, i32, i32, i32 }>*, i32, i32 }>* @"$s12SwiftPrivate28_stdlib_ShardedAtomicCounterVMf", i32 0, i32 1) to %swift.type*)
```

My previous commit only got the alias to refer to the correct target symbol,
but not at the right offset.

This commit properly emits these symbols.

With this change, print("hello world") works but print() with anything else is still broken.
Don't need the logging anymore

This reverts commit 8b8f31f.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants