Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0a1d864
Start adding wasm
zhuowei Apr 9, 2019
85b43c3
Add wasm object emit support
zhuowei Apr 9, 2019
8899579
build-script: parse skip wasm command line args
zhuowei Apr 9, 2019
3e592d4
Handle WASM sdk in cmake
zhuowei Apr 9, 2019
3c71594
Integrate Emscripten sdk path
zhuowei Apr 10, 2019
bdfb2a2
start adding Emscripten defines in stdlib
zhuowei Apr 10, 2019
2d57b51
actually pass the icu paths into CMake
zhuowei Apr 10, 2019
a0e6c66
do not link WebAssembly shared libraries for now
zhuowei Apr 10, 2019
8ddbc24
add script to launch build
zhuowei Apr 10, 2019
f65b0bc
start adding wasm32 to 32-bit checks in stdlib
zhuowei Apr 11, 2019
358e6d5
WebAssembly: more conditional compile defines
zhuowei Apr 11, 2019
c3c8aba
Hack: Remove returnaddress calls emitted by exclusivity checks
zhuowei Apr 11, 2019
2d4a7c3
WebAssembly: Hack: disable all atomic instructions
zhuowei Apr 11, 2019
54a17ff
change non-Emscripten specific ifdefs to check for __wasm__ instead
zhuowei Apr 13, 2019
46b3f1b
Switch to WASI
zhuowei Apr 13, 2019
e45c086
fix WASI header includes
zhuowei Apr 13, 2019
dff58e6
WebAssembly: Disable Comdat for reflection metadata
zhuowei Apr 14, 2019
dd17306
Disable generating PC-relative relocations in constant builder
zhuowei Apr 14, 2019
66f84ff
WebAssembly: remove even more PCRel relocations
zhuowei Apr 14, 2019
f12d86b
WebAssembly: remove more PCRel relocations
zhuowei Apr 15, 2019
56bd1ca
WebAssembly: disable relative pointers in the runtime
zhuowei Apr 15, 2019
f68ffc8
WebAssembly: HACK: disable generating lldb-optimized debug info
zhuowei Apr 15, 2019
7e014d0
Start exporting WASI musl in Glibc modulemap
zhuowei Apr 16, 2019
a531ea6
WebAssembly: disable subprocesses
zhuowei Apr 16, 2019
8076ec3
WebAssembly: add EINVAL constant manually
zhuowei Apr 17, 2019
0fdb8dd
WebAssembly: add more wasm Glibc target dependencies to cmakefiles
zhuowei Apr 17, 2019
bf09396
WebAssembly: hack: Disable tests for now
zhuowei Apr 17, 2019
48d5ec8
WebAssembly: add more ifdefs for WebAssembly
zhuowei Apr 17, 2019
e0a29d3
disable DWARF5 and atomics on WebAssembly
zhuowei Apr 18, 2019
248b0e7
remove the older dwarf5 and atomics patch
zhuowei Apr 18, 2019
f39125c
fix wasi sdk path
zhuowei Apr 19, 2019
5cb8106
WebAssembly: HACK: use llvm-ar from the WASI sdk
zhuowei Apr 19, 2019
ba1511d
WebAssembly: remove file locking on stdin; WASI doesn't support file …
zhuowei Apr 20, 2019
ae88d97
WebAssembly: compile ImageInspectionELF for WebAssembly for now
zhuowei Apr 20, 2019
2971f1a
update icu include path
zhuowei Apr 20, 2019
961536c
[stdlib] Fix return type of swift_{uint64,int64,float*}ToString
zhuowei Apr 20, 2019
2edf4c2
[stdlib] fix return type of getNumRuntimeFunctionCounters
zhuowei Apr 20, 2019
c88a7a8
WebAssembly: add a sample script for linking a wasm file
zhuowei Apr 20, 2019
41dd834
WebAssembly: use getentropy on Wasi
zhuowei Apr 20, 2019
5e60f38
fix path to fakeld
zhuowei Apr 21, 2019
1589150
WebAssembly: add start/end objects for metadata
zhuowei Apr 22, 2019
549d2c5
attempt to fix swift_once; doesn't work
zhuowei Apr 24, 2019
6f2948e
whoops, missed a swift_once
zhuowei Apr 24, 2019
50b9f53
Add wasm branch scheme to update-checkout-config
MaxDesiatov Apr 29, 2019
26f65f3
WebAssembly: fix metadata table sizes
zhuowei Apr 30, 2019
41a900b
WebAssembly: add a ton of logging when looking up metadata
zhuowei Apr 30, 2019
4c13cba
WebAssembly: fix a typo accidentally introduced into CMake file
zhuowei Apr 30, 2019
90917be
WebAssembly: fix GOT-relative pointers without PCrel
zhuowei Apr 30, 2019
8c703ad
WebAssembly: add logging in swift_getAssociatedTypeWitness
zhuowei Apr 30, 2019
7ecc42f
Revert "WebAssembly: add logging in swift_getAssociatedTypeWitness"
zhuowei May 2, 2019
1c1b0a2
Revert "WebAssembly: add a ton of logging when looking up metadata"
zhuowei May 2, 2019
f08e1cd
WebAssembly: add replac2 section to start/end objects
zhuowei Jun 9, 2019
faec5f3
Update default checkout scheme to "wasm".
kverrier Jun 15, 2019
779841b
Revert getNumRuntimeFunctionCounters() type
MaxDesiatov Oct 13, 2019
f0f30e7
Avoid to emit inline asm for WebAssembly (#5)
kateinoigakukun Oct 15, 2019
2c73d6c
Add --build-swift-static-stdlib to build script
MaxDesiatov Oct 22, 2019
b191b7c
[WASM] Set LIBC_INCLUDE_DIRECTORY for WASM to build SwiftGlibc proper…
kateinoigakukun Oct 27, 2019
fb939ab
Support building on macOS to develop this project (#8)
kateinoigakukun Nov 2, 2019
325d951
[WASM] Build ImageInspectionShared even on macOS
kateinoigakukun Nov 3, 2019
ade0e72
[WASM] Use llvm-ar instead of ranlib on macOS
kateinoigakukun Nov 3, 2019
b15f195
[WASM] Install llvm through HomeBrew to use llvm-ar
kateinoigakukun Nov 3, 2019
b0cad39
[WASM] Use llvm-ranlib instead of ranlib of Xcode
kateinoigakukun Nov 3, 2019
f75e825
[WASM] Read offset as pointer when target is wasm
kateinoigakukun Nov 3, 2019
8621823
[WASM] Copy SwiftRT-ELF.cpp into SwiftRT-WASM.cpp
kateinoigakukun Nov 8, 2019
b7e1e39
[WASM] Emit empty swift5 sections if there aren't
kateinoigakukun Nov 8, 2019
ca8e6a8
[WASM] Remove swift_end and swift_start files
kateinoigakukun Nov 8, 2019
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
115 changes: 115 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: CI

on:
pull_request:
branches:
- swiftwasm

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

steps:
- uses: actions/checkout@v1
- name: Run a multi-line script
run: |
sudo apt update
sudo apt install \
git ninja-build clang python \
uuid-dev libicu-dev icu-devtools libbsd-dev \
libedit-dev libxml2-dev libsqlite3-dev swig \
libpython-dev libncurses5-dev pkg-config \
libblocksruntime-dev libcurl4-openssl-dev \
systemtap-sdt-dev tzdata rsync

./utils/update-checkout --clone --scheme wasm
git checkout $GITHUB_SHA
export sourcedir=$PWD/..
cd $sourcedir

wget -O install_cmake.sh "https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.sh"
chmod +x install_cmake.sh
sudo mkdir -p /opt/cmake
sudo ./install_cmake.sh --skip-license --prefix=/opt/cmake
sudo ln -sf /opt/cmake/bin/* /usr/local/bin
cmake --version

wget -O wasi-sdk.tar.gz https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
tar xfz wasi-sdk.tar.gz
mv wasi-sdk-3.19gefb17cb478f9+m/opt/wasi-sdk ./wasi-sdk

wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz"
tar xf icu.tar.xz

cd swift
utils/build-script --release --wasm --verbose \
--skip-build-benchmarks \
--extra-cmake-options=" \
-DSWIFT_SDKS='WASM;LINUX' \
-DSWIFT_BUILD_SOURCEKIT=FALSE \
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE \
-DCMAKE_AR='$sourcedir/wasi-sdk/bin/llvm-ar' \
-DCMAKE_RANLIB='$sourcedir/wasi-sdk/bin/llvm-ranlib' \
" \
--build-stdlib-deployment-targets "wasm-wasm32" \
--build-swift-static-stdlib \
--install-destdir="$sourcedir/install" \
--install-prefix="/opt/swiftwasm-sdk" \
--install-swift \
--installable-package="$sourcedir/swiftwasm.tar.gz" \
--llvm-targets-to-build "X86;WebAssembly" \
--stdlib-deployment-targets "wasm-wasm32" \
--wasm-icu-data "todo-icu-data" \
--wasm-icu-i18n "$sourcedir/icu_out/lib" \
--wasm-icu-i18n-include "$sourcedir/icu_out/include" \
--wasm-icu-uc "$sourcedir/icu_out/lib" \
--wasm-icu-uc-include "$sourcedir/icu_out/include" \
--wasm-wasi-sdk "$sourcedir/wasi-sdk"

macos_build:
timeout-minutes: 0
runs-on: macOS-10.14

steps:
- uses: actions/checkout@v1
- name: Run a multi-line script
run: |
brew install cmake ninja llvm
./utils/update-checkout --clone --scheme wasm
git checkout $GITHUB_SHA
export sourcedir=$PWD/..
cd $sourcedir
wget -O wasi-sdk.tar.gz https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
tar xfz wasi-sdk.tar.gz
mv wasi-sdk-3.19gefb17cb478f9+m/opt/wasi-sdk ./wasi-sdk
# Link sysroot/usr/include to sysroot/include because Darwin sysroot doesn't
# find header files in sysroot/include but sysroot/usr/include
mkdir wasi-sdk/share/sysroot/usr/
ln -s ../include wasi-sdk/share/sysroot/usr/include
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz"
tar xf icu.tar.xz
cd swift
./utils/build-script --release --wasm --verbose \
--skip-build-benchmarks \
--extra-cmake-options=" \
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASM \
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32 \
-DSWIFT_OSX_x86_64_ICU_STATICLIB=TRUE \
-DSWIFT_BUILD_SOURCEKIT=FALSE \
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE \
-DCMAKE_AR='/usr/local/opt/llvm/bin/llvm-ar' \
-DCMAKE_RANLIB='/usr/local/opt/llvm/bin/llvm-ranlib' \
" \
--build-stdlib-deployment-targets "wasm-wasm32" \
--build-swift-dynamic-sdk-overlay false \
--build-swift-static-sdk-overlay false \
--build-swift-static-stdlib \
--llvm-targets-to-build "X86;WebAssembly" \
--stdlib-deployment-targets "wasm-wasm32" \
--wasm-icu-data "todo-icu-data" \
--wasm-icu-i18n "$sourcedir/icu_out/lib" \
--wasm-icu-i18n-include "$sourcedir/icu_out/include" \
--wasm-icu-uc "$sourcedir/icu_out/lib" \
--wasm-icu-uc-include "$sourcedir/icu_out/include" \
--wasm-wasi-sdk "$sourcedir/wasi-sdk"
28 changes: 23 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,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;WASM)
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 @@ -654,6 +654,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 @@ -838,6 +840,22 @@ 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(WASM swift_build_wasm)
if(swift_build_wasm AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASM")
#if ("${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
# message(FATAL_ERROR "You must set SWIFT_ANDROID_NDK_PATH to cross-compile the Swift runtime for Android")
#endif()
#if (NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux"))
# message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
#endif()

if("${SWIFT_SDK_WASM_ARCHITECTURES}" STREQUAL "")
set(SWIFT_SDK_WASM_ARCHITECTURES wasm32)
endif()
configure_sdk_unix("Wasm" "${SWIFT_SDK_WASM_ARCHITECTURES}")
endif()

if("${SWIFT_SDKS}" STREQUAL "")
set(SWIFT_SDKS "${SWIFT_CONFIGURED_SDKS}")
endif()
Expand Down Expand Up @@ -1146,8 +1164,8 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
endif()

if(SWIFT_INCLUDE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
#add_subdirectory(test)
#add_subdirectory(unittests)
endif()
if(SWIFT_INCLUDE_DOCS)
add_subdirectory(docs)
Expand Down
4 changes: 4 additions & 0 deletions buildstartend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e
/home/zhuowei/wasi-sdk/bin/clang++ -c swift_start.cpp
/home/zhuowei/wasi-sdk/bin/clang++ -c swift_end.cpp
16 changes: 14 additions & 2 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ function(_add_variant_link_flags)
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
list(APPEND library_search_directories ${path})
endforeach()
elseif("${LFLAGS_SDK}" STREQUAL "WASM")
# No extra libraries needed.
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 @@ -529,7 +531,9 @@ function(_add_variant_link_flags)
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
# FIXME: On Apple platforms, find_program needs to look for "ld64.lld"
find_program(LDLLD_PATH "ld.lld")
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR
if("${LFLAGS_SDK}" STREQUAL "WASM")
list(APPEND result "-fuse-ld=${CMAKE_SOURCE_DIR}/fakeld")
elseif((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR
("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS"))
list(APPEND result "-fuse-ld=lld")
Expand Down Expand Up @@ -996,7 +1000,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 @@ -1600,6 +1605,9 @@ endfunction()
# SWIFT_MODULE_DEPENDS_HAIKU
# Swift modules this library depends on when built for Haiku.
#
# SWIFT_MODULE_DEPENDS_WASM
# Swift modules this library depends on when built for WebAssembly.
#
# FRAMEWORK_DEPENDS
# System frameworks this library depends on.
#
Expand Down Expand Up @@ -1708,6 +1716,7 @@ function(add_swift_target_library name)
SWIFT_MODULE_DEPENDS_OSX
SWIFT_MODULE_DEPENDS_TVOS
SWIFT_MODULE_DEPENDS_WATCHOS
SWIFT_MODULE_DEPENDS_WASM
SWIFT_MODULE_DEPENDS_WINDOWS
TARGET_SDKS)

Expand Down Expand Up @@ -1817,6 +1826,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 WASM)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_WASM})
elseif(${sdk} STREQUAL WINDOWS)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_WINDOWS})
Expand Down
11 changes: 11 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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 "WASM")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "WASM")
else()
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
endif()
Expand Down Expand Up @@ -317,6 +319,15 @@ 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 "WASM")
if(NOT arch STREQUAL wasm32)
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
endif()
set(SWIFT_SDK_WASM_ARCH_wasm32_PATH "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot")
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
set(SWIFT_SDK_WASM_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasm")
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/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
9 changes: 9 additions & 0 deletions fakeld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3
import sys
def outputname():
for i in range(len(sys.argv)):
if sys.argv[i] == "-o":
return sys.argv[i + 1]
return "a.out"
with open(outputname(), "wb") as outfile:
pass
1 change: 1 addition & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ namespace swift {
} else if (Target.isOSLinux() || Target.isOSFreeBSD() ||
Target.isAndroid() || Target.isOSWindows() ||
Target.isPS4() || Target.isOSHaiku() ||
Target.isOSBinFormatWasm() ||
Target.getTriple().empty()) {
major = minor = revision = 0;
} else {
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: 1 addition & 1 deletion include/swift/Runtime/Mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <type_traits>

#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__HAIKU__))
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__HAIKU__) || defined(__wasi__))
#include "swift/Runtime/MutexPThread.h"
#elif defined(_WIN32)
#include "swift/Runtime/MutexWin32.h"
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
4 changes: 4 additions & 0 deletions include/swift/Runtime/Once.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ typedef std::once_flag swift_once_t;
/// extent of type swift_once_t.
SWIFT_RUNTIME_EXPORT
void swift_once(swift_once_t *predicate, void (*fn)(void *), void *context);
#ifdef __wasm__
// WebAssembly: hack
void swift_once_real(swift_once_t *predicate, void (*fn)(void *), void *context);
#endif

}

Expand Down
4 changes: 2 additions & 2 deletions include/swift/SwiftRemoteMirror/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" {
#endif

#if defined(swiftRemoteMirror_EXPORTS)
# if defined(__ELF__)
# if defined(__ELF__) || defined(__wasm__)
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("protected")))
# elif defined(__MACH__)
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
Expand All @@ -30,7 +30,7 @@ extern "C" {
# endif
# endif
#else
# if defined(__ELF__)
# if defined(__ELF__) || defined(__wasm__)
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
# elif defined(__MACH__)
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
Expand Down
Loading