Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
04898dc
Start adding wasm
zhuowei Apr 9, 2019
73c32e4
Add wasm object emit support
zhuowei Apr 9, 2019
f4fffee
build-script: parse skip wasm command line args
zhuowei Apr 9, 2019
5cff1a4
Handle WASM sdk in cmake
zhuowei Apr 9, 2019
38207f6
Integrate Emscripten sdk path
zhuowei Apr 10, 2019
600d18d
start adding Emscripten defines in stdlib
zhuowei Apr 10, 2019
0183a71
actually pass the icu paths into CMake
zhuowei Apr 10, 2019
00d28d5
do not link WebAssembly shared libraries for now
zhuowei Apr 10, 2019
d3960c3
add script to launch build
zhuowei Apr 10, 2019
d05719b
start adding wasm32 to 32-bit checks in stdlib
zhuowei Apr 11, 2019
51e6801
WebAssembly: more conditional compile defines
zhuowei Apr 11, 2019
53291de
Hack: Remove returnaddress calls emitted by exclusivity checks
zhuowei Apr 11, 2019
2480483
WebAssembly: Hack: disable all atomic instructions
zhuowei Apr 11, 2019
14b4925
change non-Emscripten specific ifdefs to check for __wasm__ instead
zhuowei Apr 13, 2019
9354b78
Switch to WASI
zhuowei Apr 13, 2019
99c0a17
fix WASI header includes
zhuowei Apr 13, 2019
0dfa4f5
WebAssembly: Disable Comdat for reflection metadata
zhuowei Apr 14, 2019
5e864fb
Disable generating PC-relative relocations in constant builder
zhuowei Apr 14, 2019
f7bb4f5
WebAssembly: remove even more PCRel relocations
zhuowei Apr 14, 2019
31edacc
WebAssembly: remove more PCRel relocations
zhuowei Apr 15, 2019
85c1cdc
WebAssembly: disable relative pointers in the runtime
zhuowei Apr 15, 2019
2dfc622
Start exporting WASI musl in Glibc modulemap
zhuowei Apr 16, 2019
3fc86e1
WebAssembly: disable subprocesses
zhuowei Apr 16, 2019
80342ee
WebAssembly: add EINVAL constant manually
zhuowei Apr 17, 2019
5e46b85
WebAssembly: add more wasm Glibc target dependencies to cmakefiles
zhuowei Apr 17, 2019
b1210ac
WebAssembly: hack: Disable tests for now
zhuowei Apr 17, 2019
e7b56e9
WebAssembly: add more ifdefs for WebAssembly
zhuowei Apr 17, 2019
8d1f660
disable DWARF5 and atomics on WebAssembly
zhuowei Apr 18, 2019
d967fde
remove the older dwarf5 and atomics patch
zhuowei Apr 18, 2019
2815215
fix wasi sdk path
zhuowei Apr 19, 2019
431f9a2
WebAssembly: HACK: use llvm-ar from the WASI sdk
zhuowei Apr 19, 2019
5e5c605
WebAssembly: remove file locking on stdin; WASI doesn't support file …
zhuowei Apr 20, 2019
37ed5e5
WebAssembly: compile ImageInspectionELF for WebAssembly for now
zhuowei Apr 20, 2019
fc87f70
update icu include path
zhuowei Apr 20, 2019
88076d9
WebAssembly: add a sample script for linking a wasm file
zhuowei Apr 20, 2019
e35604e
WebAssembly: use getentropy on Wasi
zhuowei Apr 20, 2019
0254423
fix path to fakeld
zhuowei Apr 21, 2019
53d2e91
WebAssembly: add start/end objects for metadata
zhuowei Apr 22, 2019
5ce06a3
attempt to fix swift_once; doesn't work
zhuowei Apr 24, 2019
861684d
whoops, missed a swift_once
zhuowei Apr 24, 2019
3d8e478
Add wasm branch scheme to update-checkout-config
MaxDesiatov Apr 29, 2019
92d6050
WebAssembly: fix metadata table sizes
zhuowei Apr 30, 2019
64c0cd3
WebAssembly: add a ton of logging when looking up metadata
zhuowei Apr 30, 2019
87be907
WebAssembly: fix a typo accidentally introduced into CMake file
zhuowei Apr 30, 2019
f3c4faf
WebAssembly: fix GOT-relative pointers without PCrel
zhuowei Apr 30, 2019
b939a11
WebAssembly: add logging in swift_getAssociatedTypeWitness
zhuowei Apr 30, 2019
1843a87
Revert "WebAssembly: add logging in swift_getAssociatedTypeWitness"
zhuowei May 2, 2019
2406043
Revert "WebAssembly: add a ton of logging when looking up metadata"
zhuowei May 2, 2019
b9b9781
WebAssembly: add replac2 section to start/end objects
zhuowei Jun 9, 2019
b0b619e
Update default checkout scheme to "wasm".
kverrier Jun 15, 2019
c009468
Add --build-swift-static-stdlib to build script
MaxDesiatov Oct 22, 2019
d62abee
[WASM] Set LIBC_INCLUDE_DIRECTORY for WASM to build SwiftGlibc proper…
kateinoigakukun Oct 27, 2019
14e332e
Support building on macOS to develop this project (#8)
kateinoigakukun Nov 2, 2019
a1088a3
Swift Runtime on WebAssembly (#11)
kateinoigakukun Nov 8, 2019
aebc3d5
Move CI build commands to separate scripts (#13)
MaxDesiatov Nov 12, 2019
d41ecb2
Install wget in ci-linux.sh, make path explicit in build-linux.sh
MaxDesiatov Nov 12, 2019
dbd6ee5
Update WASI SDK, create installable package on macOS (#14)
MaxDesiatov Nov 14, 2019
3d08a9f
Make SymbolLookup.swift compilable for wasm (#16)
MaxDesiatov Nov 15, 2019
a732d98
Run packaging scripts and smoke test on CI (#15)
MaxDesiatov Nov 16, 2019
c55891d
Upload SwiftWasm artifacts for later inspection (#17)
MaxDesiatov Nov 17, 2019
c897d93
Move packaging scripts from swiftwasm-package-sdk (#18)
MaxDesiatov Nov 19, 2019
8b49c06
[WASM] Link start/stop symbol weakly (#21)
kateinoigakukun Dec 14, 2019
5cf1bed
Emit thunk function for specific ABI on WebAssembly. (#6)
kateinoigakukun Dec 14, 2019
61d7f23
[WebAssembly] Remove conflicted default case
kateinoigakukun Dec 15, 2019
d780253
[WASM] Replace Wasm with WASI to switch target OS
kateinoigakukun Dec 15, 2019
61efa16
[WebAssembly] Fix merge conflicts
kateinoigakukun Dec 15, 2019
c8b9281
[WebAssembly] Fix target triple for CI
kateinoigakukun Dec 15, 2019
433b143
Fix build comand script for macOS
kateinoigakukun Dec 15, 2019
0dea906
Fix paths in packaging scripts (#23)
MaxDesiatov Dec 15, 2019
4ad17cf
Bump macOS to 10.15 in GitHub Actions (#25)
MaxDesiatov Dec 18, 2019
af61a0e
Remove fakeld (#26)
karwa Dec 19, 2019
b4f0d39
Re-enable tests (#24)
kateinoigakukun Dec 24, 2019
5fa53d0
Eliminate fakepthread dependency (#27)
kateinoigakukun Dec 25, 2019
20a16aa
Fix sil-func-extractor and driver (#28)
kateinoigakukun Dec 25, 2019
f297a62
[WASM] [CI] Install llvm on Linux
kateinoigakukun Jan 24, 2020
4651cb6
[WASM] [CI] Fix to un-archive with J due to vm tool version
kateinoigakukun Jan 24, 2020
62294fd
[WASM] [CI] Specify repository name
kateinoigakukun Jan 24, 2020
7e457d5
[WASM] [CI] Install six manually
kateinoigakukun Jan 24, 2020
119a61b
Fix conflict mistake
kateinoigakukun Jan 24, 2020
f4fbad5
Fix unit tests part1 (#31)
kateinoigakukun Jan 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: CI

on:
push:
branches:
- swiftwasm
pull_request:
branches:
- swiftwasm

jobs:
linux_build:
timeout-minutes: 0
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
with:
path: swift
- name: Build Linux installable archive
run: ./utils/webassembly/ci-linux.sh
- name: Upload Linux installable archive
uses: actions/upload-artifact@v1
with:
name: linux-installable
path: ../swiftwasm-linux.tar.gz
- name: Pack test results
run: tar cJf swift-test-results.tar.gz ../build/*/swift-linux-x86_64/swift-test-results
- name: Upload test results
uses: actions/upload-artifact@v1
with:
name: linux-test-results
path: ./swift-test-results.tar.gz

macos_build:
timeout-minutes: 0
runs-on: macos-latest

steps:
- uses: actions/checkout@v1
with:
path: swift
- name: Build macOS installable archive
run: ./utils/webassembly/ci-mac.sh
- name: Upload macOS installable archive
uses: actions/upload-artifact@v1
with:
name: macos-installable
path: ../swiftwasm-macos.tar.gz
- name: Upload packaging scripts
uses: actions/upload-artifact@v1
with:
name: packaging-scripts
path: utils/webassembly
- name: Pack test results
run: tar cJf swift-test-results.tar.gz ../build/*/swift-macosx-x86_64/swift-test-results
- name: Upload test results
uses: actions/upload-artifact@v1
with:
name: macos-test-results
path: ./swift-test-results.tar.gz
package:
name: Build SwiftWasm packages
needs:
- linux_build
- macos_build
runs-on: ubuntu-18.04
steps:
- name: Download installable Linux archive
uses: actions/download-artifact@v1
with:
name: linux-installable
- name: Download installable macOS archive
uses: actions/download-artifact@v1
with:
name: macos-installable
- name: Download packaging scripts
uses: actions/download-artifact@v1
with:
name: packaging-scripts
- name: Build the packages
shell: bash
run: |
cd packaging-scripts
find . -name '*.sh' -exec chmod +x {} \;
chmod +x sdkroot/swiftwasm
./download-prebuilts.sh

cp ../linux-installable/swiftwasm-linux.tar.gz \
../macos-installable/swiftwasm-macos.tar.gz \
prebuilt
./build-packages.sh

cd output
tar xf swiftwasm-sdk-linux.tar.xz && echo "Successfully unpacked Linux SDK"

cd swiftwasm-sdk
./swiftwasm example/hello.swift hello.wasm && echo "Successfully linked hello.wasm"

- name: Upload macOS package
uses: actions/upload-artifact@v1
with:
name: macos-package
path: packaging-scripts/output/swiftwasm-sdk-macos.tar.xz

- name: Upload Linux package
uses: actions/upload-artifact@v1
with:
name: linux-package
path: packaging-scripts/output/swiftwasm-sdk-linux.tar.xz

- name: Upload hello.wasm compiled with Linux package
uses: actions/upload-artifact@v1
with:
name: linux-hello.wasm
path: packaging-scripts/output/swiftwasm-sdk/hello.wasm

macos_smoke_test:
name: Compile hello.swift on macOS
runs-on: macos-latest
needs: package
steps:
- name: Download SwiftWasm macOS package
uses: actions/download-artifact@v1
with:
name: macos-package

- name: Build hello.wasm
shell: bash
run: |
cd macos-package
tar xf swiftwasm-sdk-macos.tar.xz && echo "Successfully unpacked macOS SDK"

cd swiftwasm-sdk
./swiftwasm example/hello.swift hello.wasm && echo "Successfully linked hello.wasm"

- name: Upload hello.wasm compiled with macOS package
uses: actions/upload-artifact@v1
with:
name: macos-hello.wasm
path: macos-package/swiftwasm-sdk/hello.wasm
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")

#
# User-configurable ICU specific options for Android, FreeBSD, Linux and Haiku.
# User-configurable ICU specific options for Android, FreeBSD, Linux, Haiku, and WebAssembly.
#

foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
foreach(arch aarch64;armv6;armv7;i686;powerpc64;powerpc64le;s390x;x86_64)
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU;WASI)
foreach(arch aarch64;armv6;armv7;i686;powerpc64;powerpc64le;s390x;wasm32;x86_64)
set(SWIFT_${sdk}_${arch}_ICU_UC "" CACHE STRING
"Path to a directory containing the icuuc library for ${sdk}")
set(SWIFT_${sdk}_${arch}_ICU_UC_INCLUDE "" CACHE STRING
Expand Down Expand Up @@ -595,6 +595,8 @@ else()
set(SWIFT_HOST_VARIANT_ARCH_default "powerpc64le")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
set(SWIFT_HOST_VARIANT_ARCH_default "s390x")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "wasm32")
set(SWIFT_HOST_VARIANT_ARCH_default "wasm32")
# FIXME: Only matches v6l/v7l - by far the most common variants
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
set(SWIFT_HOST_VARIANT_ARCH_default "armv6")
Expand Down Expand Up @@ -779,6 +781,18 @@ if(swift_build_windows AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
configure_sdk_windows("Windows" "msvc" "${SWIFT_SDK_WINDOWS_ARCHITECTURES}")
endif()

# Should we cross-compile the standard library for WebAssembly (WASI)?
is_sdk_requested(WASI swift_build_wasm)
if(swift_build_wasm AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
if(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY OR SWIFT_BUILD_DYNAMIC_STDLIB)
message(FATAL_ERROR "Unable to build dynamic overlay/stdlib for WASI. WASM does not support dynamic linking.")
endif()
if("${SWIFT_SDK_WASI_ARCHITECTURES}" STREQUAL "")
set(SWIFT_SDK_WASI_ARCHITECTURES wasm32)
endif()
configure_sdk_unix("WASI" "${SWIFT_SDK_WASI_ARCHITECTURES}")
endif()

if("${SWIFT_SDKS}" STREQUAL "")
set(SWIFT_SDKS "${SWIFT_CONFIGURED_SDKS}")
endif()
Expand Down
22 changes: 21 additions & 1 deletion cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ function(_add_variant_c_compile_flags)
list(APPEND result -isystem;${path})
endforeach()
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
elseif("${CFLAGS_SDK}" STREQUAL "WASI")
list(APPEND result "-D_WASI_EMULATED_MMAN")
elseif(CFLAGS_SDK STREQUAL WINDOWS)
swift_windows_include_for_arch(${CFLAGS_ARCH} ${CFLAGS_ARCH}_INCLUDE)
foreach(path ${${CFLAGS_ARCH}_INCLUDE})
Expand Down Expand Up @@ -439,6 +441,8 @@ function(_add_variant_swift_compile_flags
foreach(path IN LISTS ${arch}_swift_include)
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
endforeach()
elseif("${sdk}" STREQUAL "WASI")
list(APPEND result "-Xcc" "-D_WASI_EMULATED_MMAN")
endif()

if(NOT BUILD_STANDALONE)
Expand Down Expand Up @@ -551,6 +555,8 @@ function(_add_variant_link_flags)
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
list(APPEND library_search_directories ${path})
endforeach()
elseif("${LFLAGS_SDK}" STREQUAL "WASI")
list(APPEND result "-Wl,wasi-emulated-mman")
else()
# If lto is enabled, we need to add the object path flag so that the LTO code
# generator leaves the intermediate object file in a place where it will not
Expand Down Expand Up @@ -1072,7 +1078,8 @@ function(_add_swift_library_single target name)
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
if(("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF") AND
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF" OR
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "WASM") AND
SWIFTLIB_SINGLE_TARGET_LIBRARY)
if("${libkind}" STREQUAL "SHARED" AND NOT SWIFTLIB_SINGLE_NOSWIFTRT)
# TODO(compnerd) switch to the generator expression when cmake is upgraded
Expand Down Expand Up @@ -1399,6 +1406,12 @@ function(_add_swift_library_single target name)
list(APPEND c_compile_flags -D_WINDLL)
endif()
endif()
# Double-check that we're not trying to build a dynamic library for WASM.
if(SWIFTLIB_SINGLE_SDK MATCHES WASM)
if(libkind STREQUAL SHARED)
message(FATAL_ERROR "WASM does not support shared libraries.")
endif()
endif()
_add_variant_link_flags(
SDK "${SWIFTLIB_SINGLE_SDK}"
ARCH "${SWIFTLIB_SINGLE_ARCHITECTURE}"
Expand Down Expand Up @@ -1710,6 +1723,9 @@ endfunction()
# SWIFT_MODULE_DEPENDS_HAIKU
# Swift modules this library depends on when built for Haiku.
#
# SWIFT_MODULE_DEPENDS_WASI
# Swift modules this library depends on when built for WASI.
#
# FRAMEWORK_DEPENDS
# System frameworks this library depends on.
#
Expand Down Expand Up @@ -1826,6 +1842,7 @@ function(add_swift_target_library name)
SWIFT_MODULE_DEPENDS_OSX
SWIFT_MODULE_DEPENDS_TVOS
SWIFT_MODULE_DEPENDS_WATCHOS
SWIFT_MODULE_DEPENDS_WASI
SWIFT_MODULE_DEPENDS_WINDOWS
SWIFT_MODULE_DEPENDS_FROM_SDK
TARGET_SDKS
Expand Down Expand Up @@ -1987,6 +2004,9 @@ function(add_swift_target_library name)
elseif(${sdk} STREQUAL HAIKU)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_HAIKU})
elseif(${sdk} STREQUAL WASI)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_WASI})
elseif(${sdk} STREQUAL WINDOWS)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_WINDOWS})
Expand Down
10 changes: 10 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ macro(configure_sdk_unix name architectures)
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
if("${prefix}" STREQUAL "CYGWIN")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
elseif("${prefix}" STREQUAL "WASI")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "WASM")
else()
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
endif()
Expand Down Expand Up @@ -333,6 +335,14 @@ macro(configure_sdk_unix name architectures)
message(FATAL_ERROR "unsupported arch for Haiku: ${arch}")
endif()
set(SWIFT_SDK_HAIKU_ARCH_x86_64_TRIPLE "x86_64-unknown-haiku")
elseif("${prefix}" STREQUAL "WASI")
if(NOT arch STREQUAL wasm32)
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
endif()
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot")
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot/include")
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot/include")
else()
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
endif()
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/SwiftSetIfArchBitness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function(set_if_arch_bitness var_name)
"${SIA_ARCH}" STREQUAL "armv6" OR
"${SIA_ARCH}" STREQUAL "armv7" OR
"${SIA_ARCH}" STREQUAL "armv7k" OR
"${SIA_ARCH}" STREQUAL "armv7s")
"${SIA_ARCH}" STREQUAL "armv7s" OR
"${SIA_ARCH}" STREQUAL "wasm32")
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)
elseif("${SIA_ARCH}" STREQUAL "x86_64" OR
"${SIA_ARCH}" STREQUAL "arm64" OR
Expand Down
10 changes: 10 additions & 0 deletions include/swift/Basic/Lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
#include <memory>
#ifdef __APPLE__
#include <dispatch/dispatch.h>
#elif defined(__wasi__)
// No pthread on wasi
#else
#include <mutex>
#endif
#include "swift/Basic/Malloc.h"
#include "swift/Basic/type_traits.h"

#ifdef __wasi__
void wasi_polyfill_call_once(int *flag, void *context, void (*func)(void *));
#endif

namespace swift {

#ifdef __APPLE__
Expand All @@ -36,6 +42,10 @@ namespace swift {
using OnceToken_t = unsigned long;
# define SWIFT_ONCE_F(TOKEN, FUNC, CONTEXT) \
_swift_once_f(&TOKEN, CONTEXT, FUNC)
#elif defined(__wasi__)
using OnceToken_t = int;
# define SWIFT_ONCE_F(TOKEN, FUNC, CONTEXT) \
::wasi_polyfill_call_once(&TOKEN, CONTEXT, FUNC)
#else
using OnceToken_t = std::once_flag;
# define SWIFT_ONCE_F(TOKEN, FUNC, CONTEXT) \
Expand Down
12 changes: 12 additions & 0 deletions include/swift/Basic/RelativePointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ static inline uintptr_t applyRelativeOffset(BasePtrTy *basePtr, Offset offset) {
std::is_signed<Offset>::value,
"offset type should be signed integer");

#ifdef __wasm__
// WebAssembly: hack: disable relative pointers
return (uintptr_t)(intptr_t)offset;
#endif

auto base = reinterpret_cast<uintptr_t>(basePtr);
// We want to do wrapping arithmetic, but with a sign-extended
// offset. To do this in C, we need to do signed promotion to get
Expand All @@ -164,6 +169,13 @@ static inline Offset measureRelativeOffset(A *referent, B *base) {
static_assert(std::is_integral<Offset>::value &&
std::is_signed<Offset>::value,
"offset type should be signed integer");
#ifdef __wasm__
// WebAssembly: hack: disable relative pointers
auto offset = (Offset)(uintptr_t)referent;
assert((intptr_t)offset == (intptr_t)(uintptr_t)referent
&& "pointer too large to fit in offset type");
return offset;
#endif

auto distance = (uintptr_t)referent - (uintptr_t)base;
// Truncate as unsigned, then wrap around to signed.
Expand Down
5 changes: 5 additions & 0 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,11 @@ class ApplyIRLinkage {
// TODO: BFD and gold do not handle COMDATs properly
if (Triple.isOSBinFormatELF())
return;
// WebAssembly: hack: comdat + custom section = explosion
// the comdat code assumes section name would be unique for each comdat
// this doesn't happen for metadata.
if (Triple.isOSBinFormatWasm())
return;

if (IRL.Linkage == llvm::GlobalValue::LinkOnceODRLinkage ||
IRL.Linkage == llvm::GlobalValue::WeakODRLinkage)
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Runtime/Mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "swift/Runtime/MutexPThread.h"
#elif defined(_WIN32)
#include "swift/Runtime/MutexWin32.h"
#elif defined(__wasi__)
#include "swift/Runtime/MutexWASI.h"
#else
#error "Implement equivalent of MutexPThread.h/cpp for your platform."
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Runtime/MutexPThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef pthread_cond_t ConditionHandle;
typedef pthread_mutex_t MutexHandle;
typedef pthread_rwlock_t ReadWriteLockHandle;

#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__)
#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__) || defined(__wasi__)
// At the moment CYGWIN pthreads implementation doesn't support the use of
// constexpr for static allocation versions. The way they define things
// results in a reinterpret_cast which violates constexpr. Similarly, Android's
Expand Down
Loading