diff --git a/Makefile b/Makefile index 19145f7ea..c39ce84f7 100644 --- a/Makefile +++ b/Makefile @@ -475,6 +475,7 @@ endif endif endif +CFLAGS += -D_BUILDING_WASI_LIBC ifeq ($(WASI_SNAPSHOT), p2) CFLAGS += -D__wasilibc_use_wasip2 endif @@ -971,7 +972,7 @@ check-symbols: $(STARTUP_FILES) libc @# TODO: Undefine __wasm_nontrapping_fptoint__, __wasm_bulk_memory__ and @# __wasm_bulk_memory_opt__, that are new to clang 20. @# TODO: As of clang 16, __GNUC_VA_LIST is #defined without a value. - $(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \ + $(CC) $(CFLAGS) -U_BUILDING_WASI_LIBC "$(SYSROOT_SHARE)/include-all.c" \ -isystem $(SYSROOT_INC) \ -std=gnu17 \ -E -dM -Wno-\#warnings \ diff --git a/expected/wasm32-wasip1-threads/predefined-macros.txt b/expected/wasm32-wasip1-threads/predefined-macros.txt index f691c853a..093d6d73a 100644 --- a/expected/wasm32-wasip1-threads/predefined-macros.txt +++ b/expected/wasm32-wasip1-threads/predefined-macros.txt @@ -3255,7 +3255,7 @@ #define dirent64 dirent #define erf(x) __tg_real(erf, (x)) #define erfc(x) __tg_real(erfc, (x)) -#define errno errno +#define errno (*__errno_location()) #define exp(x) __tg_real_complex(exp, (x)) #define exp2(x) __tg_real(exp2, (x)) #define expm1(x) __tg_real(expm1, (x)) diff --git a/expected/wasm32-wasip1/predefined-macros.txt b/expected/wasm32-wasip1/predefined-macros.txt index 66f4c4c88..a91a454d5 100644 --- a/expected/wasm32-wasip1/predefined-macros.txt +++ b/expected/wasm32-wasip1/predefined-macros.txt @@ -3250,7 +3250,7 @@ #define dirent64 dirent #define erf(x) __tg_real(erf, (x)) #define erfc(x) __tg_real(erfc, (x)) -#define errno errno +#define errno (*__errno_location()) #define exp(x) __tg_real_complex(exp, (x)) #define exp2(x) __tg_real(exp2, (x)) #define expm1(x) __tg_real(expm1, (x)) diff --git a/expected/wasm32-wasip2/predefined-macros.txt b/expected/wasm32-wasip2/predefined-macros.txt index 1ae2e1fd2..99589ae5c 100644 --- a/expected/wasm32-wasip2/predefined-macros.txt +++ b/expected/wasm32-wasip2/predefined-macros.txt @@ -3403,7 +3403,7 @@ #define dirent64 dirent #define erf(x) __tg_real(erf, (x)) #define erfc(x) __tg_real(erfc, (x)) -#define errno errno +#define errno (*__errno_location()) #define exp(x) __tg_real_complex(exp, (x)) #define exp2(x) __tg_real(exp2, (x)) #define expm1(x) __tg_real(expm1, (x)) diff --git a/libc-bottom-half/headers/public/__errno.h b/libc-bottom-half/headers/public/__errno.h index 008245d97..6e1e91d3a 100644 --- a/libc-bottom-half/headers/public/__errno.h +++ b/libc-bottom-half/headers/public/__errno.h @@ -5,9 +5,15 @@ extern "C" { #endif +#ifdef _BUILDING_WASI_LIBC +/* libc internal access */ extern _Thread_local int errno; - #define errno errno +#else +/* user exposed ABI */ +__attribute__((__const__)) int *__errno_location(void); +#define errno (*__errno_location()) +#endif #ifdef __cplusplus }