Skip to content

Commit

Permalink
Revamp and simplify the libpreopen code. (WebAssembly#110)
Browse files Browse the repository at this point in the history
wasi-libc's copy of libpreopen has evolved so many local changes that
it's no longer worth keeping the upstream code structure and marking
changes with __wasilibc_unmodified_upstream.

This PR merges the source files into a single file, removes all
__wasilibc_unmodified_upstream code, eliminates the ability to
allocate multiple preopen lists, eliminates the need for
__wasilibc_init_preopen, eliminates the non-standard eaccess, and
makes several other cleanups. It also enables NDEBUG so that internal
assertions are disabled in release builds.
  • Loading branch information
sunfishcode authored Nov 4, 2019
1 parent eb7230c commit 7fcc4f2
Show file tree
Hide file tree
Showing 12 changed files with 558 additions and 1,607 deletions.
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
WASM_CC ?= clang
WASM_NM ?= $(patsubst %clang,%llvm-nm,$(WASM_CC))
WASM_AR ?= $(patsubst %clang,%llvm-ar,$(WASM_CC))
WASM_CFLAGS ?= -O2
WASM_CFLAGS ?= -O2 -DNDEBUG
# The directory where we build the sysroot.
SYSROOT ?= $(CURDIR)/sysroot
# A directory to install to for "make install".
Expand Down Expand Up @@ -45,12 +45,10 @@ LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC = $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/include
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_LIBPREOPEN_DIR = $(LIBC_BOTTOM_HALF_DIR)/libpreopen
LIBC_BOTTOM_HALF_LIBPREOPEN_LIB = $(LIBC_BOTTOM_HALF_LIBPREOPEN_DIR)/lib
LIBC_BOTTOM_HALF_LIBPREOPEN_INC = $(LIBC_BOTTOM_HALF_LIBPREOPEN_DIR)/include
LIBC_BOTTOM_HALF_SOURCES = $(LIBC_BOTTOM_HALF_DIR)/sources
LIBC_BOTTOM_HALF_ALL_SOURCES = \
$(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \
$(LIBC_BOTTOM_HALF_LIBPREOPEN_LIB)/po_libc_wrappers.c \
$(LIBC_BOTTOM_HALF_LIBPREOPEN_DIR)/libpreopen.c \
$(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c)
LIBWASI_EMULATED_MMAN_SOURCES = \
$(shell find $(LIBC_BOTTOM_HALF_DIR)/mman -name \*.c)
Expand Down Expand Up @@ -364,9 +362,7 @@ $(DLMALLOC_OBJS): override WASM_CFLAGS += \
startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS): override WASM_CFLAGS += \
-I$(LIBC_BOTTOM_HALF_HEADERS_PRIVATE) \
-I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC) \
-I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) \
-I$(LIBC_BOTTOM_HALF_LIBPREOPEN_LIB) \
-I$(LIBC_BOTTOM_HALF_LIBPREOPEN_INC)
-I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)

$(LIBC_TOP_HALF_ALL_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS): override WASM_CFLAGS += \
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \
Expand Down
2 changes: 0 additions & 2 deletions expected/wasm32-wasi/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ __uselocale
__utc
__wasilibc_fd_renumber
__wasilibc_find_relpath
__wasilibc_init_preopen
__wasilibc_populate_environ
__wasilibc_register_preopened_fd
__wasilibc_rmdirat
Expand Down Expand Up @@ -428,7 +427,6 @@ drand48
drem
dremf
duplocale
eaccess
ecvt
encrypt
environ
Expand Down
3 changes: 2 additions & 1 deletion expected/wasm32-wasi/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@
#define NAN (0.0f/0.0f)
#define NBBY 8
#define NCARGS 131072
#define NDEBUG 1
#define ND_NA_FLAG_OVERRIDE 0x00000020
#define ND_NA_FLAG_ROUTER 0x00000080
#define ND_NA_FLAG_SOLICITED 0x00000040
Expand Down Expand Up @@ -3171,7 +3172,7 @@
#define and_eq &=
#define asin(x) __tg_real_complex(asin, (x))
#define asinh(x) __tg_real_complex(asinh, (x))
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
#define assert(x) (void)0
#define atan(x) __tg_real_complex(atan, (x))
#define atan2(x,y) __tg_real_2(atan2, (x), (y))
#define atanh(x) __tg_real_complex(atanh, (x))
Expand Down
2 changes: 0 additions & 2 deletions libc-bottom-half/crt/crt1.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ extern void __prepare_for_exit(void);
void _Exit(int) __attribute__((noreturn));

static __wasi_errno_t populate_libpreopen(void) {
__wasilibc_init_preopen();

// Skip stdin, stdout, and stderr, and count up until we reach an invalid
// file descriptor.
for (__wasi_fd_t fd = 3; fd != 0; ++fd) {
Expand Down
215 changes: 0 additions & 215 deletions libc-bottom-half/libpreopen/include/libpreopen.h

This file was deleted.

Loading

0 comments on commit 7fcc4f2

Please sign in to comment.