]> git.proxmox.com Git - wasi-libc.git/blobdiff - Makefile
test: run a subset of tests using `libc-test` (#346)
[wasi-libc.git] / Makefile
index a93b10a6757a0170953d969d0c0d806a84dd0336..aa12cf19202d8513be47c320b00b2664b6111376 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,22 +1,34 @@
 # These variables are specifically meant to be overridable via the make
 # command-line.
-WASM_CC ?= clang
-WASM_NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(WASM_CC)))
-WASM_AR ?= $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(WASM_CC)))
-WASM_CFLAGS ?= -O2 -DNDEBUG
+# ?= doesn't work for CC and AR because make has a default value for them.
+ifeq ($(origin CC), default)
+CC := clang
+endif
+NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(CC)))
+ifeq ($(origin AR), default)
+AR = $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(CC)))
+endif
+EXTRA_CFLAGS ?= -O2 -DNDEBUG
 # The directory where we build the sysroot.
 SYSROOT ?= $(CURDIR)/sysroot
 # A directory to install to for "make install".
 INSTALL_DIR ?= /usr/local
-# single or posix
+# single or posix; note that pthread support is still a work-in-progress.
 THREAD_MODEL ?= single
 # dlmalloc or none
 MALLOC_IMPL ?= dlmalloc
 # yes or no
 BUILD_LIBC_TOP_HALF ?= yes
-# The directory where we're store intermediate artifacts.
+# The directory where we will store intermediate artifacts.
 OBJDIR ?= $(CURDIR)/build
 
+# When the length is no larger than this threshold, we consider the
+# overhead of bulk memory opcodes to outweigh the performance benefit,
+# and fall back to the original musl implementation. See
+# https://github.com/WebAssembly/wasi-libc/pull/263 for relevant
+# discussion
+BULK_MEMORY_THRESHOLD ?= 32
+
 # Variables from this point on are not meant to be overridable via the
 # make command-line.
 
@@ -31,6 +43,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
@@ -38,8 +52,9 @@ LIBC_BOTTOM_HALF_HEADERS_PUBLIC = $(LIBC_BOTTOM_HALF_DIR)/headers/public
 LIBC_BOTTOM_HALF_HEADERS_PRIVATE = $(LIBC_BOTTOM_HALF_DIR)/headers/private
 LIBC_BOTTOM_HALF_SOURCES = $(LIBC_BOTTOM_HALF_DIR)/sources
 LIBC_BOTTOM_HALF_ALL_SOURCES = \
+    $(sort \
     $(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \
-    $(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c)
+    $(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c))
 
 # FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak
 # references to a function defined in `chdir.c` only work if `chdir.c` is at the
@@ -49,13 +64,13 @@ LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_SOURCES)/chdir.c
 LIBC_BOTTOM_HALF_ALL_SOURCES := $(LIBC_BOTTOM_HALF_ALL_SOURCES) $(LIBC_BOTTOM_HALF_SOURCES)/chdir.c
 
 LIBWASI_EMULATED_MMAN_SOURCES = \
-    $(shell find $(LIBC_BOTTOM_HALF_DIR)/mman -name \*.c)
+    $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/mman -name \*.c))
 LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES = \
-    $(shell find $(LIBC_BOTTOM_HALF_DIR)/clocks -name \*.c)
+    $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/clocks -name \*.c))
 LIBWASI_EMULATED_GETPID_SOURCES = \
-    $(shell find $(LIBC_BOTTOM_HALF_DIR)/getpid -name \*.c)
+    $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/getpid -name \*.c))
 LIBWASI_EMULATED_SIGNAL_SOURCES = \
-    $(shell find $(LIBC_BOTTOM_HALF_DIR)/signal -name \*.c)
+    $(sort $(shell find $(LIBC_BOTTOM_HALF_DIR)/signal -name \*.c))
 LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES = \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/signal/psignal.c \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/strsignal.c
@@ -132,6 +147,9 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
         env/setenv.c \
         env/unsetenv.c \
         unistd/posix_close.c \
