From 4ba250067132f0b26a389d12cd23abb7028c2a0e Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 7 Dec 2020 13:16:13 +0100 Subject: [PATCH 1/7] Revise `alltypes.h` update process. NFC Align it with musl, i.e. only update `alltypes.h.in` and regenerate `alltypes.h` using a script. --- .../libc/musl/arch/emscripten/bits/alltypes.h | 209 +++++++++++++----- .../musl/arch/emscripten/bits/alltypes.h.in | 55 ++++- .../arch/emscripten/bits/update_alltypes.sh | 7 + system/lib/libc/musl/tools/mkalltypes.sed | 15 ++ 4 files changed, 215 insertions(+), 71 deletions(-) create mode 100755 system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh create mode 100644 system/lib/libc/musl/tools/mkalltypes.sed diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index 148baddd8fd7b..4f97405cd7662 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -1,16 +1,14 @@ -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __USE_TIME_BITS64 1 - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#define __LONG_MAX __LONG_MAX__ - +/* + * The .h version of this file is generated from the .h.in. + * See update_alltypes.sh. + */ #define _Addr __PTRDIFF_TYPE__ #define _Int64 __INT64_TYPE__ #define _Reg __PTRDIFF_TYPE__ -#if __GNUC__ >= 3 +#define __BYTE_ORDER 1234 +#define __LONG_MAX __LONG_MAX__ + #if defined(__NEED_va_list) && !defined(__DEFINED_va_list) typedef __builtin_va_list va_list; #define __DEFINED_va_list @@ -21,18 +19,6 @@ typedef __builtin_va_list __isoc_va_list; #define __DEFINED___isoc_va_list #endif -#else -#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) -typedef struct __va_list * va_list; -#define __DEFINED_va_list -#endif - -#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) -typedef struct __va_list * __isoc_va_list; -#define __DEFINED___isoc_va_list -#endif - -#endif #ifndef __cplusplus #ifdef __WCHAR_TYPE__ @@ -43,7 +29,7 @@ typedef __WCHAR_TYPE__ wchar_t; #else #if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) -typedef int wchar_t; +typedef long wchar_t; #define __DEFINED_wchar_t #endif @@ -55,6 +41,48 @@ typedef __WINT_TYPE__ wint_t; #endif +// XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 +#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) +typedef int blkcnt_t; +#define __DEFINED_blkcnt_t +#endif + +#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) +typedef int blksize_t; +#define __DEFINED_blksize_t +#endif + +#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) +typedef int clock_t; +#define __DEFINED_clock_t +#endif + +#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) +typedef unsigned int dev_t; +#define __DEFINED_dev_t +#endif + +#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) +typedef unsigned int fsblkcnt_t; +#define __DEFINED_fsblkcnt_t +#endif + +#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) +typedef int suseconds_t; +#define __DEFINED_suseconds_t +#endif + +#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) +typedef unsigned int fsfilcnt_t; +#define __DEFINED_fsfilcnt_t +#endif + +#if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) +typedef unsigned int wctype_t; +#define __DEFINED_wctype_t +#endif + + #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 0 #if defined(__NEED_float_t) && !defined(__DEFINED_float_t) typedef float float_t; @@ -79,40 +107,40 @@ typedef long double double_t; #endif -#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) -typedef _Int64 time_t; -#define __DEFINED_time_t +#ifndef __cplusplus +#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) +typedef struct { _Alignas(8) long long __ll; long double __ld; } max_align_t; +#define __DEFINED_max_align_t #endif -#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) -typedef int suseconds_t; /* XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 */ -#define __DEFINED_suseconds_t +#elif defined(__GNUC__) +#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) +typedef struct { __attribute__((__aligned__(8))) long long __ll; long double __ld; } max_align_t; +#define __DEFINED_max_align_t #endif +#else +#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) +typedef struct { alignas(8) long long __ll; long double __ld; } max_align_t; +#define __DEFINED_max_align_t +#endif +#endif + +// For canvas transfer implementation in Emscripten, use an extra control field +// to pass a pointer to a string denoting the WebGL canvases to transfer. #if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) -typedef struct { - union { - int __i[10]; - volatile int __vi[10]; - unsigned long __s[10]; - } __u; -#ifdef __EMSCRIPTEN__ - // For canvas transfer implementation in Emscripten, use an extra control field - // to pass a pointer to a string denoting the WebGL canvases to transfer. - const char *_a_transferredcanvases; -#endif -} pthread_attr_t; +typedef struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[10]; } __u; const char *_a_transferredcanvases; } pthread_attr_t; #define __DEFINED_pthread_attr_t #endif #if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) -typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *__p[6]; } __u; } pthread_mutex_t; +typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; #define __DEFINED_pthread_mutex_t #endif #if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) -typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *__p[6]; } __u; } mtx_t; +typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t; #define __DEFINED_mtx_t #endif @@ -127,7 +155,7 @@ typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __ #endif #if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) -typedef struct { union { int __i[sizeof(long)==8?14:8]; volatile int __vi[sizeof(long)==8?14:8]; void *__p[sizeof(long)==8?7:8]; } __u; } pthread_rwlock_t; +typedef struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t; #define __DEFINED_pthread_rwlock_t #endif @@ -136,6 +164,9 @@ typedef struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; #define __DEFINED_pthread_barrier_t #endif +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __USE_TIME_BITS64 1 #if defined(__NEED_size_t) && !defined(__DEFINED_size_t) typedef unsigned _Addr size_t; @@ -172,6 +203,16 @@ typedef _Reg register_t; #define __DEFINED_register_t #endif +#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) +typedef _Int64 time_t; +#define __DEFINED_time_t +#endif + +#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) +typedef _Int64 suseconds_t; +#define __DEFINED_suseconds_t +#endif + #if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) typedef signed char int8_t; @@ -179,22 +220,22 @@ typedef signed char int8_t; #endif #if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) -typedef short int16_t; +typedef signed short int16_t; #define __DEFINED_int16_t #endif #if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) -typedef int int32_t; +typedef signed int int32_t; #define __DEFINED_int32_t #endif #if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) -typedef _Int64 int64_t; +typedef signed _Int64 int64_t; #define __DEFINED_int64_t #endif #if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) -typedef _Int64 intmax_t; +typedef signed _Int64 intmax_t; #define __DEFINED_intmax_t #endif @@ -250,37 +291,38 @@ typedef unsigned _Int64 ino_t; #endif #if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) -typedef unsigned int dev_t; +typedef unsigned _Int64 dev_t; #define __DEFINED_dev_t #endif #if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) -typedef int blksize_t; /* XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 */ +typedef long blksize_t; #define __DEFINED_blksize_t #endif #if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) -typedef int blkcnt_t; +typedef _Int64 blkcnt_t; #define __DEFINED_blkcnt_t #endif #if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) -typedef unsigned int fsblkcnt_t; +typedef unsigned _Int64 fsblkcnt_t; #define __DEFINED_fsblkcnt_t #endif #if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) -typedef unsigned int fsfilcnt_t; +typedef unsigned _Int64 fsfilcnt_t; #define __DEFINED_fsfilcnt_t #endif + #if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) typedef unsigned wint_t; #define __DEFINED_wint_t #endif #if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) -typedef unsigned int wctype_t; /* XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 */ +typedef unsigned long wctype_t; #define __DEFINED_wctype_t #endif @@ -296,22 +338,17 @@ typedef int clockid_t; #endif #if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) -typedef int clock_t; /* XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 */ +typedef long clock_t; #define __DEFINED_clock_t #endif -#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) -typedef struct { long long __ll; long double __ld; } max_align_t; -#define __DEFINED_max_align_t -#endif - #if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) struct timeval { time_t tv_sec; suseconds_t tv_usec; }; #define __DEFINED_struct_timeval #endif #if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) -struct timespec { time_t tv_sec; long tv_nsec; }; +struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; #define __DEFINED_struct_timespec #endif @@ -396,12 +433,28 @@ typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; #endif +#if defined(__NEED_struct__IO_FILE) && !defined(__DEFINED_struct__IO_FILE) +struct _IO_FILE { char __x; }; +#define __DEFINED_struct__IO_FILE +#endif + #if defined(__NEED_FILE) && !defined(__DEFINED_FILE) typedef struct _IO_FILE FILE; #define __DEFINED_FILE #endif +#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) +typedef __builtin_va_list va_list; +#define __DEFINED_va_list +#endif + +#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) +typedef __builtin_va_list __isoc_va_list; +#define __DEFINED___isoc_va_list +#endif + + #if defined(__NEED_mbstate_t) && !defined(__DEFINED_mbstate_t) typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; #define __DEFINED_mbstate_t @@ -443,6 +496,42 @@ typedef unsigned short sa_family_t; #endif +#if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) +typedef struct { union { int __i[sizeof(long)==8?14:9]; volatile int __vi[sizeof(long)==8?14:9]; unsigned long __s[sizeof(long)==8?7:9]; } __u; } pthread_attr_t; +#define __DEFINED_pthread_attr_t +#endif + +#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) +typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } pthread_mutex_t; +#define __DEFINED_pthread_mutex_t +#endif + +#if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) +typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } mtx_t; +#define __DEFINED_mtx_t +#endif + +#if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) +typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } pthread_cond_t; +#define __DEFINED_pthread_cond_t +#endif + +#if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) +typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } cnd_t; +#define __DEFINED_cnd_t +#endif + +#if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) +typedef struct { union { int __i[sizeof(long)==8?14:8]; volatile int __vi[sizeof(long)==8?14:8]; void *__p[sizeof(long)==8?7:8]; } __u; } pthread_rwlock_t; +#define __DEFINED_pthread_rwlock_t +#endif + +#if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) +typedef struct { union { int __i[sizeof(long)==8?8:5]; volatile int __vi[sizeof(long)==8?8:5]; void *__p[sizeof(long)==8?4:5]; } __u; } pthread_barrier_t; +#define __DEFINED_pthread_barrier_t +#endif + + #undef _Addr #undef _Int64 #undef _Reg diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index fc922d01f4ac4..a1919a0b91ef6 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -1,25 +1,58 @@ +/* + * The .h version of this file is generated from the .h.in. + * See update_alltypes.sh. + */ #define _Addr __PTRDIFF_TYPE__ #define _Int64 __INT64_TYPE__ #define _Reg __PTRDIFF_TYPE__ +#define __BYTE_ORDER 1234 +#define __LONG_MAX __LONG_MAX__ + TYPEDEF __builtin_va_list va_list; TYPEDEF __builtin_va_list __isoc_va_list; #ifndef __cplusplus -TYPEDEF unsigned wchar_t; +#ifdef __WCHAR_TYPE__ +TYPEDEF __WCHAR_TYPE__ wchar_t; +#else +TYPEDEF long wchar_t; +#endif #endif -TYPEDEF unsigned wint_t; +TYPEDEF __WINT_TYPE__ wint_t; +// XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 +TYPEDEF int blkcnt_t; +TYPEDEF int blksize_t; +TYPEDEF int clock_t; +TYPEDEF unsigned int dev_t; +TYPEDEF unsigned int fsblkcnt_t; +TYPEDEF int suseconds_t; +TYPEDEF unsigned int fsfilcnt_t; +TYPEDEF unsigned int wctype_t; + +#if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 0 TYPEDEF float float_t; TYPEDEF double double_t; +#else +TYPEDEF long double float_t; +TYPEDEF long double double_t; +#endif -TYPEDEF struct { long long __ll; long double __ld; } max_align_t; -TYPEDEF long time_t; -TYPEDEF long suseconds_t; - -TYPEDEF struct { union { int __i[10]; unsigned __s[10]; } __u; } pthread_attr_t; -TYPEDEF struct { union { int __i[7]; void *__p[7]; } __u; } pthread_mutex_t; -TYPEDEF struct { union { int __i[12]; void *__p[12]; } __u; } pthread_cond_t; -TYPEDEF struct { union { int __i[8]; void *__p[8]; } __u; } pthread_rwlock_t; -TYPEDEF struct { union { int __i[5]; void *__p[5]; } __u; } pthread_barrier_t; +#ifndef __cplusplus +TYPEDEF struct { _Alignas(8) long long __ll; long double __ld; } max_align_t; +#elif defined(__GNUC__) +TYPEDEF struct { __attribute__((__aligned__(8))) long long __ll; long double __ld; } max_align_t; +#else +TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t; +#endif +// For canvas transfer implementation in Emscripten, use an extra control field +// to pass a pointer to a string denoting the WebGL canvases to transfer. +TYPEDEF struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[10]; } __u; const char *_a_transferredcanvases; } pthread_attr_t; +TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; +TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t; +TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } pthread_cond_t; +TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } cnd_t; +TYPEDEF struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t; +TYPEDEF struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t; diff --git a/system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh b/system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh new file mode 100755 index 0000000000000..94dc15e227584 --- /dev/null +++ b/system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# This script updates alltypes.h based on the contents of alltypes.h.in. +# In upstream this must be done by the top level Makefile. + +musl_srcdir="$PWD/../../.." +musl_includedir="$musl_srcdir/include" +sed -f $musl_srcdir/tools/mkalltypes.sed ./alltypes.h.in $musl_includedir/alltypes.h.in > alltypes.h diff --git a/system/lib/libc/musl/tools/mkalltypes.sed b/system/lib/libc/musl/tools/mkalltypes.sed new file mode 100644 index 0000000000000..fa15efc35f64e --- /dev/null +++ b/system/lib/libc/musl/tools/mkalltypes.sed @@ -0,0 +1,15 @@ +/^TYPEDEF/s/TYPEDEF \(.*\) \([^ ]*\);$/#if defined(__NEED_\2) \&\& !defined(__DEFINED_\2)\ +typedef \1 \2;\ +#define __DEFINED_\2\ +#endif\ +/ +/^STRUCT/s/STRUCT * \([^ ]*\) \(.*\);$/#if defined(__NEED_struct_\1) \&\& !defined(__DEFINED_struct_\1)\ +struct \1 \2;\ +#define __DEFINED_struct_\1\ +#endif\ +/ +/^UNION/s/UNION * \([^ ]*\) \(.*\);$/#if defined(__NEED_union_\1) \&\& !defined(__DEFINED_union_\1)\ +union \1 \2;\ +#define __DEFINED_union_\1\ +#endif\ +/ From 4bb13baaf45ae6663b3df26dd0ff0e5a89fabfdd Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sat, 12 Dec 2020 19:38:46 +0100 Subject: [PATCH 2/7] Deduplicate arch/emscripten/bits/alltypes.h{,in} with include/libc/alltypes.h.in --- .../libc/musl/arch/emscripten/bits/alltypes.h | 41 ------------------- .../musl/arch/emscripten/bits/alltypes.h.in | 9 ---- 2 files changed, 50 deletions(-) diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index 4f97405cd7662..dbd8ccf7166a8 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -9,17 +9,6 @@ #define __BYTE_ORDER 1234 #define __LONG_MAX __LONG_MAX__ -#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) -typedef __builtin_va_list va_list; -#define __DEFINED_va_list -#endif - -#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) -typedef __builtin_va_list __isoc_va_list; -#define __DEFINED___isoc_va_list -#endif - - #ifndef __cplusplus #ifdef __WCHAR_TYPE__ #if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) @@ -134,36 +123,6 @@ typedef struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[1 #define __DEFINED_pthread_attr_t #endif -#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) -typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; -#define __DEFINED_pthread_mutex_t -#endif - -#if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) -typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t; -#define __DEFINED_mtx_t -#endif - -#if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) -typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } pthread_cond_t; -#define __DEFINED_pthread_cond_t -#endif - -#if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) -typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } cnd_t; -#define __DEFINED_cnd_t -#endif - -#if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) -typedef struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t; -#define __DEFINED_pthread_rwlock_t -#endif - -#if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) -typedef struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t; -#define __DEFINED_pthread_barrier_t -#endif - #define __LITTLE_ENDIAN 1234 #define __BIG_ENDIAN 4321 #define __USE_TIME_BITS64 1 diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index a1919a0b91ef6..0bb70769c8e07 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -9,9 +9,6 @@ #define __BYTE_ORDER 1234 #define __LONG_MAX __LONG_MAX__ -TYPEDEF __builtin_va_list va_list; -TYPEDEF __builtin_va_list __isoc_va_list; - #ifndef __cplusplus #ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; @@ -50,9 +47,3 @@ TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t; // For canvas transfer implementation in Emscripten, use an extra control field // to pass a pointer to a string denoting the WebGL canvases to transfer. TYPEDEF struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[10]; } __u; const char *_a_transferredcanvases; } pthread_attr_t; -TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; -TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t; -TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } pthread_cond_t; -TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } cnd_t; -TYPEDEF struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t; -TYPEDEF struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t; From 4a3bcba4f30a9f3687ec15f561a78722ce2f806b Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 23 Jul 2025 18:57:51 +0200 Subject: [PATCH 3/7] Incorporate feedback --- .../libc/musl/arch/emscripten/bits/alltypes.h | 23 ------------------- .../musl/arch/emscripten/bits/alltypes.h.in | 11 --------- .../arch/emscripten/bits/update_alltypes.sh | 7 ------ system/lib/libc/update_alltypes.sh | 10 ++++++++ 4 files changed, 10 insertions(+), 41 deletions(-) delete mode 100755 system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh create mode 100755 system/lib/libc/update_alltypes.sh diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index dbd8ccf7166a8..111ff93a144a2 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -9,21 +9,11 @@ #define __BYTE_ORDER 1234 #define __LONG_MAX __LONG_MAX__ -#ifndef __cplusplus -#ifdef __WCHAR_TYPE__ #if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) typedef __WCHAR_TYPE__ wchar_t; #define __DEFINED_wchar_t #endif -#else -#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) -typedef long wchar_t; -#define __DEFINED_wchar_t -#endif - -#endif -#endif #if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) typedef __WINT_TYPE__ wint_t; #define __DEFINED_wint_t @@ -72,7 +62,6 @@ typedef unsigned int wctype_t; #endif -#if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 0 #if defined(__NEED_float_t) && !defined(__DEFINED_float_t) typedef float float_t; #define __DEFINED_float_t @@ -83,18 +72,6 @@ typedef double double_t; #define __DEFINED_double_t #endif -#else -#if defined(__NEED_float_t) && !defined(__DEFINED_float_t) -typedef long double float_t; -#define __DEFINED_float_t -#endif - -#if defined(__NEED_double_t) && !defined(__DEFINED_double_t) -typedef long double double_t; -#define __DEFINED_double_t -#endif - -#endif #ifndef __cplusplus #if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index 0bb70769c8e07..07699f3458b4e 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -9,13 +9,7 @@ #define __BYTE_ORDER 1234 #define __LONG_MAX __LONG_MAX__ -#ifndef __cplusplus -#ifdef __WCHAR_TYPE__ TYPEDEF __WCHAR_TYPE__ wchar_t; -#else -TYPEDEF long wchar_t; -#endif -#endif TYPEDEF __WINT_TYPE__ wint_t; // XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 @@ -28,13 +22,8 @@ TYPEDEF int suseconds_t; TYPEDEF unsigned int fsfilcnt_t; TYPEDEF unsigned int wctype_t; -#if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 0 TYPEDEF float float_t; TYPEDEF double double_t; -#else -TYPEDEF long double float_t; -TYPEDEF long double double_t; -#endif #ifndef __cplusplus TYPEDEF struct { _Alignas(8) long long __ll; long double __ld; } max_align_t; diff --git a/system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh b/system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh deleted file mode 100755 index 94dc15e227584..0000000000000 --- a/system/lib/libc/musl/arch/emscripten/bits/update_alltypes.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -# This script updates alltypes.h based on the contents of alltypes.h.in. -# In upstream this must be done by the top level Makefile. - -musl_srcdir="$PWD/../../.." -musl_includedir="$musl_srcdir/include" -sed -f $musl_srcdir/tools/mkalltypes.sed ./alltypes.h.in $musl_includedir/alltypes.h.in > alltypes.h diff --git a/system/lib/libc/update_alltypes.sh b/system/lib/libc/update_alltypes.sh new file mode 100755 index 0000000000000..5892c9815554e --- /dev/null +++ b/system/lib/libc/update_alltypes.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# This script updates alltypes.h based on the contents of alltypes.h.in. +# In upstream this must be done by the top level Makefile. + +musl_srcdir="$PWD/musl" +musl_includedir="$musl_srcdir/include" +emscripten_dir="$musl_srcdir/arch/emscripten/bits" +sed -f $musl_srcdir/tools/mkalltypes.sed \ + $emscripten_dir/alltypes.h.in \ + $musl_includedir/alltypes.h.in > $emscripten_dir/alltypes.h From ecefbbd9f320468ad3d9525053e1f804ae0d698f Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Wed, 23 Jul 2025 19:25:26 +0200 Subject: [PATCH 4/7] Reinstate `__cplusplus` conditional --- system/lib/libc/musl/arch/emscripten/bits/alltypes.h | 2 ++ system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in | 2 ++ 2 files changed, 4 insertions(+) diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index 111ff93a144a2..c921fd3813868 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -9,11 +9,13 @@ #define __BYTE_ORDER 1234 #define __LONG_MAX __LONG_MAX__ +#ifndef __cplusplus #if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) typedef __WCHAR_TYPE__ wchar_t; #define __DEFINED_wchar_t #endif +#endif #if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) typedef __WINT_TYPE__ wint_t; #define __DEFINED_wint_t diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index 07699f3458b4e..31dff188c3e52 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -9,7 +9,9 @@ #define __BYTE_ORDER 1234 #define __LONG_MAX __LONG_MAX__ +#ifndef __cplusplus TYPEDEF __WCHAR_TYPE__ wchar_t; +#endif TYPEDEF __WINT_TYPE__ wint_t; // XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64 From 82662c012e8afad06fc1660124d7e91755676286 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 24 Jul 2025 10:27:03 +0200 Subject: [PATCH 5/7] Update after af67939 --- system/lib/libc/musl/arch/emscripten/bits/alltypes.h | 10 ---------- .../lib/libc/musl/arch/emscripten/bits/alltypes.h.in | 2 -- 2 files changed, 12 deletions(-) diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index c921fd3813868..da46d1bc91353 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -43,21 +43,11 @@ typedef unsigned int dev_t; #define __DEFINED_dev_t #endif -#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) -typedef unsigned int fsblkcnt_t; -#define __DEFINED_fsblkcnt_t -#endif - #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) typedef int suseconds_t; #define __DEFINED_suseconds_t #endif -#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) -typedef unsigned int fsfilcnt_t; -#define __DEFINED_fsfilcnt_t -#endif - #if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) typedef unsigned int wctype_t; #define __DEFINED_wctype_t diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index 31dff188c3e52..244957a52016c 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -19,9 +19,7 @@ TYPEDEF int blkcnt_t; TYPEDEF int blksize_t; TYPEDEF int clock_t; TYPEDEF unsigned int dev_t; -TYPEDEF unsigned int fsblkcnt_t; TYPEDEF int suseconds_t; -TYPEDEF unsigned int fsfilcnt_t; TYPEDEF unsigned int wctype_t; TYPEDEF float float_t; From 6809780098d3ea573fd59413a12b52daa61b14b9 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 25 Jul 2025 13:48:51 +0200 Subject: [PATCH 6/7] Ensure byte-for-byte identical `libc-mt.a` --- system/lib/libc/musl/arch/emscripten/bits/alltypes.h | 12 ++++++++++++ .../lib/libc/musl/arch/emscripten/bits/alltypes.h.in | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index da46d1bc91353..af53539b0d3e1 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -92,6 +92,18 @@ typedef struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[1 #define __DEFINED_pthread_attr_t #endif + +// TODO(kleisauke): Remove these two typedefs. +#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) +typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*volatile*/__p[6]; } __u; } pthread_mutex_t; +#define __DEFINED_pthread_mutex_t +#endif + +#if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) +typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*volatile*/__p[6]; } __u; } mtx_t; +#define __DEFINED_mtx_t +#endif + #define __LITTLE_ENDIAN 1234 #define __BIG_ENDIAN 4321 #define __USE_TIME_BITS64 1 diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index 244957a52016c..52f40dc72c89a 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -36,3 +36,7 @@ TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t; // For canvas transfer implementation in Emscripten, use an extra control field // to pass a pointer to a string denoting the WebGL canvases to transfer. TYPEDEF struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[10]; } __u; const char *_a_transferredcanvases; } pthread_attr_t; + +// TODO(kleisauke): Remove these two typedefs. +TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*volatile*/__p[6]; } __u; } pthread_mutex_t; +TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*volatile*/__p[6]; } __u; } mtx_t; From 4eba06a1ccdde7c579a666a4ee7bbb7d60d9aee8 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 25 Jul 2025 18:24:25 +0200 Subject: [PATCH 7/7] Incorporate feedback --- system/lib/libc/musl/arch/emscripten/bits/alltypes.h | 5 +++++ system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index af53539b0d3e1..83b834246fbf0 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -104,6 +104,11 @@ typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*vol #define __DEFINED_mtx_t #endif + +// END EMSCRIPTEN-SPECIFIC DEFINITIONS +// +// Below here are the shared musl definitions. The emscripten-specific definitions above will take precedence +// due to the `__DEFINED_` macro system. #define __LITTLE_ENDIAN 1234 #define __BIG_ENDIAN 4321 #define __USE_TIME_BITS64 1 diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in index 52f40dc72c89a..5eced059b4372 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in @@ -40,3 +40,8 @@ TYPEDEF struct { union { int __i[10]; volatile int __vi[10]; unsigned long __s[1 // TODO(kleisauke): Remove these two typedefs. TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*volatile*/__p[6]; } __u; } pthread_mutex_t; TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void * /*volatile*/__p[6]; } __u; } mtx_t; + +// END EMSCRIPTEN-SPECIFIC DEFINITIONS +// +// Below here are the shared musl definitions. The emscripten-specific definitions above will take precedence +// due to the `__DEFINED_` macro system.