From 3a14878e457555761cafe26c6c1f328da35b9b77 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 9 Aug 2023 15:56:39 -0600 Subject: [PATCH 1/5] add stubs for dlopen, dlsym, etc. This adds weak exports for the POSIX `dlopen`, `dlsym`, `dlclose`, and `dlerror` functions, allowing code which uses those features to compile. The implementations are stubs which always fail since there is currently no official standard for runtime dynamic linking. Since the symbols are weak, they can be overriden with useful, runtime-specific implementations, e.g. based on host functions or statically-generated tables (see https://github.com/dicej/component-linking-demo for an example of the latter). Signed-off-by: Joel Dice --- Makefile | 2 +- .../wasm32-wasi-threads/defined-symbols.txt | 4 +++ expected/wasm32-wasi-threads/include-all.c | 1 + .../wasm32-wasi-threads/predefined-macros.txt | 10 ++++++ expected/wasm32-wasi/defined-symbols.txt | 4 +++ expected/wasm32-wasi/include-all.c | 1 + expected/wasm32-wasi/predefined-macros.txt | 10 ++++++ libc-top-half/musl/src/misc/dl.c | 31 +++++++++++++++++++ 8 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 libc-top-half/musl/src/misc/dl.c diff --git a/Makefile b/Makefile index 548c5cace..82dd1cefa 100644 --- a/Makefile +++ b/Makefile @@ -90,6 +90,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \ misc/a64l.c \ misc/basename.c \ misc/dirname.c \ + misc/dl.c \ misc/ffs.c \ misc/ffsl.c \ misc/ffsll.c \ @@ -445,7 +446,6 @@ MUSL_OMIT_HEADERS += \ "netdb.h" \ "resolv.h" \ "pty.h" \ - "dlfcn.h" \ "setjmp.h" \ "ulimit.h" \ "sys/xattr.h" \ diff --git a/expected/wasm32-wasi-threads/defined-symbols.txt b/expected/wasm32-wasi-threads/defined-symbols.txt index c913f1620..d64d022ea 100644 --- a/expected/wasm32-wasi-threads/defined-symbols.txt +++ b/expected/wasm32-wasi-threads/defined-symbols.txt @@ -573,6 +573,10 @@ difftime dirfd dirname div +dlclose +dlerror +dlopen +dlsym dprintf drand48 drem diff --git a/expected/wasm32-wasi-threads/include-all.c b/expected/wasm32-wasi-threads/include-all.c index 0b43b07d2..28b592438 100644 --- a/expected/wasm32-wasi-threads/include-all.c +++ b/expected/wasm32-wasi-threads/include-all.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasi-threads/predefined-macros.txt b/expected/wasm32-wasi-threads/predefined-macros.txt index 820f84911..8461161fc 100644 --- a/expected/wasm32-wasi-threads/predefined-macros.txt +++ b/expected/wasm32-wasi-threads/predefined-macros.txt @@ -1499,6 +1499,15 @@ #define RRFIXEDSZ NS_RRFIXEDSZ #define RRQ 01 #define RS_HIPRI 0x01 +#define RTLD_DEFAULT ((void *)0) +#define RTLD_DI_LINKMAP 2 +#define RTLD_GLOBAL 256 +#define RTLD_LAZY 1 +#define RTLD_LOCAL 0 +#define RTLD_NEXT ((void *)-1) +#define RTLD_NODELETE 4096 +#define RTLD_NOLOAD 4 +#define RTLD_NOW 2 #define RUSAGE_CHILDREN 2 #define RUSAGE_SELF 1 #define R_OK (4) @@ -2044,6 +2053,7 @@ #define _Complex_I (0.0f+1.0fi) #define _DIRENT_H #define _DIRENT_HAVE_D_TYPE +#define _DLFCN_H #define _ENDIAN_H #define _ERRNO_H #define _ERR_H diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt index 6e743228b..a66d84472 100644 --- a/expected/wasm32-wasi/defined-symbols.txt +++ b/expected/wasm32-wasi/defined-symbols.txt @@ -509,6 +509,10 @@ difftime dirfd dirname div +dlclose +dlerror +dlopen +dlsym dprintf drand48 drem diff --git a/expected/wasm32-wasi/include-all.c b/expected/wasm32-wasi/include-all.c index 86297f3ef..297e48b14 100644 --- a/expected/wasm32-wasi/include-all.c +++ b/expected/wasm32-wasi/include-all.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt index 2f2ca8fdb..f75daa0a7 100644 --- a/expected/wasm32-wasi/predefined-macros.txt +++ b/expected/wasm32-wasi/predefined-macros.txt @@ -1467,6 +1467,15 @@ #define RRFIXEDSZ NS_RRFIXEDSZ #define RRQ 01 #define RS_HIPRI 0x01 +#define RTLD_DEFAULT ((void *)0) +#define RTLD_DI_LINKMAP 2 +#define RTLD_GLOBAL 256 +#define RTLD_LAZY 1 +#define RTLD_LOCAL 0 +#define RTLD_NEXT ((void *)-1) +#define RTLD_NODELETE 4096 +#define RTLD_NOLOAD 4 +#define RTLD_NOW 2 #define RUSAGE_CHILDREN 2 #define RUSAGE_SELF 1 #define R_OK (4) @@ -2010,6 +2019,7 @@ #define _Complex_I (0.0f+1.0fi) #define _DIRENT_H #define _DIRENT_HAVE_D_TYPE +#define _DLFCN_H #define _ENDIAN_H #define _ERRNO_H #define _ERR_H diff --git a/libc-top-half/musl/src/misc/dl.c b/libc-top-half/musl/src/misc/dl.c new file mode 100644 index 000000000..58164b90a --- /dev/null +++ b/libc-top-half/musl/src/misc/dl.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include + +#define EXPORT __attribute__((visibility("default"))) __attribute__((used)) +#define WEAK __attribute__((__weak__)) + +static const char *error = 0; + +EXPORT WEAK int dlclose(void *library) { + error = "dlclose not implemented"; + return -1; +} + +EXPORT WEAK char *dlerror(void) { + const char *var = error; + error = 0; + return (char*) var; +} + +EXPORT WEAK void *dlopen(const char *name, int flags) { + error = "dlopen not implemented"; + return 0; +} + +EXPORT WEAK void *dlsym(void *library, const char *name) { + error = "dlsym not implemented"; + return 0; +} From ff16bac4fd27457ce31a745322dc8668db5bc63f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 9 Nov 2023 11:28:06 -0700 Subject: [PATCH 2/5] move `dlopen` stubs out of libc and into libdl Per review feedback, it's easier to simply replace libdl.so with a working implementation at runtime than it is to override a handful of symbols in libc. Note that I've both added libdl.so and replaced the empty libdl.a we were previously creating with one that contains the stubs. I'm thinking we might as well be consistent about what symbols the .so and the .a contain. Otherwise, e.g. the CPython build gets confused when the dlfcn.h says `dlopen` etc. exist but libdl.a is empty. Signed-off-by: Joel Dice --- Makefile | 18 +++++-- .../wasm32-wasi-threads/defined-symbols.txt | 4 -- expected/wasm32-wasi/defined-symbols.txt | 4 -- libc-top-half/musl/src/misc/dl.c | 53 ++++++++++++------- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 82dd1cefa..276023942 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,7 @@ LIBWASI_EMULATED_SIGNAL_SOURCES = \ LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES = \ $(LIBC_TOP_HALF_MUSL_SRC_DIR)/signal/psignal.c \ $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/strsignal.c +LIBDL_SOURCES = $(LIBC_TOP_HALF_MUSL_SRC_DIR)/misc/dl.c LIBC_BOTTOM_HALF_CRT_SOURCES = $(wildcard $(LIBC_BOTTOM_HALF_DIR)/crt/*.c) LIBC_TOP_HALF_DIR = libc-top-half LIBC_TOP_HALF_MUSL_DIR = $(LIBC_TOP_HALF_DIR)/musl @@ -90,7 +91,6 @@ LIBC_TOP_HALF_MUSL_SOURCES = \ misc/a64l.c \ misc/basename.c \ misc/dirname.c \ - misc/dl.c \ misc/ffs.c \ misc/ffsl.c \ misc/ffsll.c \ @@ -380,6 +380,7 @@ LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS = $(call objs,$(LIBWASI_EMULATED_PROCESS_CL LIBWASI_EMULATED_GETPID_OBJS = $(call objs,$(LIBWASI_EMULATED_GETPID_SOURCES)) LIBWASI_EMULATED_SIGNAL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_SOURCES)) LIBWASI_EMULATED_SIGNAL_MUSL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES)) +LIBDL_OBJS = $(call objs,$(LIBDL_SOURCES)) LIBC_BOTTOM_HALF_CRT_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_CRT_SOURCES)) # These variables describe the locations of various files and @@ -481,6 +482,7 @@ LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULA LIBWASI_EMULATED_GETPID_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_GETPID_OBJS)) LIBWASI_EMULATED_SIGNAL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_SIGNAL_OBJS)) LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS)) +LIBDL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBDL_OBJS)) BULK_MEMORY_SO_OBJS = $(patsubst %.o,%.pic.o,$(BULK_MEMORY_OBJS)) DLMALLOC_SO_OBJS = $(patsubst %.o,%.pic.o,$(DLMALLOC_OBJS)) LIBC_BOTTOM_HALF_ALL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBC_BOTTOM_HALF_ALL_OBJS)) @@ -521,6 +523,8 @@ $(OBJDIR)/libwasi-emulated-getpid.so.a: $(LIBWASI_EMULATED_GETPID_SO_OBJS) $(OBJDIR)/libwasi-emulated-signal.so.a: $(LIBWASI_EMULATED_SIGNAL_SO_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS) +$(OBJDIR)/libdl.so.a: $(LIBDL_SO_OBJS) + $(SYSROOT_LIB)/libc.a: $(LIBC_OBJS) $(SYSROOT_LIB)/libc-printscan-long-double.a: $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) @@ -535,6 +539,8 @@ $(SYSROOT_LIB)/libwasi-emulated-getpid.a: $(LIBWASI_EMULATED_GETPID_OBJS) $(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS) +$(SYSROOT_LIB)/libdl.a: $(LIBDL_OBJS) + %.a: @mkdir -p "$(@D)" # On Windows, the commandline for the ar invocation got too long, so it needs to be split up. @@ -603,7 +609,7 @@ startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS) $(LIBC_BOTTOM_HALF_ALL_SO_OBJS): CFLA -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \ -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal -$(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): CFLAGS += \ +$(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): 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 \ @@ -664,7 +670,8 @@ LIBC_SO = \ $(SYSROOT_LIB)/libwasi-emulated-mman.so \ $(SYSROOT_LIB)/libwasi-emulated-process-clocks.so \ $(SYSROOT_LIB)/libwasi-emulated-getpid.so \ - $(SYSROOT_LIB)/libwasi-emulated-signal.so + $(SYSROOT_LIB)/libwasi-emulated-signal.so \ + $(SYSROOT_LIB)/libdl.so endif libc_so: include_dirs $(LIBC_SO) @@ -676,13 +683,14 @@ libc: include_dirs \ $(SYSROOT_LIB)/libwasi-emulated-mman.a \ $(SYSROOT_LIB)/libwasi-emulated-process-clocks.a \ $(SYSROOT_LIB)/libwasi-emulated-getpid.a \ - $(SYSROOT_LIB)/libwasi-emulated-signal.a + $(SYSROOT_LIB)/libwasi-emulated-signal.a \ + $(SYSROOT_LIB)/libdl.a finish: startup_files libc # # Create empty placeholder libraries. # - for name in m rt pthread crypt util xnet resolv dl; do \ + for name in m rt pthread crypt util xnet resolv; do \ $(AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \ done diff --git a/expected/wasm32-wasi-threads/defined-symbols.txt b/expected/wasm32-wasi-threads/defined-symbols.txt index d64d022ea..c913f1620 100644 --- a/expected/wasm32-wasi-threads/defined-symbols.txt +++ b/expected/wasm32-wasi-threads/defined-symbols.txt @@ -573,10 +573,6 @@ difftime dirfd dirname div -dlclose -dlerror -dlopen -dlsym dprintf drand48 drem diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt index a66d84472..6e743228b 100644 --- a/expected/wasm32-wasi/defined-symbols.txt +++ b/expected/wasm32-wasi/defined-symbols.txt @@ -509,10 +509,6 @@ difftime dirfd dirname div -dlclose -dlerror -dlopen -dlsym dprintf drand48 drem diff --git a/libc-top-half/musl/src/misc/dl.c b/libc-top-half/musl/src/misc/dl.c index 58164b90a..c80485ab2 100644 --- a/libc-top-half/musl/src/misc/dl.c +++ b/libc-top-half/musl/src/misc/dl.c @@ -1,31 +1,44 @@ -#include -#include -#include -#include -#include +/* This file is used to build libdl.so with stub versions of `dlopen`, `dlsym`, + * etc. The intention is that this stubbed libdl.so can be used to build + * libraries and applications which use `dlopen` without committing to a + * specific runtime implementation. Later, it can be replaced with a real, + * working libdl.so (e.g. at runtime or component composition time). + * + * For example, the `wasm-tools component link` subcommand can be used to create + * a component that bundles any `dlopen`-able libraries in such a way that their + * function exports can be resolved symbolically at runtime using an + * implementation of libdl.so designed for that purpose. In other cases, a + * runtime might provide Emscripten-style dynamic linking via URLs or else a + * more traditional, filesystem-based implementation. Finally, even this + * stubbed version of libdl.so can be used at runtime in cases where dynamic + * library resolution cannot or should not be supported (and the application can + * handle this situation gracefully). */ -#define EXPORT __attribute__((visibility("default"))) __attribute__((used)) -#define WEAK __attribute__((__weak__)) +#include static const char *error = 0; -EXPORT WEAK int dlclose(void *library) { - error = "dlclose not implemented"; - return -1; +weak int dlclose(void *library) +{ + error = "dlclose not implemented"; + return -1; } -EXPORT WEAK char *dlerror(void) { - const char *var = error; - error = 0; - return (char*) var; +weak char *dlerror(void) +{ + const char *var = error; + error = 0; + return (char*) var; } -EXPORT WEAK void *dlopen(const char *name, int flags) { - error = "dlopen not implemented"; - return 0; +weak void *dlopen(const char *name, int flags) +{ + error = "dlopen not implemented"; + return 0; } -EXPORT WEAK void *dlsym(void *library, const char *name) { - error = "dlsym not implemented"; - return 0; +weak void *dlsym(void *library, const char *name) +{ + error = "dlsym not implemented"; + return 0; } From 78629b736f031ee91763311626d4f808aef481b4 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 13 Nov 2023 08:20:11 -0700 Subject: [PATCH 3/5] customize dlfcn.h for WASI For WASI, we use flag values which match MacOS rather than musl. This gives `RTLD_LOCAL` a non-zero value, avoiding ambiguity and allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` should be the default when neither is specified. We also avoid declaring `dladdr`, `dlinfo`, and friends on WASI since they are neither supported nor stubbed at this time. Signed-off-by: Joel Dice --- .../wasm32-wasi-threads/predefined-macros.txt | 13 ++++++------- expected/wasm32-wasi/predefined-macros.txt | 13 ++++++------- libc-top-half/musl/include/dlfcn.h | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/expected/wasm32-wasi-threads/predefined-macros.txt b/expected/wasm32-wasi-threads/predefined-macros.txt index 8461161fc..02f5f06da 100644 --- a/expected/wasm32-wasi-threads/predefined-macros.txt +++ b/expected/wasm32-wasi-threads/predefined-macros.txt @@ -1500,14 +1500,13 @@ #define RRQ 01 #define RS_HIPRI 0x01 #define RTLD_DEFAULT ((void *)0) -#define RTLD_DI_LINKMAP 2 -#define RTLD_GLOBAL 256 -#define RTLD_LAZY 1 -#define RTLD_LOCAL 0 +#define RTLD_GLOBAL 0x8 +#define RTLD_LAZY 0x1 +#define RTLD_LOCAL 0x4 #define RTLD_NEXT ((void *)-1) -#define RTLD_NODELETE 4096 -#define RTLD_NOLOAD 4 -#define RTLD_NOW 2 +#define RTLD_NODELETE 0x80 +#define RTLD_NOLOAD 0x10 +#define RTLD_NOW 0x2 #define RUSAGE_CHILDREN 2 #define RUSAGE_SELF 1 #define R_OK (4) diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt index f75daa0a7..6fa25c0d8 100644 --- a/expected/wasm32-wasi/predefined-macros.txt +++ b/expected/wasm32-wasi/predefined-macros.txt @@ -1468,14 +1468,13 @@ #define RRQ 01 #define RS_HIPRI 0x01 #define RTLD_DEFAULT ((void *)0) -#define RTLD_DI_LINKMAP 2 -#define RTLD_GLOBAL 256 -#define RTLD_LAZY 1 -#define RTLD_LOCAL 0 +#define RTLD_GLOBAL 0x8 +#define RTLD_LAZY 0x1 +#define RTLD_LOCAL 0x4 #define RTLD_NEXT ((void *)-1) -#define RTLD_NODELETE 4096 -#define RTLD_NOLOAD 4 -#define RTLD_NOW 2 +#define RTLD_NODELETE 0x80 +#define RTLD_NOLOAD 0x10 +#define RTLD_NOW 0x2 #define RUSAGE_CHILDREN 2 #define RUSAGE_SELF 1 #define R_OK (4) diff --git a/libc-top-half/musl/include/dlfcn.h b/libc-top-half/musl/include/dlfcn.h index 13ab71dd0..879b3aaeb 100644 --- a/libc-top-half/musl/include/dlfcn.h +++ b/libc-top-half/musl/include/dlfcn.h @@ -7,24 +7,40 @@ extern "C" { #include +#ifdef __wasilibc_unmodified_upstream #define RTLD_LAZY 1 #define RTLD_NOW 2 #define RTLD_NOLOAD 4 #define RTLD_NODELETE 4096 #define RTLD_GLOBAL 256 #define RTLD_LOCAL 0 +#else +/* For WASI, we use flag values which match MacOS rather than musl. This gives + * `RTLD_LOCAL` a non-zero value, avoiding ambiguity and allowing us to defer + * the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` should be the default + * when neither is specified. + */ +#define RTLD_LAZY 0x1 +#define RTLD_NOW 0x2 +#define RTLD_LOCAL 0x4 +#define RTLD_GLOBAL 0x8 +#define RTLD_NOLOAD 0x10 +#define RTLD_NODELETE 0x80 +#endif #define RTLD_NEXT ((void *)-1) #define RTLD_DEFAULT ((void *)0) +#ifdef __wasilibc_unmodified_upstream #define RTLD_DI_LINKMAP 2 +#endif int dlclose(void *); char *dlerror(void); void *dlopen(const char *, int); void *dlsym(void *__restrict, const char *__restrict); -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) typedef struct { const char *dli_fname; void *dli_fbase; From 3e11e7bc8135cae13d0f7646c37d2a6dabdd238d Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 13 Nov 2023 09:14:56 -0700 Subject: [PATCH 4/5] use musl's RTLD_* flags except for RTLD_LOCAL This minimizes the divergence from upstream while still giving us the flexibility to choose a default value later. Signed-off-by: Joel Dice --- .../wasm32-wasi-threads/predefined-macros.txt | 12 ++++++------ expected/wasm32-wasi/predefined-macros.txt | 12 ++++++------ libc-top-half/musl/include/dlfcn.h | 16 +++++----------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/expected/wasm32-wasi-threads/predefined-macros.txt b/expected/wasm32-wasi-threads/predefined-macros.txt index 02f5f06da..e86ff4eb2 100644 --- a/expected/wasm32-wasi-threads/predefined-macros.txt +++ b/expected/wasm32-wasi-threads/predefined-macros.txt @@ -1500,13 +1500,13 @@ #define RRQ 01 #define RS_HIPRI 0x01 #define RTLD_DEFAULT ((void *)0) -#define RTLD_GLOBAL 0x8 -#define RTLD_LAZY 0x1 -#define RTLD_LOCAL 0x4 +#define RTLD_GLOBAL 256 +#define RTLD_LAZY 1 +#define RTLD_LOCAL 8 #define RTLD_NEXT ((void *)-1) -#define RTLD_NODELETE 0x80 -#define RTLD_NOLOAD 0x10 -#define RTLD_NOW 0x2 +#define RTLD_NODELETE 4096 +#define RTLD_NOLOAD 4 +#define RTLD_NOW 2 #define RUSAGE_CHILDREN 2 #define RUSAGE_SELF 1 #define R_OK (4) diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt index 6fa25c0d8..ff6029d2e 100644 --- a/expected/wasm32-wasi/predefined-macros.txt +++ b/expected/wasm32-wasi/predefined-macros.txt @@ -1468,13 +1468,13 @@ #define RRQ 01 #define RS_HIPRI 0x01 #define RTLD_DEFAULT ((void *)0) -#define RTLD_GLOBAL 0x8 -#define RTLD_LAZY 0x1 -#define RTLD_LOCAL 0x4 +#define RTLD_GLOBAL 256 +#define RTLD_LAZY 1 +#define RTLD_LOCAL 8 #define RTLD_NEXT ((void *)-1) -#define RTLD_NODELETE 0x80 -#define RTLD_NOLOAD 0x10 -#define RTLD_NOW 0x2 +#define RTLD_NODELETE 4096 +#define RTLD_NOLOAD 4 +#define RTLD_NOW 2 #define RUSAGE_CHILDREN 2 #define RUSAGE_SELF 1 #define R_OK (4) diff --git a/libc-top-half/musl/include/dlfcn.h b/libc-top-half/musl/include/dlfcn.h index 879b3aaeb..e802de88f 100644 --- a/libc-top-half/musl/include/dlfcn.h +++ b/libc-top-half/musl/include/dlfcn.h @@ -7,25 +7,19 @@ extern "C" { #include -#ifdef __wasilibc_unmodified_upstream #define RTLD_LAZY 1 #define RTLD_NOW 2 #define RTLD_NOLOAD 4 #define RTLD_NODELETE 4096 #define RTLD_GLOBAL 256 +#ifdef __wasilibc_unmodified_upstream #define RTLD_LOCAL 0 #else -/* For WASI, we use flag values which match MacOS rather than musl. This gives - * `RTLD_LOCAL` a non-zero value, avoiding ambiguity and allowing us to defer - * the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` should be the default - * when neither is specified. +/* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and + * allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` + * should be the default when neither is specified. */ -#define RTLD_LAZY 0x1 -#define RTLD_NOW 0x2 -#define RTLD_LOCAL 0x4 -#define RTLD_GLOBAL 0x8 -#define RTLD_NOLOAD 0x10 -#define RTLD_NODELETE 0x80 +#define RTLD_LOCAL 8 #endif #define RTLD_NEXT ((void *)-1) From b4b59f287fd6c36824e211e4454d5e7664fedef8 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 14 Nov 2023 11:35:26 -0700 Subject: [PATCH 5/5] use `NULL` instead of `0` for null pointers Signed-off-by: Joel Dice --- libc-top-half/musl/src/misc/dl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libc-top-half/musl/src/misc/dl.c b/libc-top-half/musl/src/misc/dl.c index c80485ab2..266594fd1 100644 --- a/libc-top-half/musl/src/misc/dl.c +++ b/libc-top-half/musl/src/misc/dl.c @@ -14,9 +14,10 @@ * library resolution cannot or should not be supported (and the application can * handle this situation gracefully). */ +#include #include -static const char *error = 0; +static const char *error = NULL; weak int dlclose(void *library) { @@ -27,18 +28,18 @@ weak int dlclose(void *library) weak char *dlerror(void) { const char *var = error; - error = 0; + error = NULL; return (char*) var; } weak void *dlopen(const char *name, int flags) { error = "dlopen not implemented"; - return 0; + return NULL; } weak void *dlsym(void *library, const char *name) { error = "dlsym not implemented"; - return 0; + return NULL; }