Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support wasm64 #444

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
37122df
make api.h to support wasm64
trcrsired Oct 25, 2023
8d11df7
wasilibc_real support wasm64
trcrsired Oct 25, 2023
37702e7
fix api.h
trcrsired Oct 25, 2023
59a8228
fix atomic_arch for wasm64
trcrsired Oct 25, 2023
10dd8a7
initial attempt to fix c_header.rs
trcrsired Oct 26, 2023
d146432
Add support for 64 bits
trcrsired Oct 26, 2023
2659f2a
fix __wasi_thread_spawn's return type
trcrsired Oct 26, 2023
3b15bd1
change header of api.h to temporarily manually maintained
trcrsired Oct 26, 2023
48e8b25
Fix formatting issue for rustfmt
trcrsired Oct 26, 2023
a5ad684
Remove all signal apis
trcrsired Oct 30, 2023
b9d2738
Fix symbol of thread_spawn
trcrsired Oct 31, 2023
72d9602
Add wasi64 and wasi64+thread to CI
trcrsired Oct 31, 2023
dfc09f2
Change comment for CI for wasi64 and thread
trcrsired Oct 31, 2023
c9ad745
Merge wasm32 code with wasm64 code
trcrsired Oct 31, 2023
8a294b8
change comment in main.yml from wasi64 to wasm64
trcrsired Oct 31, 2023
46ed3a8
Fix c_header.rs issue with rust fmt
trcrsired Oct 31, 2023
7bd36bb
Merge branch 'WebAssembly:main' into main
trcrsired Nov 18, 2023
4877ea7
support dlfcn.h for wasm64
trcrsired Nov 18, 2023
56fdd62
Merge branch 'WebAssembly:main' into main
trcrsired Dec 11, 2023
a814fa8
add import name for wasi64 with _i64 postfix
trcrsired Dec 13, 2023
d6aac51
generate __wasilibc_real.c from rust code
trcrsired Dec 13, 2023
9703cc1
should be _i64 not -i64
trcrsired Dec 13, 2023
d2884b2
fix __wasilibc_real.c
trcrsired Dec 13, 2023
26f0de5
__WASI_NOEXCEPT missing in the definition of function
trcrsired Dec 13, 2023
3f36fea
fix __WASI_NOEXCEPT missing issue
trcrsired Dec 13, 2023
c8352f8
fix the issue that the definition of one_polloff isn't right on wasm64
trcrsired Dec 13, 2023
4f01294
fix the issue with rustfmt
trcrsired Dec 13, 2023
c889960
change _i64 postfix to _wasm64
trcrsired Dec 14, 2023
3289596
Merge branch 'WebAssembly:main' into main
trcrsired Dec 16, 2023
b08a02c
Merge remote-tracking branch 'parent/main'
trcrsired Jan 7, 2024
e6abb3c
add wasm64-wasi-preview2
trcrsired Jan 7, 2024
5c5b14e
Add wasm64-wasi-preview2 expected
trcrsired Jan 7, 2024
c94c0c6
fix CI and wasm32-wasi-preview2 predefined-macros
trcrsired Jan 7, 2024
01e6ed3
prevent clang 10 from crashing
trcrsired Jan 7, 2024
79184bf
Merge remote-tracking branch 'parent/main'
trcrsired Jan 15, 2024
84472d9
recompile to fix CI
trcrsired Jan 15, 2024
b40e999
Merge branch 'WebAssembly:main' into main
trcrsired Feb 3, 2024
12fc7a2
Merge remote-tracking branch 'parent/main'
trcrsired Mar 17, 2024
96b3d9e
fix
trcrsired Mar 17, 2024
34e1985
fix stdint.h on 64 bit wasm
trcrsired Mar 17, 2024
ce67b68
Fix makefile for new the p2 update
trcrsired Mar 17, 2024
3c387fa
Remove old preview triple
trcrsired Mar 17, 2024
2672d35
fix wasi32-wasi
trcrsired Mar 17, 2024
e027353
Merge branch 'WebAssembly:main' into main
trcrsired Mar 22, 2024
cabd676
Merge branch 'WebAssembly:main' into main
trcrsired May 30, 2024
3fa33a2
Merge branch 'WebAssembly:main' into main
trcrsired May 31, 2024
45b8471
Merge remote-tracking branch 'parent/main'
trcrsired Oct 29, 2024
bc5755d
remove -D_WASI_EMULATED_PTHREAD since it breaks llvm even we enable p…
trcrsired Oct 29, 2024
66491d2
give back shit
trcrsired Oct 29, 2024
0705ecf
force enable feature
trcrsired Oct 29, 2024
b129381
this is dogshit
trcrsired Oct 29, 2024
3992e73
fix
trcrsired Oct 29, 2024
0873325
fix
trcrsired Oct 29, 2024
8f8dfe7
fix issues
trcrsired Oct 29, 2024
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
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ jobs:
# which is required by our malloc implementation.
if: matrix.os == 'ubuntu-latest' && matrix.clang_version != '10.0.0'

