]> git.proxmox.com Git - wasi-libc.git/commitdiff
Add build flag to select malloc implementation
authorAyke van Laethem <aykevanlaethem@gmail.com>
Tue, 13 Jul 2021 21:10:58 +0000 (23:10 +0200)
committerDan Gohman <dev@sunfishcode.online>
Mon, 26 Jul 2021 20:42:15 +0000 (13:42 -0700)
Add a build flag MALLOC_IMPL that can be set to dlmalloc or none
(defaulting to dlmalloc) which controls the malloc implementation to
use. The dlmalloc option is the same as before, but selecting none
removes dlmalloc from the libc build.

This flag replaces the BUILD_DLMALLOC flag, which never worked and thus
can be removed without breaking any builds. By switching to MALLOC_IMPL,
there is a clear path towards a different heap implementation, such as
mimalloc.

Makefile

index 754bd2b6784ceeebf96046d058f04f480891aab1..48558cda45fc22aec92cd472fc7cadce5a69375c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,17 +10,13 @@ SYSROOT ?= $(CURDIR)/sysroot
 INSTALL_DIR ?= /usr/local
 # single or posix
 THREAD_MODEL ?= single
+# dlmalloc or none
+MALLOC_IMPL ?= dlmalloc
 # yes or no
-BUILD_DLMALLOC ?= yes
 BUILD_LIBC_TOP_HALF ?= yes
 # The directory where we're store intermediate artifacts.
 OBJDIR ?= $(CURDIR)/build
 
-# Check dependencies.
-ifneq ($(BUILD_DLMALLOC),yes)
-$(error build currently depends on BUILD_DLMALLOC=yes)
-endif
-
 # Variables from this point on are not meant to be overridable via the
 # make command-line.
 
@@ -220,8 +216,12 @@ objs = $(patsubst $(CURDIR)/%.c,$(OBJDIR)/%.o,$(1))
 DLMALLOC_OBJS = $(call objs,$(DLMALLOC_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 ($(BUILD_DLMALLOC),yes)
+ifeq ($(MALLOC_IMPL),dlmalloc)
 LIBC_OBJS += $(DLMALLOC_OBJS)
+else ifeq ($(MALLOC_IMPL),none)
+# No object files to add.
+else
+$(error unknown malloc implementation $(MALLOC_IMPL))
 endif
 # Add libc-bottom-half's objects.
 LIBC_OBJS += $(LIBC_BOTTOM_HALF_ALL_OBJS)
@@ -457,6 +457,18 @@ finish: startup_files libc
            $(WASM_AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \
        done
 
+       #
+       # The build succeeded! The generated sysroot is in $(SYSROOT).
+       #
+
+# The check for defined and undefined symbols expects there to be a heap
+# alloctor (providing malloc, calloc, free, etc). Skip this step if the build
+# is done without a malloc implementation.
+ifneq ($(MALLOC_IMPL),none)
+finish: check-symbols
+endif
+
+check-symbols: startup_files libc
        #
        # Collect metadata on the sysroot and perform sanity checks.
        #
@@ -530,10 +542,6 @@ finish: startup_files libc
        # This ignores whitespace because on Windows the output has CRLF line endings.
        diff -wur "$(CURDIR)/expected/$(MULTIARCH_TRIPLE)" "$(SYSROOT_SHARE)"
 
-       #
-       # The build succeeded! The generated sysroot is in $(SYSROOT).
-       #
-
 install: finish
        mkdir -p "$(INSTALL_DIR)"
        cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"