]> git.proxmox.com Git - wasi-libc.git/commitdiff
Use MUSL's `weak*` feature in bottom half (#306)
authorAndrew Brown <andrew.brown@intel.com>
Tue, 26 Jul 2022 21:15:12 +0000 (14:15 -0700)
committerGitHub <noreply@github.com>
Tue, 26 Jul 2022 21:15:12 +0000 (14:15 -0700)
This change extracts the `weak*`-related parts of #303 as a separate PR.
Note that this is slightly strange in that it uses some top-half MUSL
headers in the bottom-half code, but discussion around this led me to
believe that the advantages of, e.g., `LOCK` made this worthwhile.
Beyond just changing uses of `weak` to `__weak__`, we also MUSL's `weak`
and `weak_alias` macros in a few more places.

Makefile
libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c
libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c
libc-bottom-half/headers/public/wasi/libc-find-relpath.h
libc-bottom-half/sources/__main_void.c
libc-bottom-half/sources/__wasilibc_initialize_environ.c
libc-bottom-half/sources/environ.c
libc-bottom-half/sources/getentropy.c

index 6eaf094790157b12029f842d558241b66317062c..26a4ae5a821b002d46ed719a5fddd7016fa711c3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -428,7 +428,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 \
index dbb36a72da216fb63d4f1465874e5a358b3b299f..c7e1a609e7b21c6fbd8b0544e6fcc660261f1898 100644 (file)
@@ -19,4 +19,4 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) {
   *tp = timestamp_to_timespec(ts);
   return 0;
 }
-extern __typeof(__clock_gettime) clock_gettime __attribute__((weak, alias("__clock_gettime")));
+weak_alias(__clock_gettime, clock_gettime);
index 0dfc49e4c9cebc2c2aa76bc70a43c5d18a1dbf58..3e0429f10f7cad6cc9dd1e43dee40386b0576374 100644 (file)
@@ -22,4 +22,4 @@ off_t __lseek(int fildes, off_t offset, int whence) {
   return new_offset;
 }
 
-extern __typeof(__lseek) lseek __attribute__((weak, alias("__lseek")));
+weak_alias(__lseek, lseek);
index 445613f5aaefd82076616f0f2d7b90e88ec203ea..32dbb03510761b9b2c1de2123039ca3450c2ef14 100644 (file)
@@ -70,7 +70,7 @@ int __wasilibc_find_relpath_alloc(
     char **relative,
     size_t *relative_len,
     int can_realloc
-) __attribute__((weak));
+) __attribute__((__weak__));
 
 #ifdef __cplusplus
 }
index 6be5c1e6a1a56dd80d9d611fec6cec7be03b07c9..cba22efa03a4161dc192d4459d14789b3ead8269 100644 (file)
@@ -8,7 +8,7 @@ int __main_argc_argv(int argc, char *argv[]);
 // If the user's `main` function expects arguments, the compiler will rename
 // it to `__main_argc_argv`, and this version will get linked in, which
 // initializes the argument data and calls `__main_argc_argv`.
-__attribute__((weak, nodebug))
+__attribute__((__weak__, nodebug))
 int __main_void(void) {
     __wasi_errno_t err;
 
index 4ec4d30a6fa71182c2030d1ded134b55e2239f5c..4a8bb1a3e824eeb78936e1bd8e260205aa1ab3d2 100644 (file)
@@ -11,7 +11,7 @@
 /// Statically-initialize it to an invalid pointer value so that we can
 /// detect if it's been explicitly initialized (we can't use `NULL` because
 /// `clearenv` sets it to NULL.
-char **__wasilibc_environ __attribute__((weak)) = (char **)-1;
+char **__wasilibc_environ weak = (char **)-1;
 
 // See the comments in libc-environ.h.
 void __wasilibc_ensure_environ(void) {
@@ -87,7 +87,7 @@ void __wasilibc_deinitialize_environ(void) {
 }
 
 // See the comments in libc-environ.h.
-__attribute__((weak))
+weak
 void __wasilibc_maybe_reinitialize_environ_eagerly(void) {
     // This version does nothing. It may be overridden by a version which does
     // something if `environ` is used.
index 94d82ee9d66f6cb54fadb299cc7fc9f77add7d14..50d60deff407fcf929303933ac95daef3783bb00 100644 (file)
@@ -9,10 +9,8 @@
 // `__wasilibc_environ`, which is initialized with a constructor function, so
 // that it's initialized whenever user code might want to access it.
 char **__wasilibc_environ;
-extern __typeof(__wasilibc_environ) _environ
-    __attribute__((weak, alias("__wasilibc_environ")));
-extern __typeof(__wasilibc_environ) environ
-    __attribute__((weak, alias("__wasilibc_environ")));
+weak_alias(__wasilibc_environ, _environ);
+weak_alias(__wasilibc_environ, environ);
 
 // We define this function here in the same source file as
 // `__wasilibc_environ`, so that this function is called in iff environment
index 7f96b85e1f67dced02bf7fa90fd22f1fd97c6a19..1771941a31b91b4c7da7a6aad535a635153faad0 100644 (file)
@@ -21,4 +21,4 @@ int __getentropy(void *buffer, size_t len) {
 
     return 0;
 }
-extern __typeof(__getentropy) getentropy __attribute__((weak, alias("__getentropy")));
+weak_alias(__getentropy, getentropy);