diff --git a/ChangeLog.md b/ChangeLog.md index d70cb2173c030..28034967c6602 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -31,6 +31,7 @@ See docs/process.md for more on how version tagging works. in emscripten. If you still need to support extremely old browsers, you can manually transpile the output of emscripten (e.g. using babel for JS and binaryen for wasm). (#26677) +- musl libc updated from v1.2.5 to v1.2.6. (#26860) 5.0.7 - 04/30/26 ---------------- diff --git a/src/lib/libsyscall.js b/src/lib/libsyscall.js index ed39f4f64d14c..25aaf65ee5fe1 100644 --- a/src/lib/libsyscall.js +++ b/src/lib/libsyscall.js @@ -48,6 +48,7 @@ var SyscallsLibrary = { {{{ makeSetValue('buf', C_STRUCTS.stat.st_size, 'stat.size', 'i64') }}}; {{{ makeSetValue('buf', C_STRUCTS.stat.st_blksize, '4096', 'i32') }}}; {{{ makeSetValue('buf', C_STRUCTS.stat.st_blocks, 'stat.blocks', 'i32') }}}; + {{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}}; var atime = stat.atime.getTime(); var mtime = stat.mtime.getTime(); var ctime = stat.ctime.getTime(); @@ -57,7 +58,6 @@ var SyscallsLibrary = { {{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_nsec, '(mtime % 1000) * 1000 * 1000', SIZE_TYPE) }}}; {{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_sec, 'Math.floor(ctime / 1000)', 'i64') }}}; {{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_nsec, '(ctime % 1000) * 1000 * 1000', SIZE_TYPE) }}}; - {{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}}; return 0; }, writeStatFs(buf, stats) { diff --git a/src/lib/libwasmfs.js b/src/lib/libwasmfs.js index 5a4f29ede10c3..8ffaba674dd65 100644 --- a/src/lib/libwasmfs.js +++ b/src/lib/libwasmfs.js @@ -260,10 +260,10 @@ addToLibrary({ size: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_size, "i53") }}}, blksize: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_blksize, "i32") }}}, blocks: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_blocks, "i32") }}}, + ino: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_ino, "u53") }}}, atime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_atim.tv_sec, "i53") }}}, mtime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_mtim.tv_sec, "i53") }}}, - ctime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_ctim.tv_sec, "i53") }}}, - ino: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_ino, "u53") }}} + ctime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_ctim.tv_sec, "i53") }}} } }, stat(path) { diff --git a/src/struct_info_generated.json b/src/struct_info_generated.json index 223558056cd05..f77971b5167ce 100644 --- a/src/struct_info_generated.json +++ b/src/struct_info_generated.json @@ -1077,24 +1077,24 @@ "__size__": 96, "st_atim": { "__size__": 16, - "tv_nsec": 48, - "tv_sec": 40 + "tv_nsec": 56, + "tv_sec": 48 }, "st_blksize": 32, "st_blocks": 36, "st_ctim": { "__size__": 16, - "tv_nsec": 80, - "tv_sec": 72 + "tv_nsec": 88, + "tv_sec": 80 }, "st_dev": 0, "st_gid": 16, - "st_ino": 88, + "st_ino": 40, "st_mode": 4, "st_mtim": { "__size__": 16, - "tv_nsec": 64, - "tv_sec": 56 + "tv_nsec": 72, + "tv_sec": 64 }, "st_nlink": 8, "st_rdev": 20, diff --git a/src/struct_info_generated_wasm64.json b/src/struct_info_generated_wasm64.json index 6d6b9a4f98e21..cca6dc368d5ad 100644 --- a/src/struct_info_generated_wasm64.json +++ b/src/struct_info_generated_wasm64.json @@ -1077,24 +1077,24 @@ "__size__": 104, "st_atim": { "__size__": 16, - "tv_nsec": 56, - "tv_sec": 48 + "tv_nsec": 64, + "tv_sec": 56 }, "st_blksize": 40, "st_blocks": 44, "st_ctim": { "__size__": 16, - "tv_nsec": 88, - "tv_sec": 80 + "tv_nsec": 96, + "tv_sec": 88 }, "st_dev": 0, "st_gid": 20, - "st_ino": 96, + "st_ino": 48, "st_mode": 4, "st_mtim": { "__size__": 16, - "tv_nsec": 72, - "tv_sec": 64 + "tv_nsec": 80, + "tv_sec": 72 }, "st_nlink": 8, "st_rdev": 24, diff --git a/system/lib/libc/README.md b/system/lib/libc/README.md index e970933eb771a..a540132169a59 100644 --- a/system/lib/libc/README.md +++ b/system/lib/libc/README.md @@ -1,14 +1,13 @@ This folder contains the musl version of libc at `/musl`. The upstream version can be found at http://www.musl-libc.org/. -Most of the source comes from musl v1.2.5, with some exceptions listed below. +Most of the source comes from musl v1.2.6, with some exceptions listed below. We track these changes from upstream in https://github.com/emscripten-core/musl and use a script (`system/lib/update_musl.py`) to pull in updates. Some changes have been made to the version that was taken from upstream, including: - * Emscripten-specific changes (from before this readme existed). These should be marked with `XXX EMSCRIPTEN` in the source, or ifdefed with `#if __EMSCRIPTEN__`. They are mostly in pthreads code and hopefully temporary. - * Backporting an operator-precedence warning fix from 6e76e1540fc58a418494bf5eb832b556f9c5763e in the upstream version. + * Emscripten-specific changes (from before this readme existed). These should be marked with `XXX EMSCRIPTEN` in the source, or ifdefed with `#ifdef __EMSCRIPTEN__`. They are mostly in pthreads code and hopefully temporary. * Switch to using the wasi `fd_write` syscall instead of `writev`. * Simplify stdout stream handling: do not support seeking, terminal handling, etc., as it just increases code size and Emscripten doesn't have those features anyhow. * Setting `_POSIX_REALTIME_SIGNALS` and `_POSIX_SPAWN` macros to -1, to exclude unsupported functions. diff --git a/system/lib/libc/musl/COPYRIGHT b/system/lib/libc/musl/COPYRIGHT index c1628e9ac84f9..2f15edc7a1793 100644 --- a/system/lib/libc/musl/COPYRIGHT +++ b/system/lib/libc/musl/COPYRIGHT @@ -74,6 +74,7 @@ Kylie McClain Leah Neukirchen Luca Barbato Luka Perkov +Lynn Ochs M Farkas-Dyck (Strake) Mahesh Bodapati Markus Wichmann @@ -103,7 +104,6 @@ Stefan O'Rear Szabolcs Nagy Timo Teräs Trutz Behn -Valentin Ochs Will Dietz William Haddon William Pitcock @@ -143,7 +143,7 @@ domain. The code also comes with a fallback permissive license for use in jurisdictions that may not recognize the public domain. The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011 -Valentin Ochs and is licensed under an MIT-style license. +Lynn Ochs and is licensed under an MIT-style license. The x86_64 port was written by Nicholas J. Kain and is licensed under the standard MIT terms. diff --git a/system/lib/libc/musl/Makefile b/system/lib/libc/musl/Makefile index e8cc443675efc..3ad88b359a7a4 100644 --- a/system/lib/libc/musl/Makefile +++ b/system/lib/libc/musl/Makefile @@ -109,7 +109,7 @@ obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version obj/crt/rcrt1.o obj/ldso/dlstart.lo obj/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h -obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h +obj/crt/crt1.o obj/crt/Scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c diff --git a/system/lib/libc/musl/VERSION b/system/lib/libc/musl/VERSION index c813fe116c9f9..3c43790f5d820 100644 --- a/system/lib/libc/musl/VERSION +++ b/system/lib/libc/musl/VERSION @@ -1 +1 @@ -1.2.5 +1.2.6 diff --git a/system/lib/libc/musl/WHATSNEW b/system/lib/libc/musl/WHATSNEW index 7bd9072801db3..bb2cd9bd8a005 100644 --- a/system/lib/libc/musl/WHATSNEW +++ b/system/lib/libc/musl/WHATSNEW @@ -2438,3 +2438,56 @@ arch-specific bugs fixed: - riscv64 icache flush operation was non-functional - sh sigsetjmp failed to properly restore call-saved register r8 on return - sh dlsym RTLD_NEXT did not identify calling module correctly + + + +1.2.6 release notes + +new features: +- posix_getdents interface (new in POSIX-2024) +- renameat2 interface (linux extension) +- iconv support for CP858 +- vdso clock_gettime for riscv{32,64}, powerpc{,64}, and s390x +- loongarch64 TLSDESC support +- exposed __getauxval for compiler runtime use detecting cpu features + +compatibility: +- initgroups no longer artificially limits number of supplementary groups +- getusershell now skips blank lines and comments +- exit is now explicitly thread-safe (possible future requirement) +- atexit now fails rather than deadlocking if called from late dtor +- strerror now has error strings for EUCLEAN and ENAVAIL +- isatty no longer collapses errors to ENOTTY +- sched.h namespace pollution with _GNU_SOURCE is reduced +- hasmntopt now matches only whole options, not arbitrary substrings +- shadow.h no longer declares an unimplemented sgetspent interface +- vdso with missing sysv hash table (only gnu hash) is now supported + +conformance: +- pwrite now handles O_APPEND correctly, reports error if it can't +- mbnrtowcs now conforms to new POSIX-2024 requirement for partial character +- iconv GBK now properly includes euro symbol +- strptime now accepts conversion specifiers added in POSIX-2024 +- inet_ntop IPv6 "zero compression" now conforms to RFC 5952 + +bugs fixed: +- iconv euc-kr decoder could do oob writes on invalid inputs (CVE-2025-26519) +- iconv shift_jis decoder could produce wrong outputs for some invalid inputs +- printf did not honor hex float precision correctly in some cases +- lost or delayed wakes in sem_post under race condition +- termios input speed handling was wrong +- strcasestr failed to match zero-length needle +- fma handled corner case with negative zero wrongly +- syslog LOG_MAKEPRI macro was incorrect +- timer_create is no longer affected by known pthread_barrier bugs +- sysconf(_SC_MINSIGSTKSZ) computed min size incorrectly +- statx emulation left some fields uninitialized +- mntent wrongly included final newline in parsed field output +- SIGEV_THREAD timers could abort process if SIGTIMER became unblocked +- bind_textdomain_codeset returned wrong value + +arch-specific bugs fixed: +- early dynamic linker handled page size wrong on dynamic pagesize archs +- arm and aarch64 crti/n files had wrong alignment +- m68k POLLWRNORM and POLLWRBAND values were incorrect +- x32 mq ABI was mismatched diff --git a/system/lib/libc/musl/arch/emscripten/bits/endian.h b/system/lib/libc/musl/arch/emscripten/bits/endian.h deleted file mode 100644 index 172c338f5080a..0000000000000 --- a/system/lib/libc/musl/arch/emscripten/bits/endian.h +++ /dev/null @@ -1 +0,0 @@ -#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/system/lib/libc/musl/arch/emscripten/bits/fenv.h b/system/lib/libc/musl/arch/emscripten/bits/fenv.h index d3512cb6f7f53..4aff0bd7b95ec 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/fenv.h +++ b/system/lib/libc/musl/arch/emscripten/bits/fenv.h @@ -8,20 +8,7 @@ typedef unsigned short fexcept_t; typedef struct { - unsigned short __control_word; - unsigned short __unused1; - unsigned short __status_word; - unsigned short __unused2; - unsigned short __tags; - unsigned short __unused3; - unsigned int __eip; - unsigned short __cs_selector; - unsigned int __opcode:11; - unsigned int __unused4:5; - unsigned int __data_offset; - unsigned short __data_selector; - unsigned short __unused5; - unsigned int __mxcsr; + unsigned __cw; } fenv_t; #define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/system/lib/libc/musl/arch/emscripten/bits/limits.h b/system/lib/libc/musl/arch/emscripten/bits/limits.h index 7a09fdc1d175d..b36e964152ea1 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/limits.h +++ b/system/lib/libc/musl/arch/emscripten/bits/limits.h @@ -1 +1,3 @@ -#define PAGE_SIZE 65536 +// A value used historically in Emscripten, and which we don't have a strong +// reason to change so far. +#define PAGESIZE 65536 diff --git a/system/lib/libc/musl/arch/emscripten/bits/mman.h b/system/lib/libc/musl/arch/emscripten/bits/mman.h new file mode 100644 index 0000000000000..c52e718d0623f --- /dev/null +++ b/system/lib/libc/musl/arch/emscripten/bits/mman.h @@ -0,0 +1,4 @@ +// XXX Emscripten in sync with both: +// - musl/arch/x86_64/bits/mman.h +// - musl/arch/i386/bits/mman.h +#define MAP_32BIT 0x40 diff --git a/system/lib/libc/musl/arch/emscripten/bits/posix.h b/system/lib/libc/musl/arch/emscripten/bits/posix.h deleted file mode 100644 index 30a38714f36dd..0000000000000 --- a/system/lib/libc/musl/arch/emscripten/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_ILP32_OFFBIG 1 -#define _POSIX_V7_ILP32_OFFBIG 1 diff --git a/system/lib/libc/musl/arch/emscripten/bits/reg.h b/system/lib/libc/musl/arch/emscripten/bits/reg.h deleted file mode 100644 index 1c4987c775f11..0000000000000 --- a/system/lib/libc/musl/arch/emscripten/bits/reg.h +++ /dev/null @@ -1,6 +0,0 @@ -#undef __WORDSIZE -#ifdef __wasm64__ -#define __WORDSIZE 64 -#else -#define __WORDSIZE 32 -#endif diff --git a/system/lib/libc/musl/arch/emscripten/bits/setjmp.h b/system/lib/libc/musl/arch/emscripten/bits/setjmp.h index decd26dca07a0..1c9aa40ed60c4 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/setjmp.h +++ b/system/lib/libc/musl/arch/emscripten/bits/setjmp.h @@ -1 +1,2 @@ +// XXX Emscripten in sync with musl/arch/i386/bits/setjmp.h typedef unsigned long __jmp_buf[6]; diff --git a/system/lib/libc/musl/arch/emscripten/bits/signal.h b/system/lib/libc/musl/arch/emscripten/bits/signal.h index 58bc5e2c3a780..231dc9261d885 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/signal.h +++ b/system/lib/libc/musl/arch/emscripten/bits/signal.h @@ -1,3 +1,4 @@ +// XXX Emscripten in sync with musl/arch/i386/bits/signal.h #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) @@ -7,33 +8,46 @@ #endif #ifdef _GNU_SOURCE -#define REG_GS 0 -#define REG_FS 1 -#define REG_ES 2 -#define REG_DS 3 -#define REG_EDI 4 -#define REG_ESI 5 -#define REG_EBP 6 -#define REG_ESP 7 -#define REG_EBX 8 -#define REG_EDX 9 -#define REG_ECX 10 -#define REG_EAX 11 -#define REG_TRAPNO 12 -#define REG_ERR 13 -#define REG_EIP 14 -#define REG_CS 15 -#define REG_EFL 16 -#define REG_UESP 17 -#define REG_SS 18 +enum { REG_GS = 0 }; +#define REG_GS REG_GS +enum { REG_FS = 1 }; +#define REG_FS REG_FS +enum { REG_ES = 2 }; +#define REG_ES REG_ES +enum { REG_DS = 3 }; +#define REG_DS REG_DS +enum { REG_EDI = 4 }; +#define REG_EDI REG_EDI +enum { REG_ESI = 5 }; +#define REG_ESI REG_ESI +enum { REG_EBP = 6 }; +#define REG_EBP REG_EBP +enum { REG_ESP = 7 }; +#define REG_ESP REG_ESP +enum { REG_EBX = 8 }; +#define REG_EBX REG_EBX +enum { REG_EDX = 9 }; +#define REG_EDX REG_EDX +enum { REG_ECX = 10 }; +#define REG_ECX REG_ECX +enum { REG_EAX = 11 }; +#define REG_EAX REG_EAX +enum { REG_TRAPNO = 12 }; +#define REG_TRAPNO REG_TRAPNO +enum { REG_ERR = 13 }; +#define REG_ERR REG_ERR +enum { REG_EIP = 14 }; +#define REG_EIP REG_EIP +enum { REG_CS = 15 }; +#define REG_CS REG_CS +enum { REG_EFL = 16 }; +#define REG_EFL REG_EFL +enum { REG_UESP = 17 }; +#define REG_UESP REG_UESP +enum { REG_SS = 18 }; +#define REG_SS REG_SS #endif -struct sigaltstack { - void *ss_sp; - int ss_flags; - size_t ss_size; -}; - #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) typedef int greg_t, gregset_t[19]; typedef struct _fpstate { @@ -64,6 +78,12 @@ typedef struct { } mcontext_t; #endif +struct sigaltstack { + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + typedef struct __ucontext { unsigned long uc_flags; struct __ucontext *uc_link; diff --git a/system/lib/libc/musl/arch/emscripten/bits/stat.h b/system/lib/libc/musl/arch/emscripten/bits/stat.h index bfa9a597bcf6d..e2d91a9b68139 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/stat.h +++ b/system/lib/libc/musl/arch/emscripten/bits/stat.h @@ -1,8 +1,8 @@ +// XXX Emscripten in sync with musl/arch/i386/bits/stat.h except for the padding and 64-bit time_t redirections change. + /* copied from kernel definition, but with padding replaced * by the corresponding correctly-sized userspace types. */ - -struct stat -{ +struct stat { dev_t st_dev; #ifndef __EMSCRIPTEN__ int __st_dev_padding; @@ -19,8 +19,14 @@ struct stat off_t st_size; blksize_t st_blksize; blkcnt_t st_blocks; +#ifndef __EMSCRIPTEN__ // XXX Emscripten no need to activate the symbol redirections for 64-bit time_t. + struct { + long tv_sec; + long tv_nsec; + } __st_atim32, __st_mtim32, __st_ctim32; +#endif + ino_t st_ino; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; - ino_t st_ino; }; diff --git a/system/lib/libc/musl/arch/emscripten/bits/user.h b/system/lib/libc/musl/arch/emscripten/bits/user.h index fa623621eeba3..e69de29bb2d1d 100644 --- a/system/lib/libc/musl/arch/emscripten/bits/user.h +++ b/system/lib/libc/musl/arch/emscripten/bits/user.h @@ -1,48 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 32 - -typedef struct user_fpregs_struct -{ - long cwd, swd, twd, fip, fcs, foo, fos, st_space[20]; -} elf_fpregset_t; - -typedef struct user_fpxregs_struct -{ - unsigned short cwd, swd, twd, fop; - long fip, fcs, foo, fos, mxcsr, reserved; - long st_space[32], xmm_space[32], padding[56]; -} elf_fpxregset_t; - -struct user_regs_struct -{ - long ebx, ecx, edx, esi, edi, ebp, eax, xds, xes, xfs, xgs; - long orig_eax, eip, xcs, eflags, esp, xss; -}; - -#define ELF_NGREG 17 -typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG]; - -struct user -{ - struct user_regs_struct regs; - int u_fpvalid; - struct user_fpregs_struct i387; - unsigned long u_tsize; - unsigned long u_dsize; - unsigned long u_ssize; - unsigned long start_code; - unsigned long start_stack; - long signal; - int reserved; - struct user_regs_struct *u_ar0; - struct user_fpregs_struct *u_fpstate; - unsigned long magic; - char u_comm[32]; - int u_debugreg[8]; -}; - -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE -#define UPAGES 1 -#define HOST_TEXT_START_ADDR (u.start_code) -#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) diff --git a/system/lib/libc/musl/arch/generic/bits/reg.h b/system/lib/libc/musl/arch/generic/bits/reg.h new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/system/lib/libc/musl/arch/generic/bits/stat.h b/system/lib/libc/musl/arch/generic/bits/stat.h new file mode 100644 index 0000000000000..f6d9e864068db --- /dev/null +++ b/system/lib/libc/musl/arch/generic/bits/stat.h @@ -0,0 +1,18 @@ +struct stat { + dev_t st_dev; + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + unsigned long long __pad; + off_t st_size; + blksize_t st_blksize; + int __pad2; + blkcnt_t st_blocks; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; + unsigned __unused[2]; +}; diff --git a/system/lib/libc/musl/arch/generic/bits/stdarg.h b/system/lib/libc/musl/arch/generic/bits/stdarg.h deleted file mode 100644 index fde378146d5df..0000000000000 --- a/system/lib/libc/musl/arch/generic/bits/stdarg.h +++ /dev/null @@ -1,4 +0,0 @@ -#define va_start(v,l) __builtin_va_start(v,l) -#define va_end(v) __builtin_va_end(v) -#define va_arg(v,l) __builtin_va_arg(v,l) -#define va_copy(d,s) __builtin_va_copy(d,s) diff --git a/system/lib/libc/musl/arch/generic/bits/stdint.h b/system/lib/libc/musl/arch/generic/bits/stdint.h new file mode 100644 index 0000000000000..8648918746aed --- /dev/null +++ b/system/lib/libc/musl/arch/generic/bits/stdint.h @@ -0,0 +1,29 @@ +typedef int32_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef uint32_t uint_fast16_t; +typedef uint32_t uint_fast32_t; + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN + +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX + +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#if __LONG_MAX == 0x7fffffffL +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX +#define SIZE_MAX UINT32_MAX +#else +#define INTPTR_MIN INT64_MIN +#define INTPTR_MAX INT64_MAX +#define UINTPTR_MAX UINT64_MAX +#define PTRDIFF_MIN INT64_MIN +#define PTRDIFF_MAX INT64_MAX +#define SIZE_MAX UINT64_MAX +#endif diff --git a/system/lib/libc/musl/include/dirent.h b/system/lib/libc/musl/include/dirent.h index 2d8fffb23f001..7fa60e0672171 100644 --- a/system/lib/libc/musl/include/dirent.h +++ b/system/lib/libc/musl/include/dirent.h @@ -9,14 +9,23 @@ extern "C" { #define __NEED_ino_t #define __NEED_off_t -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) #define __NEED_size_t -#endif +#define __NEED_ssize_t #include #include +typedef unsigned short reclen_t; + +struct posix_dent { + ino_t d_ino; + off_t d_off; + reclen_t d_reclen; + unsigned char d_type; + char d_name[]; +}; + typedef struct __dirstream DIR; #define d_fileno d_ino @@ -29,6 +38,8 @@ int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dire void rewinddir(DIR *); int dirfd(DIR *); +ssize_t posix_getdents(int, void *, size_t, int); + int alphasort(const struct dirent **, const struct dirent **); int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); @@ -37,7 +48,6 @@ void seekdir(DIR *, long); long telldir(DIR *); #endif -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define DT_UNKNOWN 0 #define DT_FIFO 1 #define DT_CHR 2 @@ -47,6 +57,8 @@ long telldir(DIR *); #define DT_LNK 10 #define DT_SOCK 12 #define DT_WHT 14 + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define IFTODT(x) ((x)>>12 & 017) #define DTTOIF(x) ((x)<<12) int getdents(int, struct dirent *, size_t); diff --git a/system/lib/libc/musl/include/elf.h b/system/lib/libc/musl/include/elf.h index 3d5e13e4b6e53..2555b90610b0d 100644 --- a/system/lib/libc/musl/include/elf.h +++ b/system/lib/libc/musl/include/elf.h @@ -712,6 +712,8 @@ typedef struct { #define NT_LOONGARCH_LSX 0xa02 #define NT_LOONGARCH_LASX 0xa03 #define NT_LOONGARCH_LBT 0xa04 +#define NT_LOONGARCH_HW_BREAK 0xa05 +#define NT_LOONGARCH_HW_WATCH 0xa06 @@ -1040,6 +1042,8 @@ typedef struct { #define AT_RANDOM 25 #define AT_HWCAP2 26 +#define AT_HWCAP3 29 +#define AT_HWCAP4 30 #define AT_EXECFN 31 @@ -3329,6 +3333,7 @@ enum #define R_LARCH_TLS_TPREL32 10 #define R_LARCH_TLS_TPREL64 11 #define R_LARCH_IRELATIVE 12 +#define R_LARCH_TLS_DESC64 14 #define R_LARCH_MARK_LA 20 #define R_LARCH_MARK_PCREL 21 #define R_LARCH_SOP_PUSH_PCREL 22 @@ -3405,6 +3410,32 @@ enum #define R_LARCH_TLS_GD_HI20 98 #define R_LARCH_32_PCREL 99 #define R_LARCH_RELAX 100 +#define R_LARCH_DELETE 101 +#define R_LARCH_ALIGN 102 +#define R_LARCH_PCREL20_S2 103 +#define R_LARCH_CFA 104 +#define R_LARCH_ADD6 105 +#define R_LARCH_SUB6 106 +#define R_LARCH_ADD_ULEB128 107 +#define R_LARCH_SUB_ULEB128 108 +#define R_LARCH_64_PCREL 109 +#define R_LARCH_CALL36 110 +#define R_LARCH_TLS_DESC_PC_HI20 111 +#define R_LARCH_TLS_DESC_PC_LO12 112 +#define R_LARCH_TLS_DESC64_PC_LO20 113 +#define R_LARCH_TLS_DESC64_PC_HI12 114 +#define R_LARCH_TLS_DESC_HI20 115 +#define R_LARCH_TLS_DESC_LO12 116 +#define R_LARCH_TLS_DESC64_LO20 117 +#define R_LARCH_TLS_DESC64_HI12 118 +#define R_LARCH_TLS_DESC_LD 119 +#define R_LARCH_TLS_DESC_CALL 120 +#define R_LARCH_TLS_LE_HI20_R 121 +#define R_LARCH_TLS_LE_ADD_R 122 +#define R_LARCH_TLS_LE_LO12_R 123 +#define R_LARCH_TLS_LD_PCREL20_S2 124 +#define R_LARCH_TLS_GD_PCREL20_S2 125 +#define R_LARCH_TLS_DESC_PCREL20_S2 126 #ifdef __cplusplus } diff --git a/system/lib/libc/musl/include/netinet/in.h b/system/lib/libc/musl/include/netinet/in.h index fb628b61a9c40..60bbaa75b1728 100644 --- a/system/lib/libc/musl/include/netinet/in.h +++ b/system/lib/libc/musl/include/netinet/in.h @@ -132,7 +132,8 @@ uint16_t ntohs(uint16_t); #define IN6_IS_ADDR_V4COMPAT(a) \ (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) + ((uint32_t *) (a))[2] == 0 && \ + !IN6_IS_ADDR_UNSPECIFIED(a) && !IN6_IS_ADDR_LOOPBACK(a)) #define IN6_IS_ADDR_MC_NODELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) diff --git a/system/lib/libc/musl/include/sched.h b/system/lib/libc/musl/include/sched.h index 204c34f5679f3..8c3b53f0fe7a5 100644 --- a/system/lib/libc/musl/include/sched.h +++ b/system/lib/libc/musl/include/sched.h @@ -78,11 +78,10 @@ int clone (int (*)(void *), void *, int, void *, ...); int unshare(int); int setns(int, int); -void *memcpy(void *__restrict, const void *__restrict, size_t); -int memcmp(const void *, const void *, size_t); -void *memset (void *, int, size_t); -void *calloc(size_t, size_t); -void free(void *); +int (memcmp)(const void *, const void *, size_t); +void *(memset)(void *, int, size_t); +void *(calloc)(size_t, size_t); +void (free)(void *); typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; int __sched_cpucount(size_t, const cpu_set_t *); @@ -116,13 +115,13 @@ __CPU_op_func_S(XOR, ^) #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) #define CPU_COUNT_S(size,set) __sched_cpucount(size,set) -#define CPU_ZERO_S(size,set) memset(set,0,size) -#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) +#define CPU_ZERO_S(size,set) (memset)(set,0,size) +#define CPU_EQUAL_S(size,set1,set2) (!(memcmp)(set1,set2,size)) #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) -#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) -#define CPU_FREE(set) free(set) +#define CPU_ALLOC(n) ((cpu_set_t *)(calloc)(1,CPU_ALLOC_SIZE(n))) +#define CPU_FREE(set) (free)(set) #define CPU_SETSIZE 1024 diff --git a/system/lib/libc/musl/include/shadow.h b/system/lib/libc/musl/include/shadow.h index 2b1be413f3643..a9d6940f17f62 100644 --- a/system/lib/libc/musl/include/shadow.h +++ b/system/lib/libc/musl/include/shadow.h @@ -28,7 +28,6 @@ void setspent(void); void endspent(void); struct spwd *getspent(void); struct spwd *fgetspent(FILE *); -struct spwd *sgetspent(const char *); int putspent(const struct spwd *, FILE *); struct spwd *getspnam(const char *); diff --git a/system/lib/libc/musl/include/stdio.h b/system/lib/libc/musl/include/stdio.h index 609fad5fdff3e..2449b02055c89 100644 --- a/system/lib/libc/musl/include/stdio.h +++ b/system/lib/libc/musl/include/stdio.h @@ -168,6 +168,13 @@ char *ctermid(char *); #define L_ctermid 20 #endif +#if defined(_GNU_SOURCE) +#define RENAME_NOREPLACE (1 << 0) +#define RENAME_EXCHANGE (1 << 1) +#define RENAME_WHITEOUT (1 << 2) + +int renameat2(int, const char *, int, const char *, unsigned); +#endif #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ || defined(_BSD_SOURCE) diff --git a/system/lib/libc/musl/include/sys/mman.h b/system/lib/libc/musl/include/sys/mman.h index 3d5d0f9c23383..aa2c48177a9e4 100644 --- a/system/lib/libc/musl/include/sys/mman.h +++ b/system/lib/libc/musl/include/sys/mman.h @@ -95,6 +95,10 @@ extern "C" { #define MADV_KEEPONFORK 19 #define MADV_COLD 20 #define MADV_PAGEOUT 21 +#define MADV_POPULATE_READ 22 +#define MADV_POPULATE_WRITE 23 +#define MADV_DONTNEED_LOCKED 24 +#define MADV_COLLAPSE 25 #define MADV_HWPOISON 100 #define MADV_SOFT_OFFLINE 101 #endif diff --git a/system/lib/libc/musl/include/sys/reg.h b/system/lib/libc/musl/include/sys/reg.h index b47452d003ec6..0272e1370f238 100644 --- a/system/lib/libc/musl/include/sys/reg.h +++ b/system/lib/libc/musl/include/sys/reg.h @@ -4,6 +4,15 @@ #include #include +#include + +#undef __WORDSIZE +#if __LONG_MAX == 0x7fffffffL +#define __WORDSIZE 32 +#else +#define __WORDSIZE 64 +#endif + #include #endif diff --git a/system/lib/libc/musl/include/sys/stat.h b/system/lib/libc/musl/include/sys/stat.h index 6690192d19565..4f7dc2b1082c2 100644 --- a/system/lib/libc/musl/include/sys/stat.h +++ b/system/lib/libc/musl/include/sys/stat.h @@ -120,6 +120,22 @@ int lchmod(const char *, mode_t); #define STATX_BASIC_STATS 0x7ffU #define STATX_BTIME 0x800U #define STATX_ALL 0xfffU +#define STATX_MNT_ID 0x1000U +#define STATX_DIOALIGN 0x2000U +#define STATX_MNT_ID_UNIQUE 0x4000U +#define STATX_SUBVOL 0x8000U +#define STATX_WRITE_ATOMIC 0x10000U + +#define STATX_ATTR_COMPRESSED 0x4 +#define STATX_ATTR_IMMUTABLE 0x10 +#define STATX_ATTR_APPEND 0x20 +#define STATX_ATTR_NODUMP 0x40 +#define STATX_ATTR_ENCRYPTED 0x800 +#define STATX_ATTR_AUTOMOUNT 0x1000 +#define STATX_ATTR_MOUNT_ROOT 0x2000 +#define STATX_ATTR_VERITY 0x100000 +#define STATX_ATTR_DAX 0x200000 +#define STATX_ATTR_WRITE_ATOMIC 0x400000 struct statx_timestamp { int64_t tv_sec; @@ -147,7 +163,16 @@ struct statx { uint32_t stx_rdev_minor; uint32_t stx_dev_major; uint32_t stx_dev_minor; - uint64_t __pad1[14]; + uint64_t stx_mnt_id; + uint32_t stx_dio_mem_align; + uint32_t stx_dio_offset_align; + uint64_t stx_subvol; + uint32_t stx_atomic_write_unit_min; + uint32_t stx_atomic_write_unit_max; + uint32_t stx_atomic_write_segments_max; + uint32_t __pad1[1]; + uint64_t __pad2[9]; + }; int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict); diff --git a/system/lib/libc/musl/include/sys/uio.h b/system/lib/libc/musl/include/sys/uio.h index 8b5e3de79ce84..5e99c7fa24455 100644 --- a/system/lib/libc/musl/include/sys/uio.h +++ b/system/lib/libc/musl/include/sys/uio.h @@ -46,6 +46,7 @@ ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); #define RWF_SYNC 0x00000004 #define RWF_NOWAIT 0x00000008 #define RWF_APPEND 0x00000010 +#define RWF_NOAPPEND 0x00000020 #endif #ifdef __cplusplus diff --git a/system/lib/libc/musl/include/sys/user.h b/system/lib/libc/musl/include/sys/user.h index 96a03400900b6..511caba389b43 100644 --- a/system/lib/libc/musl/include/sys/user.h +++ b/system/lib/libc/musl/include/sys/user.h @@ -8,6 +8,15 @@ extern "C" { #include #include +#include + +#undef __WORDSIZE +#if __LONG_MAX == 0x7fffffffL +#define __WORDSIZE 32 +#else +#define __WORDSIZE 64 +#endif + #include #ifdef __cplusplus diff --git a/system/lib/libc/musl/include/syslog.h b/system/lib/libc/musl/include/syslog.h index 5b4d2964e780e..57599e076e925 100644 --- a/system/lib/libc/musl/include/syslog.h +++ b/system/lib/libc/musl/include/syslog.h @@ -18,7 +18,7 @@ extern "C" { #define LOG_PRIMASK 7 #define LOG_PRI(p) ((p)&LOG_PRIMASK) -#define LOG_MAKEPRI(f, p) (((f)<<3)|(p)) +#define LOG_MAKEPRI(f, p) ((f)|(p)) #define LOG_MASK(p) (1<<(p)) #define LOG_UPTO(p) ((1<<((p)+1))-1) diff --git a/system/lib/libc/musl/include/unistd.h b/system/lib/libc/musl/include/unistd.h index d98a7460db4d3..59b38fd01d8a0 100644 --- a/system/lib/libc/musl/include/unistd.h +++ b/system/lib/libc/musl/include/unistd.h @@ -293,7 +293,13 @@ pid_t gettid(void); #define _POSIX2_C_BIND _POSIX_VERSION -#include +#if __LONG_MAX == 0x7fffffffL +#define _POSIX_V6_ILP32_OFFBIG 1 +#define _POSIX_V7_ILP32_OFFBIG 1 +#else +#define _POSIX_V6_LP64_OFF64 1 +#define _POSIX_V7_LP64_OFF64 1 +#endif diff --git a/system/lib/libc/musl/ldso/dlstart.c b/system/lib/libc/musl/ldso/dlstart.c index 259f5e18eecf8..4aac42bc23572 100644 --- a/system/lib/libc/musl/ldso/dlstart.c +++ b/system/lib/libc/musl/ldso/dlstart.c @@ -45,7 +45,7 @@ hidden void _dlstart_c(size_t *sp, size_t *dynv) /* If dynv is null, the entry point was started from loader * that is not fdpic-aware. We can assume normal fixed- * displacement ELF loading was performed, but when ldso was - * run as a command, finding the Ehdr is a heursitic: we + * run as a command, finding the Ehdr is a heuristic: we * have to assume Phdrs start in the first 4k of the file. */ base = aux[AT_BASE]; if (!base) base = aux[AT_PHDR] & -4096; diff --git a/system/lib/libc/musl/ldso/dynlink.c b/system/lib/libc/musl/ldso/dynlink.c index 324aa85919f0f..715948f4f8b3e 100644 --- a/system/lib/libc/musl/ldso/dynlink.c +++ b/system/lib/libc/musl/ldso/dynlink.c @@ -21,15 +21,17 @@ #include #include "pthread_impl.h" #include "fork_impl.h" +#include "libc.h" #include "dynlink.h" static size_t ldso_page_size; -#ifndef PAGE_SIZE +/* libc.h may have defined a macro for dynamic PAGE_SIZE already, but + * PAGESIZE is only defined if it's constant for the arch. */ +#ifndef PAGESIZE +#undef PAGE_SIZE #define PAGE_SIZE ldso_page_size #endif -#include "libc.h" - #define malloc __libc_malloc #define calloc __libc_calloc #define realloc __libc_realloc @@ -360,19 +362,14 @@ static struct symdef get_lfs64(const char *name) "pwritev\0readdir\0scandir\0sendfile\0setrlimit\0" "stat\0statfs\0statvfs\0tmpfile\0truncate\0versionsort\0" "__fxstat\0__fxstatat\0__lxstat\0__xstat\0"; - size_t l; - char buf[16]; - for (l=0; name[l]; l++) { - if (l >= sizeof buf) goto nomatch; - buf[l] = name[l]; - } if (!strcmp(name, "readdir64_r")) return find_sym(&ldso, "readdir_r", 1); - if (l<2 || name[l-2]!='6' || name[l-1]!='4') + size_t l = strnlen(name, 18); + if (l<2 || name[l-2]!='6' || name[l-1]!='4' || name[l]) goto nomatch; - buf[l-=2] = 0; for (p=lfs64_list; *p; p++) { - if (!strcmp(buf, p)) return find_sym(&ldso, buf, 1); + if (!strncmp(name, p, l-2) && !p[l-2]) + return find_sym(&ldso, p, 1); while (*p) p++; } nomatch: @@ -619,6 +616,7 @@ static void reclaim_gaps(struct dso *dso) for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) { if (ph->p_type!=PT_LOAD) continue; if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue; + if (ph->p_memsz == 0) continue; reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr); reclaim(dso, ph->p_vaddr+ph->p_memsz, ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE); diff --git a/system/lib/libc/musl/src/complex/cacosh.c b/system/lib/libc/musl/src/complex/cacosh.c index 76127f75f4bb1..55b857cefea37 100644 --- a/system/lib/libc/musl/src/complex/cacosh.c +++ b/system/lib/libc/musl/src/complex/cacosh.c @@ -1,6 +1,6 @@ #include "complex_impl.h" -/* acosh(z) = i acos(z) */ +/* acosh(z) = ±i acos(z) */ double complex cacosh(double complex z) { diff --git a/system/lib/libc/musl/src/complex/catan.c b/system/lib/libc/musl/src/complex/catan.c index ccc2fb539af79..b4fe552a786ae 100644 --- a/system/lib/libc/musl/src/complex/catan.c +++ b/system/lib/libc/musl/src/complex/catan.c @@ -60,29 +60,6 @@ #include "complex_impl.h" -#define MAXNUM 1.0e308 - -static const double DP1 = 3.14159265160560607910E0; -static const double DP2 = 1.98418714791870343106E-9; -static const double DP3 = 1.14423774522196636802E-17; - -static double _redupi(double x) -{ - double t; - long i; - - t = x/M_PI; - if (t >= 0.0) - t += 0.5; - else - t -= 0.5; - - i = t; /* the multiple */ - t = i; - t = ((x - t * DP1) - t * DP2) - t * DP3; - return t; -} - double complex catan(double complex z) { double complex w; @@ -95,7 +72,7 @@ double complex catan(double complex z) a = 1.0 - x2 - (y * y); t = 0.5 * atan2(2.0 * x, a); - w = _redupi(t); + w = t; t = y - 1.0; a = x2 + (t * t); diff --git a/system/lib/libc/musl/src/complex/catanf.c b/system/lib/libc/musl/src/complex/catanf.c index 1d569f2dacf99..faaa907a27e21 100644 --- a/system/lib/libc/musl/src/complex/catanf.c +++ b/system/lib/libc/musl/src/complex/catanf.c @@ -55,32 +55,6 @@ #include "complex_impl.h" -#define MAXNUMF 1.0e38F - -static const double DP1 = 3.140625; -static const double DP2 = 9.67502593994140625E-4; -static const double DP3 = 1.509957990978376432E-7; - -static const float float_pi = M_PI; - -static float _redupif(float xx) -{ - float x, t; - long i; - - x = xx; - t = x/float_pi; - if (t >= 0.0f) - t += 0.5f; - else - t -= 0.5f; - - i = t; /* the multiple */ - t = i; - t = ((x - t * DP1) - t * DP2) - t * DP3; - return t; -} - float complex catanf(float complex z) { float complex w; @@ -93,7 +67,7 @@ float complex catanf(float complex z) a = 1.0f - x2 - (y * y); t = 0.5f * atan2f(2.0f * x, a); - w = _redupif(t); + w = t; t = y - 1.0f; a = x2 + (t * t); diff --git a/system/lib/libc/musl/src/complex/catanl.c b/system/lib/libc/musl/src/complex/catanl.c index e62526c00672b..cd2d2b0032723 100644 --- a/system/lib/libc/musl/src/complex/catanl.c +++ b/system/lib/libc/musl/src/complex/catanl.c @@ -67,28 +67,6 @@ long double complex catanl(long double complex z) return catan(z); } #else -static const long double PIL = 3.141592653589793238462643383279502884197169L; -static const long double DP1 = 3.14159265358979323829596852490908531763125L; -static const long double DP2 = 1.6667485837041756656403424829301998703007e-19L; -static const long double DP3 = 1.8830410776607851167459095484560349402753e-39L; - -static long double redupil(long double x) -{ - long double t; - long i; - - t = x / PIL; - if (t >= 0.0L) - t += 0.5L; - else - t -= 0.5L; - - i = t; /* the multiple */ - t = i; - t = ((x - t * DP1) - t * DP2) - t * DP3; - return t; -} - long double complex catanl(long double complex z) { long double complex w; @@ -101,7 +79,7 @@ long double complex catanl(long double complex z) a = 1.0L - x2 - (y * y); t = atan2l(2.0L * x, a) * 0.5L; - w = redupil(t); + w = t; t = y - 1.0L; a = x2 + (t * t); diff --git a/system/lib/libc/musl/src/conf/sysconf.c b/system/lib/libc/musl/src/conf/sysconf.c index a043fe1ac08e1..f3f9993977d47 100644 --- a/system/lib/libc/musl/src/conf/sysconf.c +++ b/system/lib/libc/musl/src/conf/sysconf.c @@ -234,8 +234,13 @@ long sysconf(int name) return (mem > LONG_MAX) ? LONG_MAX : mem; case JT_MINSIGSTKSZ & 255: case JT_SIGSTKSZ & 255: ; - long val = __getauxval(AT_MINSIGSTKSZ); - if (val < MINSIGSTKSZ) val = MINSIGSTKSZ; + /* Value from auxv/kernel is only sigfame size. Clamp it + * to at least 1k below arch's traditional MINSIGSTKSZ, + * then add 1k of working space for signal handler. */ + unsigned long sigframe_sz = __getauxval(AT_MINSIGSTKSZ); + if (sigframe_sz < MINSIGSTKSZ - 1024) + sigframe_sz = MINSIGSTKSZ - 1024; + unsigned val = sigframe_sz + 1024; if (values[name] == JT_SIGSTKSZ) val += SIGSTKSZ - MINSIGSTKSZ; return val; diff --git a/system/lib/libc/musl/src/dirent/posix_getdents.c b/system/lib/libc/musl/src/dirent/posix_getdents.c new file mode 100644 index 0000000000000..26c16ac6b8e94 --- /dev/null +++ b/system/lib/libc/musl/src/dirent/posix_getdents.c @@ -0,0 +1,11 @@ +#include +#include +#include +#include "syscall.h" + +ssize_t posix_getdents(int fd, void *buf, size_t len, int flags) +{ + if (flags) return __syscall_ret(-EOPNOTSUPP); + if (len>INT_MAX) len = INT_MAX; + return syscall(SYS_getdents, fd, buf, len); +} diff --git a/system/lib/libc/musl/src/errno/__strerror.h b/system/lib/libc/musl/src/errno/__strerror.h index 598af448c5102..d9fd210fc30dc 100644 --- a/system/lib/libc/musl/src/errno/__strerror.h +++ b/system/lib/libc/musl/src/errno/__strerror.h @@ -112,6 +112,8 @@ E(ESHUTDOWN, "Cannot send after socket shutdown") E(EALREADY, "Operation already in progress") E(EINPROGRESS, "Operation in progress") E(ESTALE, "Stale file handle") +E(EUCLEAN, "Data consistency error") +E(ENAVAIL, "Resource not available") E(EREMOTEIO, "Remote I/O error") E(EDQUOT, "Quota exceeded") E(ENOMEDIUM, "No medium found") diff --git a/system/lib/libc/musl/src/exit/atexit.c b/system/lib/libc/musl/src/exit/atexit.c index f2401780b30e5..4d9571dd80137 100644 --- a/system/lib/libc/musl/src/exit/atexit.c +++ b/system/lib/libc/musl/src/exit/atexit.c @@ -19,6 +19,7 @@ static struct fl void *a[COUNT]; } builtin, *head; +static int finished_atexit; static int slot; static volatile int lock[1]; volatile int *const __atexit_lockptr = lock; @@ -34,6 +35,10 @@ void __funcs_on_exit() func(arg); LOCK(lock); } + /* Unlock to prevent deadlock if a global dtor + * attempts to call atexit. */ + finished_atexit = 1; + UNLOCK(lock); } void ___cxa_finalize(void *dso) @@ -44,6 +49,13 @@ int ___cxa_atexit(void (*func)(void *), void *arg, void *dso) { LOCK(lock); + /* Prevent dtors from registering further atexit + * handlers that would never be run. */ + if (finished_atexit) { + UNLOCK(lock); + return -1; + } + /* Defer initialization of head so it can be in BSS */ if (!head) head = &builtin; diff --git a/system/lib/libc/musl/src/exit/exit.c b/system/lib/libc/musl/src/exit/exit.c index a6869b37594ea..1637fdaae0b5a 100644 --- a/system/lib/libc/musl/src/exit/exit.c +++ b/system/lib/libc/musl/src/exit/exit.c @@ -1,6 +1,9 @@ #include #include #include "libc.h" +#include "pthread_impl.h" +#include "atomic.h" +#include "syscall.h" static void dummy() { @@ -26,6 +29,19 @@ weak_alias(libc_exit_fini, __libc_exit_fini); _Noreturn void exit(int code) { +#ifdef _REENTRANT // XXX Emscripten: guard with _REENTRANT + /* Handle potentially concurrent or recursive calls to exit, + * whose behaviors have traditionally been undefined by the + * standards. Using a custom lock here avoids pulling in lock + * machinery and lets us trap recursive calls while supporting + * multiple threads contending to be the one to exit(). */ + static volatile int exit_lock[1]; + int tid = __pthread_self()->tid; + int prev = a_cas(exit_lock, 0, tid); + if (prev == tid) a_crash(); + else if (prev) for (;;) __sys_pause(); +#endif + __funcs_on_exit(); __libc_exit_fini(); __stdio_exit(); diff --git a/system/lib/libc/musl/src/internal/syscall.h b/system/lib/libc/musl/src/internal/syscall.h index 1a6c4313852d7..4476dbe7db09a 100644 --- a/system/lib/libc/musl/src/internal/syscall.h +++ b/system/lib/libc/musl/src/internal/syscall.h @@ -433,6 +433,17 @@ hidden long __syscall_ret(unsigned long), #define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__) #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) +#ifdef SYS_pause +#define __sys_pause() __syscall(SYS_pause) +#define __sys_pause_cp() __syscall_cp(SYS_pause) +#else +#define __sys_pause() __syscall(SYS_ppoll, 0, 0, 0, 0) +#define __sys_pause_cp() __syscall_cp(SYS_ppoll, 0, 0, 0, 0) +#endif + +#define sys_pause() __syscall_ret(__sys_pause()) +#define sys_pause_cp() __syscall_ret(__sys_pause_cp()) + #ifdef SYS_wait4 #define __sys_wait4(a,b,c,d) __syscall(SYS_wait4,a,b,c,d) #define __sys_wait4_cp(a,b,c,d) __syscall_cp(SYS_wait4,a,b,c,d) diff --git a/system/lib/libc/musl/src/internal/vdso.c b/system/lib/libc/musl/src/internal/vdso.c index d46d32281e649..2b6e1ae2893d1 100644 --- a/system/lib/libc/musl/src/internal/vdso.c +++ b/system/lib/libc/musl/src/internal/vdso.c @@ -40,6 +40,24 @@ static int checkver(Verdef *def, int vsym, const char *vername, char *strings) #define OK_TYPES (1< nsym) + nsym = buckets[i]; + } + if (nsym) { + hashval = buckets + gh[0] + (nsym - gh[1]); + do nsym++; + while (!(*hashval++ & 1)); + } + return nsym; +} + + void *__vdsosym(const char *vername, const char *name) { size_t i; @@ -60,6 +78,7 @@ void *__vdsosym(const char *vername, const char *name) char *strings = 0; Sym *syms = 0; Elf_Symndx *hashtab = 0; + uint32_t *ghashtab = 0; uint16_t *versym = 0; Verdef *verdef = 0; @@ -69,15 +88,20 @@ void *__vdsosym(const char *vername, const char *name) case DT_STRTAB: strings = p; break; case DT_SYMTAB: syms = p; break; case DT_HASH: hashtab = p; break; + case DT_GNU_HASH: ghashtab = p; break; case DT_VERSYM: versym = p; break; case DT_VERDEF: verdef = p; break; } } - if (!strings || !syms || !hashtab) return 0; + if (!strings || !syms) return 0; if (!verdef) versym = 0; + size_t nsym = 0; + + if (hashtab) nsym = hashtab[1]; + else if (ghashtab) nsym = count_syms_gnu(ghashtab); - for (i=0; i>4) & OK_BINDS)) continue; if (!syms[i].st_shndx) continue; diff --git a/system/lib/libc/musl/src/internal/version.h b/system/lib/libc/musl/src/internal/version.h index a324baa3e16fb..b426e1a4def13 100644 --- a/system/lib/libc/musl/src/internal/version.h +++ b/system/lib/libc/musl/src/internal/version.h @@ -1 +1 @@ -#define VERSION "1.2.5" +#define VERSION "1.2.6" diff --git a/system/lib/libc/musl/src/legacy/getusershell.c b/system/lib/libc/musl/src/legacy/getusershell.c index 5fecdec2e4419..1c5d98ec0e6cf 100644 --- a/system/lib/libc/musl/src/legacy/getusershell.c +++ b/system/lib/libc/musl/src/legacy/getusershell.c @@ -25,8 +25,10 @@ char *getusershell(void) ssize_t l; if (!f) setusershell(); if (!f) return 0; - l = getline(&line, &linesize, f); - if (l <= 0) return 0; + do { + l = getline(&line, &linesize, f); + if (l <= 0) return 0; + } while (line[0] == '#' || line[0] == '\n'); if (line[l-1]=='\n') line[l-1]=0; return line; } diff --git a/system/lib/libc/musl/src/linux/renameat2.c b/system/lib/libc/musl/src/linux/renameat2.c new file mode 100644 index 0000000000000..b806038890d26 --- /dev/null +++ b/system/lib/libc/musl/src/linux/renameat2.c @@ -0,0 +1,11 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int renameat2(int oldfd, const char *old, int newfd, const char *new, unsigned flags) +{ +#ifdef SYS_renameat + if (!flags) return syscall(SYS_renameat, oldfd, old, newfd, new); +#endif + return syscall(SYS_renameat2, oldfd, old, newfd, new, flags); +} diff --git a/system/lib/libc/musl/src/linux/statx.c b/system/lib/libc/musl/src/linux/statx.c index 0245e34608bcd..95307eaaa4ee3 100644 --- a/system/lib/libc/musl/src/linux/statx.c +++ b/system/lib/libc/musl/src/linux/statx.c @@ -23,8 +23,11 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct ret = fstatat(dirfd, path, &st, flags); if (ret) return ret; + *stx = (struct statx){0}; stx->stx_dev_major = major(st.st_dev); stx->stx_dev_minor = minor(st.st_dev); + stx->stx_rdev_major = major(st.st_rdev); + stx->stx_rdev_minor = minor(st.st_rdev); stx->stx_ino = st.st_ino; stx->stx_mode = st.st_mode; stx->stx_nlink = st.st_nlink; @@ -39,7 +42,6 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct stx->stx_mtime.tv_nsec = st.st_mtim.tv_nsec; stx->stx_ctime.tv_sec = st.st_ctim.tv_sec; stx->stx_ctime.tv_nsec = st.st_ctim.tv_nsec; - stx->stx_btime = (struct statx_timestamp){.tv_sec=0, .tv_nsec=0}; stx->stx_mask = STATX_BASIC_STATS; return 0; diff --git a/system/lib/libc/musl/src/locale/bind_textdomain_codeset.c b/system/lib/libc/musl/src/locale/bind_textdomain_codeset.c index 5ebfd5e8a818f..240e83edffeff 100644 --- a/system/lib/libc/musl/src/locale/bind_textdomain_codeset.c +++ b/system/lib/libc/musl/src/locale/bind_textdomain_codeset.c @@ -5,7 +5,9 @@ char *bind_textdomain_codeset(const char *domainname, const char *codeset) { - if (codeset && strcasecmp(codeset, "UTF-8")) + if (codeset && strcasecmp(codeset, "UTF-8")) { errno = EINVAL; - return NULL; + return 0; + } + return "UTF-8"; } diff --git a/system/lib/libc/musl/src/locale/codepages.h b/system/lib/libc/musl/src/locale/codepages.h index 4e236ef3abee8..a254f0f58781b 100644 --- a/system/lib/libc/musl/src/locale/codepages.h +++ b/system/lib/libc/musl/src/locale/codepages.h @@ -286,6 +286,17 @@ "\323\174\103\215\64\365\124\123\213\77\336\150\263\115\66\375\164\363\12\55" "\255\304\42\261\57\266\234\162\17\56\260\240\162\113\56\263\310\62\66\50" +"cp858\0" +"\0\40" +"\307\360\223\216\70\344\200\123\316\71\352\254\203\316\73\356\260\103\114\61" +"\311\230\143\14\75\366\310\263\117\76\377\130\303\15\76\243\140\163\15\135" +"\341\264\63\217\76\361\104\243\212\56\277\270\302\112\57\274\204\262\312\56" +"\140\207\55\66\315\72\7\43\14\60\251\104\375\163\321\113\213\122\212\315" +"\67\363\274\163\316\63\367\74\316\60\110\13\175\65\325\116\373\254\65\51" +"\360\100\243\314\62\310\220\334\214\63\317\340\134\163\327\134\233\302\314\326" +"\323\174\103\215\64\365\124\123\213\77\336\150\263\115\66\375\164\363\12\55" +"\255\304\42\261\57\266\234\162\17\56\260\240\162\113\56\263\310\62\66\50" + "cp866\0" "\0\40" "\337\201\27\236\170\343\221\127\236\171\347\241\227\236\172" diff --git a/system/lib/libc/musl/src/locale/iconv.c b/system/lib/libc/musl/src/locale/iconv.c index 3dd9fd902e09d..52178950d470c 100644 --- a/system/lib/libc/musl/src/locale/iconv.c +++ b/system/lib/libc/musl/src/locale/iconv.c @@ -52,7 +52,7 @@ static const unsigned char charmaps[] = "shiftjis\0sjis\0cp932\0\0\321" "iso2022jp\0\0\322" "gb18030\0\0\330" -"gbk\0\0\331" +"gbk\0cp936\0windows936\0\0\331" "gb2312\0\0\332" "big5\0bigfive\0cp950\0big5hkscs\0\0\340" "euckr\0ksc5601\0ksx1001\0cp949\0\0\350" @@ -339,7 +339,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri } else if (d-159 <= 252-159) { c++; d -= 159; + } else { + goto ilseq; } + if (c>=84) goto ilseq; c = jis0208[c][d]; if (!c) goto ilseq; break; @@ -403,6 +406,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri if (c < 128) break; if (c < 0xa1) goto ilseq; case GBK: + if (c == 128) { + c = 0x20ac; + break; + } case GB18030: if (c < 128) break; c -= 0x81; diff --git a/system/lib/libc/musl/src/math/fma.c b/system/lib/libc/musl/src/math/fma.c index 5336a2d504467..6b1a6d02a01c5 100644 --- a/system/lib/libc/musl/src/math/fma.c +++ b/system/lib/libc/musl/src/math/fma.c @@ -55,7 +55,7 @@ double fma(double x, double y, double z) return x*y + z; if (nz.e >= ZEROINFNAN) { if (nz.e > ZEROINFNAN) /* z==0 */ - return x*y + z; + return x*y; return z; } diff --git a/system/lib/libc/musl/src/math/powl.c b/system/lib/libc/musl/src/math/powl.c index 6f64ea71182d8..9eb2216205e17 100644 --- a/system/lib/libc/musl/src/math/powl.c +++ b/system/lib/libc/musl/src/math/powl.c @@ -57,14 +57,6 @@ * IEEE 0,8700 60000 6.5e-18 1.0e-18 * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed. * - * - * ERROR MESSAGES: - * - * message condition value returned - * pow overflow x**y > MAXNUM INFINITY - * pow underflow x**y < 1/MAXNUM 0.0 - * pow domain x<0 and y noninteger 0.0 - * */ #include "libm.h" diff --git a/system/lib/libc/musl/src/misc/initgroups.c b/system/lib/libc/musl/src/misc/initgroups.c index 922a958142b0a..101f5c7b0363a 100644 --- a/system/lib/libc/musl/src/misc/initgroups.c +++ b/system/lib/libc/musl/src/misc/initgroups.c @@ -1,11 +1,29 @@ #define _GNU_SOURCE #include #include +#include int initgroups(const char *user, gid_t gid) { - gid_t groups[NGROUPS_MAX]; - int count = NGROUPS_MAX; - if (getgrouplist(user, gid, groups, &count) < 0) return -1; - return setgroups(count, groups); + gid_t buf[32], *groups = buf; + int count = sizeof buf / sizeof *buf, prev_count = count; + while (getgrouplist(user, gid, groups, &count) < 0) { + if (groups != buf) free(groups); + + /* Return if failure isn't buffer size */ + if (count <= prev_count) + return -1; + + /* Always increase by at least 50% to limit to + * logarithmically many retries on TOCTOU races. */ + if (count < prev_count + (prev_count>>1)) + count = prev_count + (prev_count>>1); + + groups = calloc(count, sizeof *groups); + if (!groups) return -1; + prev_count = count; + } + int ret = setgroups(count, groups); + if (groups != buf) free(groups); + return ret; } diff --git a/system/lib/libc/musl/src/misc/mntent.c b/system/lib/libc/musl/src/misc/mntent.c index 78bf0cd0f52fa..76f9c16271685 100644 --- a/system/lib/libc/musl/src/misc/mntent.c +++ b/system/lib/libc/musl/src/misc/mntent.c @@ -81,7 +81,7 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle len = strlen(linebuf); if (len > INT_MAX) continue; for (i = 0; i < sizeof n / sizeof *n; i++) n[i] = len; - sscanf(linebuf, " %n%*[^ \t]%n %n%*[^ \t]%n %n%*[^ \t]%n %n%*[^ \t]%n %d %d", + sscanf(linebuf, " %n%*[^ \t\n]%n %n%*[^ \t\n]%n %n%*[^ \t\n]%n %n%*[^ \t\n]%n %d %d", n, n+1, n+2, n+3, n+4, n+5, n+6, n+7, &mnt->mnt_freq, &mnt->mnt_passno); } while (linebuf[n[0]] == '#' || n[1]==len); @@ -115,5 +115,13 @@ int addmntent(FILE *f, const struct mntent *mnt) char *hasmntopt(const struct mntent *mnt, const char *opt) { - return strstr(mnt->mnt_opts, opt); + size_t l = strlen(opt); + char *p = mnt->mnt_opts; + for (;;) { + if (!strncmp(p, opt, l) && (!p[l] || p[l]==',' || p[l]=='=')) + return p; + p = strchr(p, ','); + if (!p) return 0; + p++; + } } diff --git a/system/lib/libc/musl/src/multibyte/mbsnrtowcs.c b/system/lib/libc/musl/src/multibyte/mbsnrtowcs.c index 931192e2d83c4..47cbdc0044967 100644 --- a/system/lib/libc/musl/src/multibyte/mbsnrtowcs.c +++ b/system/lib/libc/musl/src/multibyte/mbsnrtowcs.c @@ -2,11 +2,13 @@ size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, size_t wn, mbstate_t *restrict st) { + static unsigned internal_state; size_t l, cnt=0, n2; wchar_t *ws, wbuf[256]; const char *s = *src; const char *tmp_s; + if (!st) st = (void *)&internal_state; if (!wcs) ws = wbuf, wn = sizeof wbuf / sizeof *wbuf; else ws = wcs; @@ -41,8 +43,8 @@ size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, si s = 0; break; } - /* have to roll back partial character */ - *(unsigned *)st = 0; + s += n; + n -= n; break; } s += l; n -= l; diff --git a/system/lib/libc/musl/src/network/getifaddrs.c b/system/lib/libc/musl/src/network/getifaddrs.c index 74df4d6c6a211..55039bd89682e 100644 --- a/system/lib/libc/musl/src/network/getifaddrs.c +++ b/system/lib/libc/musl/src/network/getifaddrs.c @@ -13,8 +13,8 @@ /* getifaddrs() reports hardware addresses with PF_PACKET that implies * struct sockaddr_ll. But e.g. Infiniband socket address length is - * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct - * to extend ssl_addr - callers should be able to still use it. */ + * longer than sockaddr_ll.sll_addr[8] can hold. Use this hack struct + * to extend sll_addr - callers should be able to still use it. */ struct sockaddr_ll_hack { unsigned short sll_family, sll_protocol; int sll_ifindex; diff --git a/system/lib/libc/musl/src/network/inet_ntop.c b/system/lib/libc/musl/src/network/inet_ntop.c index 4bfef2c557ab4..f442f47d7b5aa 100644 --- a/system/lib/libc/musl/src/network/inet_ntop.c +++ b/system/lib/libc/musl/src/network/inet_ntop.c @@ -34,7 +34,12 @@ const char *inet_ntop(int af, const void *restrict a0, char *restrict s, socklen for (i=best=0, max=2; buf[i]; i++) { if (i && buf[i] != ':') continue; j = strspn(buf+i, ":0"); - if (j>max) best=i, max=j; + /* The leading sequence of zeros (best==0) is + * disadvantaged compared to sequences elsewhere + * as it doesn't have a leading colon. One extra + * character is required for another sequence to + * beat it fairly. */ + if (j>max+(best==0)) best=i, max=j; } if (max>3) { buf[best] = buf[best+1] = ':'; diff --git a/system/lib/libc/musl/src/network/res_msend.c b/system/lib/libc/musl/src/network/res_msend.c index 109942806c29e..efe86a38a2c5d 100644 --- a/system/lib/libc/musl/src/network/res_msend.c +++ b/system/lib/libc/musl/src/network/res_msend.c @@ -87,8 +87,8 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries, int fd; int timeout, attempts, retry_interval, servfail_retry; union { - struct sockaddr_in sin; struct sockaddr_in6 sin6; + struct sockaddr_in sin; } sa = {0}, ns[MAXNS] = {{0}}; socklen_t sl = sizeof sa.sin; int nns = 0; diff --git a/system/lib/libc/musl/src/passwd/getgr_a.c b/system/lib/libc/musl/src/passwd/getgr_a.c index afeb1eceb5f86..8455040458017 100644 --- a/system/lib/libc/musl/src/passwd/getgr_a.c +++ b/system/lib/libc/musl/src/passwd/getgr_a.c @@ -71,6 +71,10 @@ int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t goto cleanup_f; } + if (groupbuf[GRMEMCNT] > (size_t)(INT32_MAX-1)) { + rv = ENOMEM; + goto cleanup_f; + } if (groupbuf[GRNAMELEN] > SIZE_MAX - groupbuf[GRPASSWDLEN]) { rv = ENOMEM; goto cleanup_f; @@ -127,7 +131,13 @@ int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t if (groupbuf[GRMEMCNT]) { mem[0][0] = *buf + groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN]; for (ptr = mem[0][0], i = 0; ptr != mem[0][0]+grlist_len; ptr++) - if (!*ptr) mem[0][++i] = ptr+1; + if (!*ptr) + if (i #include +#include #include "syscall.h" int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) { if (ss) { - if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) { + size_t min = sysconf(_SC_MINSIGSTKSZ); + if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < min) { errno = ENOMEM; return -1; } diff --git a/system/lib/libc/musl/src/signal/siglongjmp.c b/system/lib/libc/musl/src/signal/siglongjmp.c index bc317acce9317..53789b23959ed 100644 --- a/system/lib/libc/musl/src/signal/siglongjmp.c +++ b/system/lib/libc/musl/src/signal/siglongjmp.c @@ -5,5 +5,10 @@ _Noreturn void siglongjmp(sigjmp_buf buf, int ret) { + /* If sigsetjmp was called with nonzero savemask flag, the address + * longjmp will return to is inside of sigsetjmp. The signal mask + * will then be restored in the returned-to context instead of here, + * which matters if the context we are returning from may not have + * sufficient stack space for signal delivery. */ longjmp(buf, ret); } diff --git a/system/lib/libc/musl/src/signal/sigpause.c b/system/lib/libc/musl/src/signal/sigpause.c index 363d2fec27f9c..1587c3918da67 100644 --- a/system/lib/libc/musl/src/signal/sigpause.c +++ b/system/lib/libc/musl/src/signal/sigpause.c @@ -4,6 +4,6 @@ int sigpause(int sig) { sigset_t mask; sigprocmask(0, 0, &mask); - sigdelset(&mask, sig); + if (sigdelset(&mask, sig)) return -1; return sigsuspend(&mask); } diff --git a/system/lib/libc/musl/src/stdio/__stdio_write.c b/system/lib/libc/musl/src/stdio/__stdio_write.c index cce9f6a16a558..7a125b89b928d 100644 --- a/system/lib/libc/musl/src/stdio/__stdio_write.c +++ b/system/lib/libc/musl/src/stdio/__stdio_write.c @@ -11,6 +11,11 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) size_t rem = iov[0].iov_len + iov[1].iov_len; int iovcnt = 2; ssize_t cnt; + + if (!iov->iov_len) { + iov++; + iovcnt--; + } for (;;) { #if __EMSCRIPTEN__ size_t num; diff --git a/system/lib/libc/musl/src/stdio/vfprintf.c b/system/lib/libc/musl/src/stdio/vfprintf.c index c0542b599024c..96779841164ce 100644 --- a/system/lib/libc/musl/src/stdio/vfprintf.c +++ b/system/lib/libc/musl/src/stdio/vfprintf.c @@ -210,7 +210,8 @@ static char *fmt_u(uintmax_t x, char *s) { unsigned long y; for ( ; x>ULONG_MAX; x/=10) *--s = '0' + x%10; - for (y=x; y; y/=10) *--s = '0' + y%10; + for (y=x; y>=10; y/=10) *--s = '0' + y%10; + if (y) *--s = '0' + y; return s; } @@ -225,12 +226,18 @@ typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long_double) // get it linked in // also use a double argument here, as mentioned before, // we print float128s at double precision -typedef int (*fmt_fp_t)(FILE *f, long_double y, int w, int p, int fl, int t); +typedef int (*fmt_fp_t)(FILE *f, long_double y, int w, int p, int fl, int t, int ps); -static int fmt_fp(FILE *f, long_double y, int w, int p, int fl, int t) +static int fmt_fp(FILE *f, long_double y, int w, int p, int fl, int t, int ps) { - uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion - + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion + int max_mant_dig = (ps==BIGLPRE) ? LDBL_MANT_DIG : DBL_MANT_DIG; + int max_exp = (ps==BIGLPRE) ? LDBL_MAX_EXP : DBL_MAX_EXP; + /* One slot for 29 bits left of radix point, a slot for every 29-21=8 + * bits right of the radix point, and one final zero slot. */ + int max_mant_slots = 1 + (max_mant_dig-29+7)/8 + 1; + int max_exp_slots = (max_exp+max_mant_dig+28+8)/9; + int bufsize = max_mant_slots + max_exp_slots; + uint32_t big[bufsize]; uint32_t *a, *d, *r, *z; int e2=0, e, i, j, l; char buf[9+LDBL_MANT_DIG/4], *s; @@ -261,18 +268,11 @@ static int fmt_fp(FILE *f, long_double y, int w, int p, int fl, int t) if (y) e2--; if ((t|32)=='a') { - long_double round = 8.0; - int re; - if (t&32) prefix += 9; pl += 2; - if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0; - else re=LDBL_MANT_DIG/4-1-p; - - if (re) { - round *= 1<<(LDBL_MANT_DIG%4); - while (re--) round*=16; + if (p>=0 && p<(LDBL_MANT_DIG-1+3)/4) { + double round = scalbn(1, LDBL_MANT_DIG-1-(p*4)); if (*prefix=='-') { y=-y; y-=round; @@ -318,7 +318,7 @@ static int fmt_fp(FILE *f, long_double y, int w, int p, int fl, int t) if (y) y *= 0x1p28, e2-=28; if (e2<0) a=r=z=big; - else a=r=z=big+sizeof(big)/sizeof(*big) - LDBL_MANT_DIG - 1; + else a=r=z=big+sizeof(big)/sizeof(*big) - max_mant_slots - 1; do { *z = y; @@ -615,11 +615,11 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, case 'x': case 'X': a = fmt_x(arg.i, z, t&32); if (arg.i && (fl & ALT_FORM)) prefix+=(t>>4), pl=2; - if (0) { + goto ifmt_tail; case 'o': a = fmt_o(arg.i, z); if ((fl&ALT_FORM) && pINTMAX_MAX) { @@ -631,7 +631,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, } else pl=0; case 'u': a = fmt_u(arg.i, z); - } + ifmt_tail: if (xp && p<0) goto overflow; if (xp) fl &= ~ZERO_PAD; if (!arg.i && !p) { @@ -678,7 +678,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, case 'e': case 'f': case 'g': case 'a': case 'E': case 'F': case 'G': case 'A': if (xp && p<0) goto overflow; - l = fmt_fp(f, arg.f, w, p, fl, t); + l = fmt_fp(f, arg.f, w, p, fl, t, ps); if (l<0) goto overflow; continue; } diff --git a/system/lib/libc/musl/src/stdlib/qsort.c b/system/lib/libc/musl/src/stdlib/qsort.c index 314ddc29da1db..ab79dc6f40899 100644 --- a/system/lib/libc/musl/src/stdlib/qsort.c +++ b/system/lib/libc/musl/src/stdlib/qsort.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 by Valentin Ochs +/* Copyright (C) 2011 by Lynn Ochs * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to diff --git a/system/lib/libc/musl/src/string/strcasestr.c b/system/lib/libc/musl/src/string/strcasestr.c index af109f3611bd4..dc598bc388f71 100644 --- a/system/lib/libc/musl/src/string/strcasestr.c +++ b/system/lib/libc/musl/src/string/strcasestr.c @@ -4,6 +4,7 @@ char *strcasestr(const char *h, const char *n) { size_t l = strlen(n); + if (!l) return (char *)h; for (; *h; h++) if (!strncasecmp(h, n, l)) return (char *)h; return 0; } diff --git a/system/lib/libc/musl/src/termios/cfgetospeed.c b/system/lib/libc/musl/src/termios/cfgetospeed.c index 55fa6f55c0ecb..de46a1d8a7f84 100644 --- a/system/lib/libc/musl/src/termios/cfgetospeed.c +++ b/system/lib/libc/musl/src/termios/cfgetospeed.c @@ -9,5 +9,5 @@ speed_t cfgetospeed(const struct termios *tio) speed_t cfgetispeed(const struct termios *tio) { - return cfgetospeed(tio); + return (tio->c_cflag & CIBAUD) / (CIBAUD/CBAUD); } diff --git a/system/lib/libc/musl/src/termios/cfsetospeed.c b/system/lib/libc/musl/src/termios/cfsetospeed.c index c9cbdd9d9d2e1..3eab092afa522 100644 --- a/system/lib/libc/musl/src/termios/cfsetospeed.c +++ b/system/lib/libc/musl/src/termios/cfsetospeed.c @@ -16,7 +16,11 @@ int cfsetospeed(struct termios *tio, speed_t speed) int cfsetispeed(struct termios *tio, speed_t speed) { - return speed ? cfsetospeed(tio, speed) : 0; + if (speed & ~CBAUD) { + errno = EINVAL; + return -1; + } + tio->c_cflag &= ~CIBAUD; + tio->c_cflag |= speed * (CIBAUD/CBAUD); + return 0; } - -weak_alias(cfsetospeed, cfsetspeed); diff --git a/system/lib/libc/musl/src/termios/cfsetspeed.c b/system/lib/libc/musl/src/termios/cfsetspeed.c new file mode 100644 index 0000000000000..2c369db93017b --- /dev/null +++ b/system/lib/libc/musl/src/termios/cfsetspeed.c @@ -0,0 +1,11 @@ +#define _BSD_SOURCE +#include +#include +#include + +int cfsetspeed(struct termios *tio, speed_t speed) +{ + int r = cfsetospeed(tio, speed); + if (!r) cfsetispeed(tio, 0); + return r; +} diff --git a/system/lib/libc/musl/src/thread/sem_post.c b/system/lib/libc/musl/src/thread/sem_post.c index 5c2517f23606d..1c8f763cacbd0 100644 --- a/system/lib/libc/musl/src/thread/sem_post.c +++ b/system/lib/libc/musl/src/thread/sem_post.c @@ -16,6 +16,6 @@ int sem_post(sem_t *sem) if (waiters <= 1) new &= ~0x80000000; } while (a_cas(sem->__val, val, new) != val); - if (val<0) __wake(sem->__val, waiters>1 ? 1 : -1, priv); + if (val<0 || waiters) __wake(sem->__val, waiters>1 ? 1 : -1, priv); return 0; } diff --git a/system/lib/libc/musl/src/time/__tz.c b/system/lib/libc/musl/src/time/__tz.c index 1aac321562e3a..7da45f88ca43d 100644 --- a/system/lib/libc/musl/src/time/__tz.c +++ b/system/lib/libc/musl/src/time/__tz.c @@ -29,7 +29,6 @@ weak_alias(__tzname, tzname); static char std_name[TZNAME_MAX+1]; static char dst_name[TZNAME_MAX+1]; -weak const char __utc[] = "UTC"; static int dst_off; static int r0[5], r1[5]; diff --git a/system/lib/libc/musl/src/time/__utc.c b/system/lib/libc/musl/src/time/__utc.c new file mode 100644 index 0000000000000..bf658341cd11a --- /dev/null +++ b/system/lib/libc/musl/src/time/__utc.c @@ -0,0 +1,3 @@ +#include "time_impl.h" + +weak const char __utc[] = "UTC"; diff --git a/system/lib/libc/musl/src/time/strptime.c b/system/lib/libc/musl/src/time/strptime.c index c54a0d8c4c52e..b114724286b79 100644 --- a/system/lib/libc/musl/src/time/strptime.c +++ b/system/lib/libc/musl/src/time/strptime.c @@ -59,6 +59,22 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri s = strptime(s, "%m/%d/%y", tm); if (!s) return 0; break; + case 'F': + /* Use temp buffer to implement the odd requirement + * that entire field be width-limited but the year + * subfield not itself be limited. */ + i = 0; + char tmp[20]; + if (*s == '-' || *s == '+') tmp[i++] = *s++; + while (*s=='0' && isdigit(s[1])) s++; + for (; *s && i<(size_t)w && i+1tm_hour; min = 0; @@ -114,6 +130,13 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri s = strptime(s, "%H:%M", tm); if (!s) return 0; break; + case 's': + /* Parse only. Effect on tm is unspecified + * and presently no effect is implemented.. */ + if (*s == '-') s++; + if (!isdigit(*s)) return 0; + while (isdigit(*s)) s++; + break; case 'S': dest = &tm->tm_sec; min = 0; @@ -125,11 +148,30 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri break; case 'U': case 'W': - /* Throw away result, for now. (FIXME?) */ + /* Throw away result of %U, %V, %W, %g, and %G. Effect + * is unspecified and there is no clear right choice. */ dest = &dummy; min = 0; range = 54; goto numeric_range; + case 'V': + dest = &dummy; + min = 1; + range = 53; + goto numeric_range; + case 'g': + dest = &dummy; + w = 2; + goto numeric_digits; + case 'G': + dest = &dummy; + if (w<0) w=4; + goto numeric_digits; + case 'u': + dest = &tm->tm_wday; + min = 1; + range = 7; + goto numeric_range; case 'w': dest = &tm->tm_wday; min = 0; @@ -154,6 +196,28 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri adj = 1900; want_century = 0; goto numeric_digits; + case 'z': + if (*s == '+') neg = 0; + else if (*s == '-') neg = 1; + else return 0; + for (i=0; i<4; i++) if (!isdigit(s[1+i])) return 0; + tm->__tm_gmtoff = (s[1]-'0')*36000+(s[2]-'0')*3600 + + (s[3]-'0')*600 + (s[4]-'0')*60; + if (neg) tm->__tm_gmtoff = -tm->__tm_gmtoff; + s += 5; + break; + case 'Z': + if (!strncmp(s, tzname[0], len = strlen(tzname[0]))) { + tm->tm_isdst = 0; + s += len; + } else if (!strncmp(s, tzname[1], len=strlen(tzname[1]))) { + tm->tm_isdst = 1; + s += len; + } else { + /* FIXME: is this supposed to be an error? */ + while ((*s|32)-'a' <= 'z'-'a') s++; + } + break; case '%': if (*s++ != '%') return 0; break; diff --git a/system/lib/libc/musl/src/time/timer_create.c b/system/lib/libc/musl/src/time/timer_create.c index 9216b3abc5689..cc6c2236753e7 100644 --- a/system/lib/libc/musl/src/time/timer_create.c +++ b/system/lib/libc/musl/src/time/timer_create.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "pthread_impl.h" #include "atomic.h" @@ -12,7 +13,7 @@ struct ksigevent { }; struct start_args { - pthread_barrier_t b; + sem_t sem1, sem2; struct sigevent *sev; }; @@ -21,10 +22,16 @@ static void dummy_0() } weak_alias(dummy_0, __pthread_tsd_run_dtors); +static void timer_handler(int sig, siginfo_t *si, void *ctx) +{ +} + static void cleanup_fromsig(void *p) { pthread_t self = __pthread_self(); __pthread_tsd_run_dtors(); + __block_app_sigs(0); + __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGTIMER_SET, 0, _NSIG/8); self->cancel = 0; self->cancelbuf = 0; self->canceldisable = 0; @@ -42,7 +49,14 @@ static void *start(void *arg) void (*notify)(union sigval) = args->sev->sigev_notify_function; union sigval val = args->sev->sigev_value; - pthread_barrier_wait(&args->b); + /* The two-way semaphore synchronization ensures that we see + * self->cancel set by the parent if timer creation failed or + * self->timer_id if it succeeded, and informs the parent that + * we are done accessing the arguments so that the parent can + * proceed past their block lifetime. */ + while (sem_wait(&args->sem1)); + sem_post(&args->sem2); + if (self->cancel) return 0; for (;;) { @@ -90,7 +104,10 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict break; case SIGEV_THREAD: if (!init) { - struct sigaction sa = { .sa_handler = SIG_DFL }; + struct sigaction sa = { + .sa_sigaction = timer_handler, + .sa_flags = SA_SIGINFO | SA_RESTART + }; __libc_sigaction(SIGTIMER, &sa, 0); a_store(&init, 1); } @@ -99,7 +116,8 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict else pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_barrier_init(&args.b, 0, 2); + sem_init(&args.sem1, 0, 0); + sem_init(&args.sem2, 0, 0); args.sev = evp; __block_app_sigs(&set); @@ -120,7 +138,8 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict td->cancel = 1; } td->timer_id = timerid; - pthread_barrier_wait(&args.b); + sem_post(&args.sem1); + while (sem_wait(&args.sem2)); if (timerid < 0) return -1; *res = (void *)(INTPTR_MIN | (uintptr_t)td>>1); break; diff --git a/system/lib/libc/musl/src/unistd/isatty.c b/system/lib/libc/musl/src/unistd/isatty.c index 1e41a6edbd1aa..fe922d465bffb 100644 --- a/system/lib/libc/musl/src/unistd/isatty.c +++ b/system/lib/libc/musl/src/unistd/isatty.c @@ -1,6 +1,3 @@ -#ifdef __EMSCRIPTEN__ -#include -#endif #include #include #include @@ -26,9 +23,7 @@ int isatty(int fd) return 1; #else struct winsize wsz; - unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz); - if (r == 0) return 1; - if (errno != EBADF) errno = ENOTTY; - return 0; + /* +1 converts from error status (0/-1) to boolean (1/0) */ + return syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz) + 1; #endif } diff --git a/system/lib/libc/musl/src/unistd/pause.c b/system/lib/libc/musl/src/unistd/pause.c index 90bbf4ca8ab53..90cc8db57b275 100644 --- a/system/lib/libc/musl/src/unistd/pause.c +++ b/system/lib/libc/musl/src/unistd/pause.c @@ -3,9 +3,5 @@ int pause(void) { -#ifdef SYS_pause - return syscall_cp(SYS_pause); -#else - return syscall_cp(SYS_ppoll, 0, 0, 0, 0); -#endif + return sys_pause_cp(); } diff --git a/system/lib/libc/musl/src/unistd/pwrite.c b/system/lib/libc/musl/src/unistd/pwrite.c index 3573ab3902f82..4b2035ade9ea4 100644 --- a/system/lib/libc/musl/src/unistd/pwrite.c +++ b/system/lib/libc/musl/src/unistd/pwrite.c @@ -1,4 +1,7 @@ +#define _GNU_SOURCE #include +#include +#include #include "syscall.h" ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) @@ -14,6 +17,14 @@ ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) } return num; #else + if (ofs == -1) ofs--; + int r = __syscall_cp(SYS_pwritev2, fd, + (&(struct iovec){ .iov_base = (void *)buf, .iov_len = size }), + 1, (long)(ofs), (long)(ofs>>32), RWF_NOAPPEND); + if (r != -EOPNOTSUPP && r != -ENOSYS) + return __syscall_ret(r); + if (fcntl(fd, F_GETFL) & O_APPEND) + return __syscall_ret(-EOPNOTSUPP); return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs)); #endif } diff --git a/system/lib/libc/musl/src/unistd/pwritev.c b/system/lib/libc/musl/src/unistd/pwritev.c index bb44236c51ef7..d4f03899d73d0 100644 --- a/system/lib/libc/musl/src/unistd/pwritev.c +++ b/system/lib/libc/musl/src/unistd/pwritev.c @@ -1,6 +1,7 @@ -#define _BSD_SOURCE +#define _GNU_SOURCE #include #include +#include #include "syscall.h" ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) @@ -12,6 +13,13 @@ ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) } return num; #else + if (ofs == -1) ofs--; + int r = __syscall_cp(SYS_pwritev2, fd, iov, count, + (long)(ofs), (long)(ofs>>32), RWF_NOAPPEND); + if (r != -EOPNOTSUPP && r != -ENOSYS) + return __syscall_ret(r); + if (fcntl(fd, F_GETFL) & O_APPEND) + return __syscall_ret(-EOPNOTSUPP); return syscall_cp(SYS_pwritev, fd, iov, count, (long)(ofs), (long)(ofs>>32)); #endif diff --git a/system/lib/update_musl.py b/system/lib/update_musl.py index a13debc2dfb76..262717c6fd3f1 100755 --- a/system/lib/update_musl.py +++ b/system/lib/update_musl.py @@ -31,9 +31,11 @@ # Parts of src we don't build 'malloc', # Arch-specific code we don't use - 'arm', 'x32', 'sh', 'i386', 'x86_64', 'aarch64', 'riscv64', - 's390x', 'mips', 'mips64', 'mipsn32', 'powerpc', 'powerpc64', - 'm68k', 'microblaze', 'or1k') + 'aarch64', 'arm', 'i386', 'loongarch64', 'm68k', + 'microblaze', 'mips', 'mips64', 'mipsn32', 'or1k', + 'powerpc', 'powerpc64', 'riscv32', 'riscv64', 's390x', + 'sh', 'x32', 'x86_64' +) exclude_files = ( 'aio.h', 'sendfile.h', diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index 2c79cb1867c54..573557ccf688e 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { "a.out.js": 19260, "a.out.js.gz": 7991, - "a.out.nodebug.wasm": 132627, - "a.out.nodebug.wasm.gz": 49921, - "total": 151887, - "total_gz": 57912, + "a.out.nodebug.wasm": 132680, + "a.out.nodebug.wasm.gz": 49972, + "total": 151940, + "total_gz": 57963, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index 804f183eeb82f..a91d5516b555e 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { "a.out.js": 19237, "a.out.js.gz": 7978, - "a.out.nodebug.wasm": 132055, - "a.out.nodebug.wasm.gz": 49575, - "total": 151292, - "total_gz": 57553, + "a.out.nodebug.wasm": 132109, + "a.out.nodebug.wasm.gz": 49634, + "total": 151346, + "total_gz": 57612, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index d4b61ac6a1c85..65d657c9629cb 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { "a.out.js": 23240, "a.out.js.gz": 8978, - "a.out.nodebug.wasm": 172526, - "a.out.nodebug.wasm.gz": 57447, - "total": 195766, - "total_gz": 66425, + "a.out.nodebug.wasm": 172611, + "a.out.nodebug.wasm.gz": 57524, + "total": 195851, + "total_gz": 66502, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_except_wasm.json b/test/codesize/test_codesize_cxx_except_wasm.json index 69dbaf45c33db..bc5c31364bd50 100644 --- a/test/codesize/test_codesize_cxx_except_wasm.json +++ b/test/codesize/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { "a.out.js": 19092, "a.out.js.gz": 7925, - "a.out.nodebug.wasm": 147926, - "a.out.nodebug.wasm.gz": 55309, - "total": 167018, - "total_gz": 63234, + "a.out.nodebug.wasm": 148017, + "a.out.nodebug.wasm.gz": 55360, + "total": 167109, + "total_gz": 63285, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_except_wasm_legacy.json b/test/codesize/test_codesize_cxx_except_wasm_legacy.json index 00312e3edb1e2..6eeac72a1326d 100644 --- a/test/codesize/test_codesize_cxx_except_wasm_legacy.json +++ b/test/codesize/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { "a.out.js": 19166, "a.out.js.gz": 7949, - "a.out.nodebug.wasm": 145732, - "a.out.nodebug.wasm.gz": 54936, - "total": 164898, - "total_gz": 62885, + "a.out.nodebug.wasm": 145823, + "a.out.nodebug.wasm.gz": 54993, + "total": 164989, + "total_gz": 62942, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_lto.json b/test/codesize/test_codesize_cxx_lto.json index 8a6f2e6c97a86..1900221377528 100644 --- a/test/codesize/test_codesize_cxx_lto.json +++ b/test/codesize/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { "a.out.js": 18629, "a.out.js.gz": 7685, - "a.out.nodebug.wasm": 101958, - "a.out.nodebug.wasm.gz": 39461, - "total": 120587, - "total_gz": 47146, + "a.out.nodebug.wasm": 101979, + "a.out.nodebug.wasm.gz": 39479, + "total": 120608, + "total_gz": 47164, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index 1a77a90940e08..933bb3d5218c4 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { "a.out.js": 23290, "a.out.js.gz": 9000, - "a.out.nodebug.wasm": 238955, - "a.out.nodebug.wasm.gz": 79818, - "total": 262245, - "total_gz": 88818, + "a.out.nodebug.wasm": 239040, + "a.out.nodebug.wasm.gz": 79876, + "total": 262330, + "total_gz": 88876, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index 32250f8e3793b..f991907c790c3 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { "a.out.js": 19260, "a.out.js.gz": 7991, - "a.out.nodebug.wasm": 134657, - "a.out.nodebug.wasm.gz": 50769, - "total": 153917, - "total_gz": 58760, + "a.out.nodebug.wasm": 134696, + "a.out.nodebug.wasm.gz": 50824, + "total": 153956, + "total_gz": 58815, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 7f6c324000085..351bfa981be4e 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { "a.out.js": 7023, "a.out.js.gz": 3310, - "a.out.nodebug.wasm": 172750, - "a.out.nodebug.wasm.gz": 63325, - "total": 179773, - "total_gz": 66635, + "a.out.nodebug.wasm": 172789, + "a.out.nodebug.wasm.gz": 63376, + "total": 179812, + "total_gz": 66686, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_file_preload.expected.js b/test/codesize/test_codesize_file_preload.expected.js index 6bbafeceff346..e152d02bcc14f 100644 --- a/test/codesize/test_codesize_file_preload.expected.js +++ b/test/codesize/test_codesize_file_preload.expected.js @@ -3028,16 +3028,16 @@ var SYSCALLS = { HEAP64[(((buf) + (24)) >> 3)] = BigInt(stat.size); HEAP32[(((buf) + (32)) >> 2)] = 4096; HEAP32[(((buf) + (36)) >> 2)] = stat.blocks; + HEAP64[(((buf) + (40)) >> 3)] = BigInt(stat.ino); var atime = stat.atime.getTime(); var mtime = stat.mtime.getTime(); var ctime = stat.ctime.getTime(); - HEAP64[(((buf) + (40)) >> 3)] = BigInt(Math.floor(atime / 1e3)); - HEAPU32[(((buf) + (48)) >> 2)] = (atime % 1e3) * 1e3 * 1e3; - HEAP64[(((buf) + (56)) >> 3)] = BigInt(Math.floor(mtime / 1e3)); - HEAPU32[(((buf) + (64)) >> 2)] = (mtime % 1e3) * 1e3 * 1e3; - HEAP64[(((buf) + (72)) >> 3)] = BigInt(Math.floor(ctime / 1e3)); - HEAPU32[(((buf) + (80)) >> 2)] = (ctime % 1e3) * 1e3 * 1e3; - HEAP64[(((buf) + (88)) >> 3)] = BigInt(stat.ino); + HEAP64[(((buf) + (48)) >> 3)] = BigInt(Math.floor(atime / 1e3)); + HEAPU32[(((buf) + (56)) >> 2)] = (atime % 1e3) * 1e3 * 1e3; + HEAP64[(((buf) + (64)) >> 3)] = BigInt(Math.floor(mtime / 1e3)); + HEAPU32[(((buf) + (72)) >> 2)] = (mtime % 1e3) * 1e3 * 1e3; + HEAP64[(((buf) + (80)) >> 3)] = BigInt(Math.floor(ctime / 1e3)); + HEAPU32[(((buf) + (88)) >> 2)] = (ctime % 1e3) * 1e3 * 1e3; return 0; }, writeStatFs(buf, stats) { diff --git a/test/codesize/test_codesize_file_preload.json b/test/codesize/test_codesize_file_preload.json index 67043ac70f5df..d4fb262fef743 100644 --- a/test/codesize/test_codesize_file_preload.json +++ b/test/codesize/test_codesize_file_preload.json @@ -1,10 +1,10 @@ { "a.out.js": 22204, "a.out.js.gz": 9207, - "a.out.nodebug.wasm": 1648, - "a.out.nodebug.wasm.gz": 938, - "total": 23852, - "total_gz": 10145, + "a.out.nodebug.wasm": 1666, + "a.out.nodebug.wasm.gz": 945, + "total": 23870, + "total_gz": 10152, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 978d779d3bcd0..0ff577f24f2ac 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { "a.out.js": 24220, "a.out.js.gz": 8713, - "a.out.nodebug.wasm": 14850, - "a.out.nodebug.wasm.gz": 7314, - "total": 39070, - "total_gz": 16027, + "a.out.nodebug.wasm": 15115, + "a.out.nodebug.wasm.gz": 7464, + "total": 39335, + "total_gz": 16177, "sent": [ "fd_write" ], @@ -71,6 +71,7 @@ "$pop_arg_long_double", "$printf", "$printf_core", + "$scalbn", "$strerror", "$strnlen", "$vfprintf", diff --git a/test/codesize/test_codesize_hello_O1.json b/test/codesize/test_codesize_hello_O1.json index 1cee141c63fce..02ca2dad0ba4f 100644 --- a/test/codesize/test_codesize_hello_O1.json +++ b/test/codesize/test_codesize_hello_O1.json @@ -1,10 +1,10 @@ { "a.out.js": 6345, "a.out.js.gz": 2456, - "a.out.nodebug.wasm": 2530, - "a.out.nodebug.wasm.gz": 1421, - "total": 8875, - "total_gz": 3877, + "a.out.nodebug.wasm": 2544, + "a.out.nodebug.wasm.gz": 1436, + "total": 8889, + "total_gz": 3892, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O2.json b/test/codesize/test_codesize_hello_O2.json index 383ae20cdc135..7a49e2f53ac7e 100644 --- a/test/codesize/test_codesize_hello_O2.json +++ b/test/codesize/test_codesize_hello_O2.json @@ -1,10 +1,10 @@ { "a.out.js": 4323, "a.out.js.gz": 2130, - "a.out.nodebug.wasm": 1898, - "a.out.nodebug.wasm.gz": 1120, - "total": 6221, - "total_gz": 3250, + "a.out.nodebug.wasm": 1912, + "a.out.nodebug.wasm.gz": 1129, + "total": 6235, + "total_gz": 3259, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O3.json b/test/codesize/test_codesize_hello_O3.json index c6cc2db3c5d91..4c64aa01850f3 100644 --- a/test/codesize/test_codesize_hello_O3.json +++ b/test/codesize/test_codesize_hello_O3.json @@ -1,10 +1,10 @@ { "a.out.js": 4265, "a.out.js.gz": 2089, - "a.out.nodebug.wasm": 1648, - "a.out.nodebug.wasm.gz": 938, - "total": 5913, - "total_gz": 3027, + "a.out.nodebug.wasm": 1666, + "a.out.nodebug.wasm.gz": 945, + "total": 5931, + "total_gz": 3034, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Os.json b/test/codesize/test_codesize_hello_Os.json index 433d6af14da02..552851389c2b6 100644 --- a/test/codesize/test_codesize_hello_Os.json +++ b/test/codesize/test_codesize_hello_Os.json @@ -1,10 +1,10 @@ { "a.out.js": 4265, "a.out.js.gz": 2089, - "a.out.nodebug.wasm": 1638, - "a.out.nodebug.wasm.gz": 941, - "total": 5903, - "total_gz": 3030, + "a.out.nodebug.wasm": 1654, + "a.out.nodebug.wasm.gz": 953, + "total": 5919, + "total_gz": 3042, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Oz.json b/test/codesize/test_codesize_hello_Oz.json index a25237d4dd55b..ace0d3116f3d6 100644 --- a/test/codesize/test_codesize_hello_Oz.json +++ b/test/codesize/test_codesize_hello_Oz.json @@ -1,10 +1,10 @@ { "a.out.js": 3900, "a.out.js.gz": 1896, - "a.out.nodebug.wasm": 1172, - "a.out.nodebug.wasm.gz": 723, - "total": 5072, - "total_gz": 2619, + "a.out.nodebug.wasm": 1188, + "a.out.nodebug.wasm.gz": 731, + "total": 5088, + "total_gz": 2627, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_dylink.json b/test/codesize/test_codesize_hello_dylink.json index 48f9a338731ef..df25556375ebc 100644 --- a/test/codesize/test_codesize_hello_dylink.json +++ b/test/codesize/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { "a.out.js": 26251, "a.out.js.gz": 11195, - "a.out.nodebug.wasm": 17671, - "a.out.nodebug.wasm.gz": 8925, - "total": 43922, - "total_gz": 20120, + "a.out.nodebug.wasm": 17861, + "a.out.nodebug.wasm.gz": 9021, + "total": 44112, + "total_gz": 20216, "sent": [ "__syscall_stat64", "emscripten_resize_heap", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index b732020df5398..71436c30986b7 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { "a.out.js": 244557, - "a.out.nodebug.wasm": 578129, - "total": 822686, + "a.out.nodebug.wasm": 578081, + "total": 822638, "sent": [ "IMG_Init", "IMG_Load", @@ -2795,6 +2795,7 @@ "posix_close", "posix_fadvise", "posix_fallocate", + "posix_getdents", "posix_madvise", "posix_memalign", "posix_openpt", @@ -3943,10 +3944,12 @@ "$cexp", "$cexpf", "$cexpl", + "$cfgetispeed", "$cfgetospeed", "$cfmakeraw", "$cfsetispeed", "$cfsetospeed", + "$cfsetspeed", "$chdir", "$checkint", "$checkint", @@ -4571,6 +4574,7 @@ "$posix_close", "$posix_fadvise", "$posix_fallocate", + "$posix_getdents", "$posix_openpt", "$posix_spawn", "$posix_spawn_file_actions_addchdir_np", diff --git a/test/codesize/test_codesize_hello_single_file.json b/test/codesize/test_codesize_hello_single_file.json index efdca993df465..6fac8a3d66292 100644 --- a/test/codesize/test_codesize_hello_single_file.json +++ b/test/codesize/test_codesize_hello_single_file.json @@ -1,6 +1,6 @@ { - "a.out.js": 5223, - "a.out.js.gz": 2887, + "a.out.js": 5241, + "a.out.js.gz": 2893, "sent": [ "a (fd_write)" ] diff --git a/test/codesize/test_codesize_hello_wasmfs.json b/test/codesize/test_codesize_hello_wasmfs.json index c6cc2db3c5d91..4c64aa01850f3 100644 --- a/test/codesize/test_codesize_hello_wasmfs.json +++ b/test/codesize/test_codesize_hello_wasmfs.json @@ -1,10 +1,10 @@ { "a.out.js": 4265, "a.out.js.gz": 2089, - "a.out.nodebug.wasm": 1648, - "a.out.nodebug.wasm.gz": 938, - "total": 5913, - "total_gz": 3027, + "a.out.nodebug.wasm": 1666, + "a.out.nodebug.wasm.gz": 945, + "total": 5931, + "total_gz": 3034, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index 695a6c895732b..f222dc49fbcd7 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { "a.out.js": 7372, "a.out.js.gz": 3594, - "a.out.nodebug.wasm": 19047, - "a.out.nodebug.wasm.gz": 8794, - "total": 26419, - "total_gz": 12388, + "a.out.nodebug.wasm": 19024, + "a.out.nodebug.wasm.gz": 8776, + "total": 26396, + "total_gz": 12370, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index f2a49a3541479..96fdadd8bd066 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { "a.out.js": 7781, "a.out.js.gz": 3797, - "a.out.nodebug.wasm": 19048, - "a.out.nodebug.wasm.gz": 8796, - "total": 26829, - "total_gz": 12593, + "a.out.nodebug.wasm": 19025, + "a.out.nodebug.wasm.gz": 8777, + "total": 26806, + "total_gz": 12574, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json index 2d6f52c4ad1e9..58825a46c4c30 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm.json @@ -1,4 +1,4 @@ { - "a.html": 10815, - "a.html.gz": 5649 + "a.html": 11057, + "a.html.gz": 5755 } diff --git a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json index abb290e68d76b..6597f80fe7fa6 100644 --- a/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json +++ b/test/codesize/test_minimal_runtime_code_size_random_printf_wasm2js.json @@ -1,4 +1,4 @@ { - "a.html": 17114, - "a.html.gz": 7478 + "a.html": 17417, + "a.html.gz": 7657 } diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 2bac6e12355a6..70c82fa5b54de 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { "hello_world.js": 56997, "hello_world.js.gz": 17742, - "hello_world.wasm": 14850, - "hello_world.wasm.gz": 7314, + "hello_world.wasm": 15115, + "hello_world.wasm.gz": 7464, "no_asserts.js": 26622, "no_asserts.js.gz": 8888, - "no_asserts.wasm": 12010, - "no_asserts.wasm.gz": 5880, + "no_asserts.wasm": 12229, + "no_asserts.wasm.gz": 6004, "strict.js": 54815, "strict.js.gz": 17049, - "strict.wasm": 14850, - "strict.wasm.gz": 7310, - "total": 180144, - "total_gz": 64183 + "strict.wasm": 15115, + "strict.wasm.gz": 7457, + "total": 180893, + "total_gz": 64604 } diff --git a/tools/system_libs.py b/tools/system_libs.py index 160b695546f83..50348a17d2057 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1365,6 +1365,7 @@ def get_files(self): '__map_file.c', 'strftime.c', '__tz.c', + '__utc.c', '__tm_to_secs.c', '__year_to_secs.c', '__month_to_secs.c', @@ -2307,6 +2308,7 @@ def get_files(self): path='system/lib/libc/musl/src/time', filenames=['__secs_to_tm.c', '__tz.c', + '__utc.c', 'gettimeofday.c', 'localtime_r.c', 'gmtime_r.c',