+        stat/futimesat.c \
+        legacy/getpagesize.c \
+        thread/thrd_sleep.c \
     ) \
     $(filter-out %/procfdname.c %/syscall.c %/syscall_ret.c %/vdso.c %/version.c, \
                  $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/*.c)) \
@@ -170,6 +188,76 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
                  %/cimagf.c %/cimag.c %cimagl.c, \
                  $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/complex/*.c)) \
     $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/crypt/*.c)
+
+ifeq ($(THREAD_MODEL), posix)
+LIBC_TOP_HALF_MUSL_SOURCES += \
+    $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \
+        env/__init_tls.c \
+        stdio/__lockfile.c \
+        thread/__lock.c \
+        thread/__wait.c \
+        thread/__timedwait.c \
+        thread/default_attr.c \
+        thread/pthread_attr_destroy.c \
+        thread/pthread_attr_init.c \
+        thread/pthread_attr_setstack.c \
+        thread/pthread_attr_setstacksize.c \
+        thread/pthread_cleanup_push.c \
+        thread/pthread_cond_broadcast.c \
+        thread/pthread_cond_destroy.c \
+        thread/pthread_cond_init.c \
+        thread/pthread_cond_signal.c \
+        thread/pthread_cond_timedwait.c \
+        thread/pthread_cond_wait.c \
+        thread/pthread_condattr_destroy.c \
+        thread/pthread_condattr_init.c \
+        thread/pthread_condattr_setclock.c \
+        thread/pthread_condattr_setpshared.c \
+        thread/pthread_create.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 \
+        thread/pthread_mutex_getprioceiling.c \
+        thread/pthread_mutex_lock.c \
+        thread/pthread_mutex_timedlock.c \
+        thread/pthread_mutex_trylock.c \
+        thread/pthread_mutex_unlock.c \
+        thread/pthread_mutexattr_destroy.c \
+        thread/pthread_mutexattr_init.c \
+        thread/pthread_mutexattr_setprotocol.c \
+        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 \
+        thread/pthread_rwlock_timedrdlock.c \
+        thread/pthread_rwlock_timedwrlock.c \
+        thread/pthread_rwlock_tryrdlock.c \
+        thread/pthread_rwlock_trywrlock.c \
+        thread/pthread_rwlock_unlock.c \
+        thread/pthread_rwlock_wrlock.c \
+        thread/pthread_rwlockattr_destroy.c \
+        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 \
+        thread/sem_init.c \
+        thread/sem_post.c \
+        thread/sem_timedwait.c \
+        thread/sem_trywait.c \
+        thread/sem_wait.c \
+    )
+endif
+
 MUSL_PRINTSCAN_SOURCES = \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/floatscan.c \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfprintf.c \
@@ -177,14 +265,20 @@ MUSL_PRINTSCAN_SOURCES = \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfscanf.c \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/strtod.c \
     $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/wcstod.c
+BULK_MEMORY_SOURCES = \
+    $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/memcpy.c \
+    $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/memmove.c \
+    $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/memset.c
 LIBC_TOP_HALF_HEADERS_PRIVATE = $(LIBC_TOP_HALF_DIR)/headers/private
 LIBC_TOP_HALF_SOURCES = $(LIBC_TOP_HALF_DIR)/sources
 LIBC_TOP_HALF_ALL_SOURCES = \
     $(LIBC_TOP_HALF_MUSL_SOURCES) \
-    $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.c)
+    $(sort $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.c))
 
+# Add any extra flags
+CFLAGS = $(EXTRA_CFLAGS)
 # Set the target.
-CFLAGS = $(WASM_CFLAGS) --target=$(TARGET_TRIPLE)
+CFLAGS += --target=$(TARGET_TRIPLE)
 # WebAssembly floating-point match doesn't trap.
 # TODO: Add -fno-signaling-nans when the compiler supports it.
 CFLAGS += -fno-trapping-math
@@ -206,20 +300,39 @@ ifeq ($(THREAD_MODEL), single)
 CFLAGS += -mthread-model single
 endif
 ifeq ($(THREAD_MODEL), posix)
-CFLAGS += -mthread-model posix -pthread
+# 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
+
+# Include cloudlib's directory to access the structure definition of clockid_t
+CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
 endif
 
-# Set the sysroot.
-CFLAGS += --sysroot="$(SYSROOT)"
+# Expose the public headers to the implementation. We use `-isystem` for
+# purpose for two reasons:
+#
+# 1. It only does `<...>` not `"...."` lookup. We are making a libc,
+#    which is a system library, so all public headers should be
+#    accessible via `<...>` and never also need `"..."`. `-isystem` main
+#    purpose is to only effect `<...>` lookup.
+#
+# 2. The `-I` for private headers added for specific C files below
+#    should come earlier in the search path, so they can "override"
+#    and/or `#include_next` the public headers. `-isystem` (like
+#    `-idirafter`) comes later in the search path than `-I`.
+CFLAGS += -isystem "$(SYSROOT_INC)"
 
 # These variables describe the locations of various files and directories in
 # 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
@@ -234,6 +347,7 @@ endif
 MUSL_PRINTSCAN_OBJS = $(call objs,$(MUSL_PRINTSCAN_SOURCES))
 MUSL_PRINTSCAN_LONG_DOUBLE_OBJS = $(patsubst %.o,%.long-double.o,$(MUSL_PRINTSCAN_OBJS))
 MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS = $(patsubst %.o,%.no-floating-point.o,$(MUSL_PRINTSCAN_OBJS))
+BULK_MEMORY_OBJS = $(call objs,$(BULK_MEMORY_SOURCES))
 LIBWASI_EMULATED_MMAN_OBJS = $(call objs,$(LIBWASI_EMULATED_MMAN_SOURCES))
 LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS = $(call objs,$(LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES))
 LIBWASI_EMULATED_GETPID_OBJS = $(call objs,$(LIBWASI_EMULATED_GETPID_SOURCES))
@@ -323,11 +437,12 @@ MUSL_OMIT_HEADERS += \
     "netinet/ether.h" \
     "sys/timerfd.h" \
     "libintl.h" \
-    "sys/sysmacros.h"
+    "sys/sysmacros.h" \
+    "aio.h"
 
 ifeq ($(THREAD_MODEL), single)
 # Remove headers not supported in single-threaded mode.
-MUSL_OMIT_HEADERS += "aio.h" "pthread.h"
+MUSL_OMIT_HEADERS += "pthread.h"
 endif
 
 default: finish
@@ -349,13 +464,13 @@ $(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBW
 %.a:
        @mkdir -p "$(@D)"
        # On Windows, the commandline for the ar invocation got too long, so it needs to be split up.
-       $(WASM_AR) crs $@ $(wordlist 1, 199, $^)
-       $(WASM_AR) crs $@ $(wordlist 200, 399, $^)
-       $(WASM_AR) crs $@ $(wordlist 400, 599, $^)
-       $(WASM_AR) crs $@ $(wordlist 600, 799, $^)
+       $(AR) crs $@ $(wordlist 1, 199, $^)
+       $(AR) crs $@ $(wordlist 200, 399, $^)
+       $(AR) crs $@ $(wordlist 400, 599, $^)
+       $(AR) crs $@ $(wordlist 600, 799, $^)
        # This might eventually overflow again, but at least it'll do so in a loud way instead of
        # silently dropping the tail.
-       $(WASM_AR) crs $@ $(wordlist 800, 100000, $^)
+       $(AR) crs $@ $(wordlist 800, 100000, $^)
 
 $(MUSL_PRINTSCAN_OBJS): CFLAGS += \
            -D__wasilibc_printscan_no_long_double \
@@ -365,20 +480,28 @@ $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS): CFLAGS += \
            -D__wasilibc_printscan_no_floating_point \
            -D__wasilibc_printscan_floating_point_support_option="\"remove -lc-printscan-no-floating-point from the link command\""
 
+# TODO: apply -mbulk-memory globally, once
+# https://github.com/llvm/llvm-project/issues/52618 is resolved
+$(BULK_MEMORY_OBJS): CFLAGS += \
+        -mbulk-memory
+
+$(BULK_MEMORY_OBJS): CFLAGS += \
+        -DBULK_MEMORY_THRESHOLD=$(BULK_MEMORY_THRESHOLD)
+
 $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \
            -D_WASI_EMULATED_SIGNAL
 
 $(OBJDIR)/%.long-double.o: $(CURDIR)/%.c include_dirs
        @mkdir -p "$(@D)"
-       $(WASM_CC) $(CFLAGS) -MD -MP -o $@ -c $<
+       $(CC) $(CFLAGS) -MD -MP -o $@ -c $<
 
 $(OBJDIR)/%.no-floating-point.o: $(CURDIR)/%.c include_dirs
        @mkdir -p "$(@D)"
-       $(WASM_CC) $(CFLAGS) -MD -MP -o $@ -c $<
+       $(CC) $(CFLAGS) -MD -MP -o $@ -c $<
 
 $(OBJDIR)/%.o: $(CURDIR)/%.c include_dirs
        @mkdir -p "$(@D)"
-       $(WASM_CC) $(CFLAGS) -MD -MP -o $@ -c $<
+       $(CC) $(CFLAGS) -MD -MP -o $@ -c $<
 
 -include $(shell find $(OBJDIR) -name \*.d)
 
@@ -388,7 +511,9 @@ $(DLMALLOC_OBJS): CFLAGS += \
 startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS): CFLAGS += \
     -I$(LIBC_BOTTOM_HALF_HEADERS_PRIVATE) \
     -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC) \
-    -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
+    -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) \
+    -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \
+    -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal
 
 $(LIBC_TOP_HALF_ALL_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \
     -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \
@@ -408,8 +533,6 @@ $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS): CFLAGS += \
     -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
 
 include_dirs:
-       $(RM) -r "$(SYSROOT)"
-
        #
        # Install the include files.
        #
@@ -438,7 +561,7 @@ startup_files: include_dirs
        #
        @mkdir -p "$(OBJDIR)"
        cd "$(OBJDIR)" && \
-       $(WASM_CC) $(CFLAGS) -c $(LIBC_BOTTOM_HALF_CRT_SOURCES) -MD -MP && \
+       $(CC) $(CFLAGS) -c $(LIBC_BOTTOM_HALF_CRT_SOURCES) -MD -MP && \
        mkdir -p "$(SYSROOT_LIB)" && \
        mv *.o "$(SYSROOT_LIB)"
 
@@ -456,7 +579,7 @@ finish: startup_files libc
        # Create empty placeholder libraries.
        #
        for name in m rt pthread crypt util xnet resolv dl; do \
-           $(WASM_AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \
+           $(AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \
        done
 
        #
@@ -470,6 +593,9 @@ ifneq ($(MALLOC_IMPL),none)
 finish: check-symbols
 endif
 
+DEFINED_SYMBOLS = $(SYSROOT_SHARE)/defined-symbols.txt
+UNDEFINED_SYMBOLS = $(SYSROOT_SHARE)/undefined-symbols.txt
+
 check-symbols: startup_files libc
        #
        # Collect metadata on the sysroot and perform sanity checks.
@@ -483,28 +609,28 @@ check-symbols: startup_files libc
        @# LLVM PR40497, which is fixed in 9.0, but not in 8.0.
        @# Ignore certain llvm builtin symbols such as those starting with __mul
        @# since these dependencies can vary between llvm versions.
-       "$(WASM_NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \
-           |grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort > "$(SYSROOT_SHARE)/defined-symbols.txt"
-       for undef_sym in $$("$(WASM_NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
+       "$(NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \
+           |grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort |uniq > "$(DEFINED_SYMBOLS)"
+       for undef_sym in $$("$(NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
            |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
-           grep -q '\<'$$undef_sym'\>' "$(SYSROOT_SHARE)/defined-symbols.txt" || echo $$undef_sym; \
-       done | grep -v "^__mul" > "$(SYSROOT_SHARE)/undefined-symbols.txt"
-       grep '^_*imported_wasi_' "$(SYSROOT_SHARE)/undefined-symbols.txt" \
+           grep -q '\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo $$undef_sym; \
+       done | grep -v "^__mul" > "$(UNDEFINED_SYMBOLS)"
+       grep '^_*imported_wasi_' "$(UNDEFINED_SYMBOLS)" \
            > "$(SYSROOT_LIB)/libc.imports"
 
        #
-       # Generate a test file that includes all public header files.
+       # Generate a test file that includes all public header files.
        #
-       cd "$(SYSROOT)" && \
-         for header in $$(find include -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h |grep -v /bits/); do \
-             echo '#include <'$$header'>' | sed 's/include\///' ; \
-       done |LC_ALL=C sort >share/$(MULTIARCH_TRIPLE)/include-all.c ; \
+       cd "$(SYSROOT_INC)" && \
+         for header in $$(find . -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h |grep -v /bits/ |grep -v /c++/); do \
+             echo '#include <'$$header'>' | sed 's/\.\///' ; \
+       done |LC_ALL=C sort >$(SYSROOT_SHARE)/include-all.c ; \
        cd - >/dev/null
 
        #
        # Test that it compiles.
        #
-       $(WASM_CC) $(CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings
+       $(CC) $(CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings
 
        #
        # Collect all the predefined macros, except for compiler version macros
@@ -520,7 +646,10 @@ check-symbols: startup_files libc
        @#
        @# TODO: Undefine __FLOAT128__ for now since it's not in clang 8.0.
        @# TODO: Filter out __FLT16_* for now, as not all versions of clang have these.
-       $(WASM_CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \
+       @# 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.
+       $(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \
            -isystem $(SYSROOT_INC) \
            -std=gnu17 \
            -E -dM -Wno-\#warnings \
@@ -538,16 +667,24 @@ check-symbols: startup_files libc
            -U__GNUC_PATCHLEVEL__ \
            -U__VERSION__ \
            -U__FLOAT128__ \
+           -U__NO_MATH_ERRNO__ \
+           -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/' \
            | 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)" "$(SYSROOT_SHARE)"
+       diff -wur "$(CURDIR)/expected/$(MULTIARCH_TRIPLE)/$(THREAD_MODEL)" "$(SYSROOT_SHARE)"
 
 install: finish
        mkdir -p "$(INSTALL_DIR)"
        cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
 
-.PHONY: default startup_files libc finish install include_dirs
+clean:
+       $(RM) -r "$(OBJDIR)"
+       $(RM) -r "$(SYSROOT)"
+
+.PHONY: default startup_files libc finish install include_dirs clean