diff --git a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h index 3599062069ac0..83b834246fbf0 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/alltypes.h +++ b/system/lib/libc/musl/arch/emscripten/bits/alltypes.h @@ -1,61 +1,59 @@ -#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 -#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) -typedef __builtin_va_list va_list; -#define __DEFINED_va_list -#endif +#define __BYTE_ORDER 1234 +#define __LONG_MAX __LONG_MAX__ -#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) -typedef __builtin_va_list __isoc_va_list; -#define __DEFINED___isoc_va_list +#ifndef __cplusplus +#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) +typedef __WCHAR_TYPE__ wchar_t; +#define __DEFINED_wchar_t #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 +#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) +typedef __WINT_TYPE__ wint_t; +#define __DEFINED_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 -#ifndef __cplusplus -#ifdef __WCHAR_TYPE__ -#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) -typedef __WCHAR_TYPE__ wchar_t; -#define __DEFINED_wchar_t +#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) +typedef int blksize_t; +#define __DEFINED_blksize_t #endif -#else -#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) -typedef int wchar_t; -#define __DEFINED_wchar_t +#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_suseconds_t) && !defined(__DEFINED_suseconds_t) +typedef int suseconds_t; +#define __DEFINED_suseconds_t #endif -#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) -typedef __WINT_TYPE__ wint_t; -#define __DEFINED_wint_t + +#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; #define __DEFINED_float_t @@ -66,76 +64,54 @@ 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 +#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 +#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 -#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) -typedef _Int64 time_t; -#define __DEFINED_time_t +#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 -#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 #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 + +// 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 *__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 -#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[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[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t; -#define __DEFINED_pthread_barrier_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 #if defined(__NEED_size_t) && !defined(__DEFINED_size_t) typedef unsigned _Addr size_t; @@ -172,6 +148,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 +165,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,17 +236,17 @@ 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 @@ -274,13 +260,14 @@ 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 +283,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 +378,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 +441,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..5eced059b4372 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,47 @@ +/* + * 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__ -TYPEDEF __builtin_va_list va_list; -TYPEDEF __builtin_va_list __isoc_va_list; +#define __BYTE_ORDER 1234 +#define __LONG_MAX __LONG_MAX__ #ifndef __cplusplus -TYPEDEF unsigned wchar_t; +TYPEDEF __WCHAR_TYPE__ wchar_t; #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 int suseconds_t; +TYPEDEF unsigned int wctype_t; TYPEDEF float float_t; TYPEDEF double double_t; -TYPEDEF struct { long long __ll; long double __ld; } max_align_t; -TYPEDEF long time_t; -TYPEDEF long suseconds_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[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; +// 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. 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\ +/ 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