]> git.proxmox.com Git - wasi-libc.git/blobdiff - Makefile
Use a separate OBJDIR for each TARGET_TRIPLE (#373)
[wasi-libc.git] / Makefile
index 7f71a3e23d476d5db296988154feb06feabd8b8e..7461adfd08e5bf34bee77734213a029996fa97a8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,8 +19,8 @@ THREAD_MODEL ?= single
 MALLOC_IMPL ?= dlmalloc
 # yes or no
 BUILD_LIBC_TOP_HALF ?= yes
-# The directory where we're store intermediate artifacts.
-OBJDIR ?= $(CURDIR)/build
+# The directory where we will store intermediate artifacts.
+OBJDIR ?= $(CURDIR)/build/$(TARGET_TRIPLE)
 
 # When the length is no larger than this threshold, we consider the
 # overhead of bulk memory opcodes to outweigh the performance benefit,
@@ -32,10 +32,14 @@ BULK_MEMORY_THRESHOLD ?= 32
 # Variables from this point on are not meant to be overridable via the
 # make command-line.
 
-# Set the target variables. Multiarch triples notably omit the vendor field,
-# which happens to be what we do for the main target triple too.
+# Set the default WASI target triple.
 TARGET_TRIPLE = wasm32-wasi
-MULTIARCH_TRIPLE = wasm32-wasi
+
+# Threaded version necessitates a different traget, as objects from different
+# targets can't be mixed together while linking.
+ifeq ($(THREAD_MODEL), posix)
+TARGET_TRIPLE = wasm32-wasi-pthread
+endif
 
 # These variables describe the locations of various files and directories in
 # the source tree.
@@ -43,6 +47,8 @@ DLMALLOC_DIR = $(CURDIR)/dlmalloc
 DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src
 DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/dlmalloc.c
 DLMALLOC_INC = $(DLMALLOC_DIR)/include
+EMMALLOC_DIR = $(CURDIR)/emmalloc
+EMMALLOC_SOURCES = $(EMMALLOC_DIR)/emmalloc.c
 LIBC_BOTTOM_HALF_DIR = $(CURDIR)/libc-bottom-half
 LIBC_BOTTOM_HALF_CLOUDLIBC_SRC = $(LIBC_BOTTOM_HALF_DIR)/cloudlibc/src
 LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC = $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/include
@@ -139,6 +145,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
         fcntl/creat.c \
         dirent/alphasort.c \
         dirent/versionsort.c \
+        env/__stack_chk_fail.c \
         env/clearenv.c \
         env/getenv.c \
         env/putenv.c \
@@ -190,8 +197,23 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
 ifeq ($(THREAD_MODEL), posix)
 LIBC_TOP_HALF_MUSL_SOURCES += \
     $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \
+        env/__init_tls.c \
+        stdio/__lockfile.c \
+        stdio/flockfile.c \
+        stdio/ftrylockfile.c \
+        stdio/funlockfile.c \
+        thread/__lock.c \
         thread/__wait.c \
         thread/__timedwait.c \
+        thread/default_attr.c \
+        thread/pthread_attr_destroy.c \
+        thread/pthread_attr_get.c \
+        thread/pthread_attr_init.c \
+        thread/pthread_attr_setstack.c \
+        thread/pthread_attr_setstacksize.c \
+        thread/pthread_barrier_destroy.c \
+        thread/pthread_barrier_init.c \
+        thread/pthread_barrier_wait.c \
         thread/pthread_cleanup_push.c \
         thread/pthread_cond_broadcast.c \
         thread/pthread_cond_destroy.c \
@@ -204,6 +226,10 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
         thread/pthread_condattr_setclock.c \
         thread/pthread_condattr_setpshared.c \
         thread/pthread_create.c \
+        thread/pthread_detach.c \
+        thread/pthread_getspecific.c \
+        thread/pthread_join.c \
+        thread/pthread_key_create.c \
         thread/pthread_mutex_consistent.c \
         thread/pthread_mutex_destroy.c \
         thread/pthread_mutex_init.c \
@@ -218,6 +244,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
         thread/pthread_mutexattr_setpshared.c \
         thread/pthread_mutexattr_setrobust.c \
         thread/pthread_mutexattr_settype.c \
+        thread/pthread_once.c \
         thread/pthread_rwlock_destroy.c \
         thread/pthread_rwlock_init.c \
         thread/pthread_rwlock_rdlock.c \
@@ -231,6 +258,8 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
         thread/pthread_rwlockattr_init.c \
         thread/pthread_rwlockattr_setpshared.c \
         thread/pthread_setcancelstate.c \
+        thread/pthread_setspecific.c \
+        thread/pthread_self.c \
         thread/pthread_testcancel.c \
         thread/sem_destroy.c \
         thread/sem_getvalue.c \
@@ -310,10 +339,13 @@ CFLAGS += -isystem "$(SYSROOT_INC)"
 # the build tree.
 objs = $(patsubst $(CURDIR)/%.c,$(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))
 LIBC_TOP_HALF_ALL_OBJS = $(call objs,$(LIBC_TOP_HALF_ALL_SOURCES))
 ifeq ($(MALLOC_IMPL),dlmalloc)
 LIBC_OBJS += $(DLMALLOC_OBJS)
+else ifeq ($(MALLOC_IMPL),emmalloc)
+LIBC_OBJS += $(EMMALLOC_OBJS)
 else ifeq ($(MALLOC_IMPL),none)
 # No object files to add.
 else
@@ -337,9 +369,9 @@ LIBWASI_EMULATED_SIGNAL_MUSL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_MUSL_S
 
 # These variables describe the locations of various files and
 # directories in the generated sysroot tree.
-SYSROOT_LIB := $(SYSROOT)/lib/$(MULTIARCH_TRIPLE)
+SYSROOT_LIB := $(SYSROOT)/lib/$(TARGET_TRIPLE)
 SYSROOT_INC = $(SYSROOT)/include
-SYSROOT_SHARE = $(SYSROOT)/share/$(MULTIARCH_TRIPLE)
+SYSROOT_SHARE = $(SYSROOT)/share/$(TARGET_TRIPLE)
 
 # Files from musl's include directory that we don't want to install in the
 # sysroot's include directory.
@@ -630,6 +662,9 @@ check-symbols: startup_files libc
        @# TODO: Filter out __NO_MATH_ERRNO_ and a few __*WIDTH__ that are new to clang 14.
        @# TODO: clang defined __FLT_EVAL_METHOD__ until clang 15, so we force-undefine it
        @# for older versions.
+       @# TODO: Undefine __wasm_mutable_globals__ and __wasm_sign_ext__, that are new to
+       @# clang 16 for -mcpu=generic.
+       @# TODO: As of clang 16, __GNUC_VA_LIST is #defined without a value.
        $(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \
            -isystem $(SYSROOT_INC) \
            -std=gnu17 \
@@ -643,6 +678,8 @@ check-symbols: startup_files libc
            -U__clang_version__ \
            -U__clang_literal_encoding__ \
            -U__clang_wide_literal_encoding__ \
+           -U__wasm_mutable_globals__ \
+           -U__wasm_sign_ext__ \
            -U__GNUC__ \
            -U__GNUC_MINOR__ \
            -U__GNUC_PATCHLEVEL__ \
@@ -652,13 +689,14 @@ check-symbols: startup_files libc
            -U__BITINT_MAXWIDTH__ \
            -U__FLT_EVAL_METHOD__ -Wno-builtin-macro-redefined \
            | sed -e 's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \
+           | sed -e 's/__GNUC_VA_LIST $$/__GNUC_VA_LIST 1/' \
            | grep -v '^#define __FLT16_' \
            | grep -v '^#define __\(BOOL\|INT_\(LEAST\|FAST\)\(8\|16\|32\|64\)\|INT\|LONG\|LLONG\|SHRT\)_WIDTH__' \
            > "$(SYSROOT_SHARE)/predefined-macros.txt"
 
        # Check that the computed metadata matches the expected metadata.
        # This ignores whitespace because on Windows the output has CRLF line endings.
-       diff -wur "$(CURDIR)/expected/$(MULTIARCH_TRIPLE)/$(THREAD_MODEL)" "$(SYSROOT_SHARE)"
+       diff -wur "$(CURDIR)/expected/$(TARGET_TRIPLE)" "$(SYSROOT_SHARE)"
 
 install: finish
        mkdir -p "$(INSTALL_DIR)"