- name: Build libc + threads
# Only build the thread-capable wasi-libc in the latest supported Clang
# version; the earliest version does not have all necessary builtins
# (e.g., `__builtin_wasm_memory_atomic_notify`).
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 THREAD_MODEL=posix

- name: Build wasm64 + libc
# Build wasm64
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 WASM64=yes

- name: Build wasm64 + libc + threads
# Build wasm64 with thread support
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 WASM64=yes THREAD_MODEL=posix

- uses: actions/[email protected]
with:
# Upload the sysroot folder. To avoid action erros, we give it a unique
Expand Down
58 changes: 34 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ BUILD_LIBC_TOP_HALF ?= yes
BUILD_LIBSETJMP ?= yes
# The directory where we will store intermediate artifacts.
OBJDIR ?= build/$(TARGET_TRIPLE)
# 64 bit wasm?
WASM64 ?= no

# LTO; no, full, or thin
# Note: thin LTO here is just for experimentation. It has known issues:
Expand Down Expand Up @@ -53,19 +55,37 @@ BULK_MEMORY_THRESHOLD ?= 32
# Variables from this point on are not meant to be overridable via the
# make command-line.

# Set the default WASI target triple.
TARGET_TRIPLE = wasm32-wasi

# Threaded version necessitates a different target, as objects from different
# targets can't be mixed together while linking.

ifeq ($(THREAD_MODEL), posix)
TARGET_TRIPLE = wasm32-wasi-threads
THREADS_SUFFIX=-threads
else
THREADS_SUFFIX=
endif

ifeq ($(WASI_SNAPSHOT), p2)
TARGET_TRIPLE = wasm32-wasip2
ifeq ($(WASM64), yes)
WASM_SUFFIX=64
else
WASM_SUFFIX=32
endif

TARGET_TRIPLE = wasm${WASM_SUFFIX}-wasi$(WASI_SNAPSHOT)${THREADS_SUFFIX}

ifeq ($(TARGET_TRIPLE), wasm32-wasi)
EXPECTED_TARGET_TRIPLE = wasm32-wasip1
else ifeq ($(TARGET_TRIPLE), wasm32-wasi-threads)
EXPECTED_TARGET_TRIPLE = wasm32-wasip1-threads
else ifeq ($(TARGET_TRIPLE), wasm64-wasi)
EXPECTED_TARGET_TRIPLE = wasm64-wasip1
else ifeq ($(TARGET_TRIPLE), wasm64-wasi-threads)
EXPECTED_TARGET_TRIPLE = wasm64-wasip1-threads
else
EXPECTED_TARGET_TRIPLE = ${TARGET_TRIPLE}
endif

EXPECTED_TARGET_DIR = expected/${EXPECTED_TARGET_TRIPLE}

BUILTINS_LIB ?= $(shell ${CC} ${CFLAGS} --print-libgcc-file-name)

# These variables describe the locations of various files and directories in
Expand Down Expand Up @@ -371,7 +391,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
thread/sem_timedwait.c \
thread/sem_trywait.c \
thread/sem_wait.c \
thread/wasm32/wasi_thread_start.s \
thread/wasm/wasi_thread_start.S \
)
endif
ifeq ($(THREAD_MODEL), single)
Expand Down Expand Up @@ -435,6 +455,7 @@ ifeq ($(THREAD_MODEL), posix)
# Specify the tls-model until LLVM 15 is released (which should contain
# https://reviews.llvm.org/D130053).
CFLAGS += -mthread-model posix -pthread -ftls-model=local-exec

ASMFLAGS += -matomics
endif

Expand Down Expand Up @@ -474,7 +495,7 @@ CFLAGS += -isystem "$(SYSROOT_INC)"
# These variables describe the locations of various files and directories in
# the build tree.
objs = $(patsubst %.c,$(OBJDIR)/%.o,$(1))
asmobjs = $(patsubst %.s,$(OBJDIR)/%.o,$(1))
asmobjs = $(patsubst %.S,$(OBJDIR)/%.o,$(1))
DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES))
EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES))
LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES))
Expand Down Expand Up @@ -759,7 +780,7 @@ $(OBJDIR)/%.o: %.c include_dirs
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<

$(OBJDIR)/%.o: %.s include_dirs
$(OBJDIR)/%.o: %.S include_dirs
@mkdir -p "$(@D)"
$(CC) $(ASMFLAGS) -o $@ -c $<

Expand All @@ -778,7 +799,7 @@ startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS) $(LIBC_BOTTOM_HALF_ALL_SO_OBJS): CFLA
$(LIBC_TOP_HALF_ALL_OBJS) $(LIBC_TOP_HALF_ALL_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_SO_OBJS) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS) $(LIBDL_OBJS) $(LIBDL_SO_OBJS) $(LIBSETJMP_OBJS) $(LIBSETJMP_SO_OBJS): CFLAGS += \
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal \
-I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32 \
-I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm \
-I$(LIBC_TOP_HALF_MUSL_DIR)/arch/generic \
-I$(LIBC_TOP_HALF_HEADERS_PRIVATE) \
-Wno-parentheses \
Expand All @@ -799,7 +820,7 @@ $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) $(LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJ
$(LIBWASI_EMULATED_PTHREAD_OBJS) $(LIBWASI_EMULATED_PTHREAD_SO_OBJS): CFLAGS += \
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal \
-I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32 \
-I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm \
-D_WASI_EMULATED_PTHREAD

# emmalloc uses a lot of pointer type-punning, which is UB under strict aliasing,
Expand All @@ -817,15 +838,15 @@ include_dirs:
# Generate musl's bits/alltypes.h header.
mkdir -p "$(SYSROOT_INC)/bits"
sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \
$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32/bits/alltypes.h.in \
$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm/bits/alltypes.h.in \
$(LIBC_TOP_HALF_MUSL_DIR)/include/alltypes.h.in \
> "$(SYSROOT_INC)/bits/alltypes.h"

# Copy in the bulk of musl's public header files.
cp -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)"
# Copy in the musl's "bits" header files.
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits"
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits"
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm/bits/* "$(SYSROOT_INC)/bits"

cp "$(MUSL_FTS_SRC_DIR)/fts.h" "$(SYSROOT_INC)/fts.h"

Expand Down Expand Up @@ -909,17 +930,6 @@ endif
DEFINED_SYMBOLS = $(SYSROOT_SHARE)/defined-symbols.txt
UNDEFINED_SYMBOLS = $(SYSROOT_SHARE)/undefined-symbols.txt

ifeq ($(WASI_SNAPSHOT),p2)
EXPECTED_TARGET_DIR = expected/wasm32-wasip2
else
ifeq ($(THREAD_MODEL),posix)
EXPECTED_TARGET_DIR = expected/wasm32-wasip1-threads
else
EXPECTED_TARGET_DIR = expected/wasm32-wasip1
endif
endif


check-symbols: startup_files libc
#
# Collect metadata on the sysroot and perform sanity checks.
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ build directions with one addition: `make ... THREAD_MODEL=posix`. This creates
additional artifacts in `sysroot/lib/wasm32-wasi-threads` to support `--target
wasm32-wasi-threads`.

## 64 bits support

To enable 64 bits support, follow the above
build directions with one addition: `make ... WASM64=yes`. This creates
artifacts in `sysroot/lib/wasm64-wasi` to support `--target
wasm64-wasi`.

You can build 64 bits with pthread support together with
'make ... WASM64=yes THREAD_MODEL=posix'. This creates
artifacts in `sysroot/lib/wasm64-wasi-threads` to support `--target
wasm64-wasi-threads`.

## Arch Linux AUR package

For Arch Linux users, there's an official [wasi-libc] package tracking this Git
Expand Down
3 changes: 2 additions & 1 deletion expected/wasm32-wasip1-threads/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3011,6 +3011,7 @@
#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2))
#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3))
#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0))
#define __WASI_NOEXCEPT
#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0))
#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1))
#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2))
Expand Down Expand Up @@ -3088,7 +3089,7 @@
#define __tg_real_remquo(x,y,z) (__RETCAST_2(x, y)( __FLT(x) && __FLT(y) ? remquof(x, y, z) : __LDBL((x)+(y)) ? remquol(x, y, z) : remquo(x, y, z) ))
#define __tm_gmtoff tm_gmtoff
#define __tm_zone tm_zone
#define __va_copy(d,s) __builtin_va_copy(d,s)
#define __va_copy(d,s) __builtin_va_copy(d, s)
#define __wasi__ 1
#define __wasi_api_h
#define __wasi_libc_environ_h
Expand Down
7 changes: 2 additions & 5 deletions expected/wasm32-wasip1/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,7 @@
#define _UTIME_H
#define _VALUES_H
#define _VA_LIST
#define _WASI_EMULATED_PTHREAD
#define _WCHAR_H
#define _WCHAR_T
#define _WCTYPE_H
Expand Down Expand Up @@ -3004,6 +3005,7 @@
#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2))
#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3))
#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0))
#define __WASI_NOEXCEPT
#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0))
#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1))
#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2))
Expand Down Expand Up @@ -3389,12 +3391,7 @@
#define preadv64 preadv
#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
#define pthread_create(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_detach(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_equal(x,y) ((x)==(y))
#define pthread_join(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pwrite64 pwrite
#define pwritev64 pwritev
#define readdir64 readdir
Expand Down
7 changes: 2 additions & 5 deletions expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,7 @@
#define _UTIME_H
#define _VALUES_H
#define _VA_LIST
#define _WASI_EMULATED_PTHREAD
#define _WCHAR_H
#define _WCHAR_T
#define _WCTYPE_H
Expand Down Expand Up @@ -3156,6 +3157,7 @@
#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2))
#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3))
#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0))
#define __WASI_NOEXCEPT
#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0))
#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1))
#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2))
Expand Down Expand Up @@ -3544,12 +3546,7 @@
#define preadv64 preadv
#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
#define pthread_create(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_detach(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_equal(x,y) ((x)==(y))
#define pthread_join(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
#define pwrite64 pwrite
#define pwritev64 pwritev
#define readdir64 readdir
Expand Down
Loading