Skip to content

Commit 31cf2bb

Browse files
Update musl to 1.1.15 (#4813)
* Revert all emscripten musl changes * Update musl to 1.1.5 * Reapply emscripten patches * Fix up libs to partially compile * Revert emscripten musl include folder * Update musl include folder to 1.1.5 * Reapply emscripten libc include changes * Get compiling again! * Restore alltypes.h to have emscripten-specific changes alltypes.h is autogenerated, and we've since overridden the types Longer-term, we should figure out a way to either autogenerate the types to match what emscripten expects, or change emscripten's expectation to support musl's assumptions. Probably worth including with merging the asm&wasm ABIs. * Update expected langinfo test output for fixes in upstream musl * Canonicalize nans in hyperbolic test Nans are now printed out with their sign if negative. Asm and wasm treat these differently, so canonicalize how they print. * Tweak how musl forwards syscalls to emscripten Before: pass all syscall args as varargs, args are int32 After: cast all syscall args to int32, pass as varargs This fixes and prevents aliasing issues, and is more consistent with other architectures * Change __syscall to syscall in isatty to set errno POSIX specifies that isatty sets errno in the case that it fails. __syscall doesn't set errno, and syscall does. * Update struct_info again * Always allocate pthread_self, even in the stub * sys_open should call __syscall_ret * Fix up pthread js for optimized code (remove __asm: true) * Canonicalize more nans in testsuite * Re-set expected langinfo output * Update align_moar expected addresses * Disable assert in wasm_backend llseek syscall * Update now-passing wasm_backend tests * Update other.test_locale to non-stub setlocale * Fix compiling with -s USE_PTHREADS=1 * Initialize __pthread_self() when using pthread_stub * Canonicalize nans for test_zerodiv * Update count of globals in test_dlfcn_self * Rework how we initialize pthread_self for non-threaded applications * Prefer 'EMSCRIPTEN_START_FUNCS' in test_memorygrowth, because 'var TOTAL_MEMORY' can move around * Now that CURRENT_LOCALE isn't reading off NULL, test_langinfo should expect ASCII * Re-disable test_demangle_stacks - was spuriously passing earlier * Explicitly pass 0 as the high bits for SYS__llseek * Enable v8 for test_readdir now that it supports printErr * Only use __syscall_emscripten if __EMSCRIPTEN__ is defined * Move O_LARGEFILE as default back to libc * libc #if to #ifdef * Rename pthread import funcs to not rely on alias * Consistently reference pthread_setcancelstate by alias in libc * Stub out fcntl64 for NO_FILESYSTEM case * Update emscripten-specific pthread struct fields * Consistently reference pthread_testcancel by alias in libc * Stub out SYS_rt_sigqueueinfo syscall * Stub out SYS_sendmmsg syscall * Stub out SYS_recvmmsg syscall * Revert "Consistently reference pthread_testcancel by alias in libc" This reverts commit 43563a5. * Revert "Consistently reference pthread_setcancelstate by alias in libc" This reverts commit 2ca2ede. * Correctly fix unresolved symbol: __pthread_setcancelstate * Update library_pthread.c pthread_testcancel to match musl's expectations * test_strftime.c -> test_strftime.cpp * library_pthread_stub pthread_exit should call exit, not nothing * TEMP: init pthread_self->locale with pthreads enabled * Initialize pthread global data from libc in JS * Move _b_lock and _b_waiters back to not emscripten-only * Remove untrue __asm annotation from threaded pthread_self, make stub pthread_self non-asm * Remove old unneeded pthread init exported functions * Move pthread_self in stub case to libc C code * Move emscripten_pthread initialization to its own file, out from locale_map.c * Statically allocate the pthread struct and not just a pointer in the stub case * Remove commented-out test args * Remove misleading __asm annotation for _register_pthread_ptr * Do module-side pthread initialization in-module * Don't cast away volatile when calling emscripten_futex_wake in __wake * Expose libc struct to emscripten, use that for non-main pthread initialization * Re-add pthread_impl.h import to library_pthread.c * Update align_moar alignment post-rebase * Update emscripten header include in libc.c * Remove obsolete locale preallocating code in newlocale We previously statically allocated a single locale in the event that we needed to dynamically allocate one during startup. musl changed their implementation to statically allocate C_LOCALE and UTF8_LOCALE, so we already get that behavior. In addition this was causing invalid locales to get allocated instead of returning NULL, because the preceding logic changed. That was caught by other.test_locale_wrong * Update test_llvm_lto * Bump version to 1.37.5
1 parent bda1131 commit 31cf2bb

File tree

537 files changed

+14060
-4250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

537 files changed

+14060
-4250
lines changed

emscripten-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"1.37.4"
1+
"1.37.5"

src/library.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,12 @@ LibraryManager.library = {
21072107
return -1;
21082108
},
21092109

2110+
__map_file__deps: ['$ERRNO_CODES', '__setErrNo'],
2111+
__map_file: function(pathname, size) {
2112+
___setErrNo(ERRNO_CODES.EPERM);
2113+
return -1;
2114+
},
2115+
21102116
_MONTH_DAYS_REGULAR: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
21112117
_MONTH_DAYS_LEAP: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
21122118

@@ -4282,7 +4288,7 @@ LibraryManager.library = {
42824288
_pthread_cleanup_push: function(){},
42834289
_pthread_cleanup_pop: function(){},
42844290
__pthread_self: function() { abort() },
4285-
pthread_setcancelstate: function() { return 0 },
4291+
__pthread_setcancelstate: function() { return 0 },
42864292

42874293
// libunwind
42884294

src/library_pthread.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ var LibraryPThread = {
416416
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.attr }}} + 20) >> 2, threadParams.schedPolicy);
417417
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.attr }}} + 24) >> 2, threadParams.schedPrio);
418418

419+
var global_libc = _emscripten_get_global_libc();
420+
var global_locale = global_libc + {{{ C_STRUCTS.libc.global_locale }}};
421+
Atomics.store(HEAPU32, (pthread.threadInfoStruct + {{{ C_STRUCTS.pthread.locale }}}) >> 2, global_locale);
422+
419423
#if PTHREADS_PROFILING
420424
PThread.createProfilerBlock(pthread.threadInfoStruct);
421425
#endif
@@ -735,7 +739,6 @@ var LibraryPThread = {
735739
_pthread_is_main_runtime_thread: 0,
736740
_pthread_is_main_browser_thread: 0,
737741

738-
_register_pthread_ptr__asm: true,
739742
_register_pthread_ptr__deps: ['_pthread_ptr', '_pthread_is_main_runtime_thread', '_pthread_is_main_browser_thread'],
740743
_register_pthread_ptr: function(pthreadPtr, isMainBrowserThread, isMainRuntimeThread) {
741744
pthreadPtr = pthreadPtr|0;
@@ -747,7 +750,6 @@ var LibraryPThread = {
747750
},
748751

749752
// Public pthread_self() function which returns a unique ID for the thread.
750-
pthread_self__asm: true,
751753
pthread_self__deps: ['_pthread_ptr'],
752754
pthread_self: function() {
753755
return __pthread_ptr|0;

src/library_pthread_stub.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ var LibraryPThreadStub = {
7979
return 0;
8080
},
8181

82-
pthread_self__asm: true,
83-
pthread_self__sig: 'i',
84-
pthread_self: function() {
85-
return 0;
86-
},
87-
8882
pthread_attr_init: function(attr) {
8983
/* int pthread_attr_init(pthread_attr_t *attr); */
9084
//FIXME: should allocate a pthread_attr_t
@@ -194,7 +188,10 @@ var LibraryPThreadStub = {
194188
return {{{ cDefine('EAGAIN') }}};
195189
},
196190
pthread_cancel: function() {},
197-
pthread_exit: function() {},
191+
pthread_exit__deps: ['exit'],
192+
pthread_exit: function(status) {
193+
_exit(status);
194+
},
198195

199196
pthread_equal: function() {},
200197
pthread_join: function() {},

src/library_syscall.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ var SyscallsLibrary = {
332332
var argp = SYSCALLS.get();
333333
return FS.ioctl(stream, op, argp);
334334
}
335+
case {{{ cDefine('TIOCGWINSZ') }}}: {
336+
// TODO: in theory we should write to the winsize struct that gets
337+
// passed in, but for now musl doesn't read anything on it
338+
if (!stream.tty) return -ERRNO_CODES.ENOTTY;
339+
return 0;
340+
}
335341
default: abort('bad ioctl syscall ' + op);
336342
}
337343
#endif // NO_FILESYSTEM
@@ -833,6 +839,12 @@ var SyscallsLibrary = {
833839
}
834840
return nonzero;
835841
},
842+
__syscall178: function(which, varargs) { // rt_sigqueueinfo
843+
#if SYSCALL_DEBUG
844+
Module.printErr('warning: ignoring SYS_rt_sigqueueinfo');
845+
#endif
846+
return 0;
847+
},
836848
__syscall180: function(which, varargs) { // pread64
837849
var stream = SYSCALLS.getStreamFromFD(), buf = SYSCALLS.get(), count = SYSCALLS.get(), zero = SYSCALLS.getZero(), offset = SYSCALLS.get64();
838850
return FS.read(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, count, offset);
@@ -996,6 +1008,12 @@ var SyscallsLibrary = {
9961008
},
9971009
__syscall221__deps: ['__setErrNo'],
9981010
__syscall221: function(which, varargs) { // fcntl64
1011+
#if NO_FILESYSTEM
1012+
#if SYSCALL_DEBUG
1013+
Module.printErr('no-op in fcntl64 syscall due to NO_FILESYSTEM');
1014+
#endif
1015+
return 0;
1016+
#else
9991017
var stream = SYSCALLS.getStreamFromFD(), cmd = SYSCALLS.get();
10001018
switch (cmd) {
10011019
case {{{ cDefine('F_DUPFD') }}}: {
@@ -1044,6 +1062,7 @@ var SyscallsLibrary = {
10441062
return -ERRNO_CODES.EINVAL;
10451063
}
10461064
}
1065+
#endif // NO_FILESYSTEM
10471066
},
10481067
__syscall265: function(which, varargs) { // clock_nanosleep
10491068
#if SYSCALL_DEBUG
@@ -1231,6 +1250,12 @@ var SyscallsLibrary = {
12311250
var stream = SYSCALLS.getStreamFromFD(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get(), offset = SYSCALLS.get();
12321251
return SYSCALLS.doWritev(stream, iov, iovcnt, offset);
12331252
},
1253+
__syscall337: function(which, varargs) { // recvmmsg
1254+
#if SYSCALL_DEBUG
1255+
Module.printErr('warning: ignoring SYS_recvmmsg');
1256+
#endif
1257+
return 0;
1258+
},
12341259
__syscall340: function(which, varargs) { // prlimit64
12351260
var pid = SYSCALLS.get(), resource = SYSCALLS.get(), new_limit = SYSCALLS.get(), old_limit = SYSCALLS.get();
12361261
if (old_limit) { // just report no limits
@@ -1241,6 +1266,12 @@ var SyscallsLibrary = {
12411266
}
12421267
return 0;
12431268
},
1269+
__syscall345: function(which, varargs) { // sendmmsg
1270+
#if SYSCALL_DEBUG
1271+
Module.printErr('warning: ignoring SYS_sendmmsg');
1272+
#endif
1273+
return 0;
1274+
},
12441275
};
12451276

12461277
if (SYSCALL_DEBUG) {
@@ -1577,6 +1608,7 @@ if (SYSCALL_DEBUG) {
15771608
SYS_inotify_init1: 332,
15781609
SYS_preadv: 333,
15791610
SYS_pwritev: 334,
1611+
SYS_recvmmsg: 337,
15801612
SYS_prlimit64: 340,
15811613
SYS_name_to_handle_at: 341,
15821614
SYS_open_by_handle_at: 342,

src/struct_info.compiled.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/struct_info.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@
467467
"F_GETOWN_EX",
468468
"F_SETFD",
469469
"O_EXCL",
470-
"F_GETFL"
470+
"F_GETFL",
471+
"O_LARGEFILE"
471472
],
472473
"structs": {}
473474
},
@@ -491,7 +492,8 @@
491492
"TCGETS",
492493
"TCSETS",
493494
"TIOCGPGRP",
494-
"TIOCSPGRP"
495+
"TIOCSPGRP",
496+
"TIOCGWINSZ"
495497
],
496498
"structs": {}
497499
},
@@ -1485,7 +1487,17 @@
14851487
"tid",
14861488
"pid",
14871489
"canceldisable",
1488-
"cancelasync"
1490+
"cancelasync",
1491+
"locale"
1492+
]
1493+
},
1494+
"defines": []
1495+
},
1496+
{
1497+
"file": "../lib/libc/musl/src/internal/libc.h",
1498+
"structs": {
1499+
"libc": [
1500+
"global_locale"
14891501
]
14901502
},
14911503
"defines": []

system/include/emscripten/threading.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ uint16_t emscripten_atomic_xor_u16(void/*uint16_t*/ *addr, uint16_t val);
8080
uint32_t emscripten_atomic_xor_u32(void/*uint32_t*/ *addr, uint32_t val);
8181
uint64_t emscripten_atomic_xor_u64(void/*uint64_t*/ *addr, uint64_t val); // Emulated with locks, very slow!!
8282

83-
int emscripten_futex_wait(void/*uint32_t*/ *addr, uint32_t val, double maxWaitMilliseconds);
84-
int emscripten_futex_wake(void/*uint32_t*/ *addr, int count);
85-
int emscripten_futex_wake_or_requeue(void/*uint32_t*/ *addr, int count, void/*uint32_t*/ *addr2, int cmpValue);
83+
int emscripten_futex_wait(volatile void/*uint32_t*/ *addr, uint32_t val, double maxWaitMilliseconds);
84+
int emscripten_futex_wake(volatile void/*uint32_t*/ *addr, int count);
85+
int emscripten_futex_wake_or_requeue(volatile void/*uint32_t*/ *addr, int count, volatile void/*uint32_t*/ *addr2, int cmpValue);
8686

8787
typedef union em_variant_val
8888
{

system/include/libc/aio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct aiocb {
2121
struct sigevent aio_sigevent;
2222
void *__td;
2323
int __lock[2];
24-
int __err;
24+
volatile int __err;
2525
ssize_t __ret;
2626
off_t aio_offset;
2727
void *__next, *__prev;

system/include/libc/alltypes.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ TYPEDEF _Int64 blkcnt_t;
2828
TYPEDEF unsigned _Int64 fsblkcnt_t;
2929
TYPEDEF unsigned _Int64 fsfilcnt_t;
3030

31+
TYPEDEF unsigned wint_t;
3132
TYPEDEF unsigned long wctype_t;
3233

3334
TYPEDEF void * timer_t;
@@ -58,6 +59,8 @@ TYPEDEF struct { unsigned __attr[2]; } pthread_rwlockattr_t;
5859

5960
TYPEDEF struct _IO_FILE FILE;
6061

62+
TYPEDEF struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t;
63+
6164
TYPEDEF struct __locale_struct * locale_t;
6265

6366
TYPEDEF struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t;

system/include/libc/arpa/nameser.h

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef _ARPA_NAMESER_H
22
#define _ARPA_NAMESER_H
33

4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <stddef.h>
49
#include <stdint.h>
510

611
#define __NAMESER 19991006
@@ -48,6 +53,8 @@ extern const struct _ns_flagdata _ns_flagdata[];
4853
#define ns_msg_end(handle) ((handle)._eom + 0)
4954
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
5055
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
56+
#define ns_msg_getflag(handle, flag) \
57+
(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)
5158

5259
typedef struct __ns_rr {
5360
char name[NS_MAXDNAME];
@@ -296,43 +303,20 @@ typedef enum __ns_cert_types {
296303
#define NS_OPT_DNSSEC_OK 0x8000U
297304
#define NS_OPT_NSID 3
298305

299-
#define NS_GET16(s, cp) do { \
300-
register const unsigned char *t_cp = (const unsigned char *)(cp); \
301-
(s) = ((uint16_t)t_cp[0] << 8) \
302-
| ((uint16_t)t_cp[1]) \
303-
; \
304-
(cp) += NS_INT16SZ; \
305-
} while (0)
306-
307-
#define NS_GET32(l, cp) do { \
308-
register const unsigned char *t_cp = (const unsigned char *)(cp); \
309-
(l) = ((uint32_t)t_cp[0] << 24) \
310-
| ((uint32_t)t_cp[1] << 16) \
311-
| ((uint32_t)t_cp[2] << 8) \
312-
| ((uint32_t)t_cp[3]) \
313-
; \
314-
(cp) += NS_INT32SZ; \
315-
} while (0)
316-
317-
#define NS_PUT16(s, cp) do { \
318-
register uint16_t t_s = (uint16_t)(s); \
319-
register unsigned char *t_cp = (unsigned char *)(cp); \
320-
*t_cp++ = t_s >> 8; \
321-
*t_cp = t_s; \
322-
(cp) += NS_INT16SZ; \
323-
} while (0)
324-
325-
#define NS_PUT32(l, cp) do { \
326-
register uint32_t t_l = (uint32_t)(l); \
327-
register unsigned char *t_cp = (unsigned char *)(cp); \
328-
*t_cp++ = t_l >> 24; \
329-
*t_cp++ = t_l >> 16; \
330-
*t_cp++ = t_l >> 8; \
331-
*t_cp = t_l; \
332-
(cp) += NS_INT32SZ; \
333-
} while (0)
306+
#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
307+
#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
308+
#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
309+
#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)
334310

311+
unsigned ns_get16(const unsigned char *);
312+
unsigned long ns_get32(const unsigned char *);
313+
void ns_put16(unsigned, unsigned char *);
314+
void ns_put32(unsigned long, unsigned char *);
335315

316+
int ns_initparse(const unsigned char *, int, ns_msg *);
317+
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
318+
int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
319+
int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);
336320

337321

338322
#define __BIND 19950621
@@ -464,4 +448,8 @@ typedef struct {
464448
#define PUTSHORT NS_PUT16
465449
#define PUTLONG NS_PUT32
466450

451+
#ifdef __cplusplus
452+
}
453+
#endif
454+
467455
#endif

system/include/libc/assert.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
99
#endif
1010

11+
#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
12+
#define static_assert _Static_assert
13+
#endif
14+
1115
#ifdef __cplusplus
1216
extern "C" {
1317
#endif
1418

15-
#if __EMSCRIPTEN__
19+
#ifdef __EMSCRIPTEN__
1620
_Noreturn
1721
#endif
1822
void __assert_fail (const char *, const char *, int, const char *);

system/include/libc/complex.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ extern "C" {
77

88
#define complex _Complex
99
#ifdef __GNUC__
10-
#define _Complex_I (__extension__ 1.0fi)
10+
#define _Complex_I (__extension__ (0.0f+1.0fi))
1111
#else
12-
#define _Complex_I 1.0fi
12+
#define _Complex_I (0.0f+1.0fi)
1313
#endif
1414
#define I _Complex_I
1515

@@ -101,8 +101,9 @@ double creal(double complex);
101101
float crealf(float complex);
102102
long double creall(long double complex);
103103

104+
#ifndef __cplusplus
104105
#define __CIMAG(x, t) \
105-
((union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1])
106+
(+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1])
106107

107108
#define creal(x) ((double)(x))
108109
#define crealf(x) ((float)(x))
@@ -111,13 +112,20 @@ long double creall(long double complex);
111112
#define cimag(x) __CIMAG(x, double)
112113
#define cimagf(x) __CIMAG(x, float)
113114
#define cimagl(x) __CIMAG(x, long double)
115+
#endif
114116

115-
#define __CMPLX(x, y, t) \
116-
((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z)
117-
117+
#if __STDC_VERSION__ >= 201112L
118+
#if defined(_Imaginary_I)
119+
#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y))
120+
#elif defined(__clang__)
121+
#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) })
122+
#else
123+
#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
124+
#endif
118125
#define CMPLX(x, y) __CMPLX(x, y, double)
119126
#define CMPLXF(x, y) __CMPLX(x, y, float)
120127
#define CMPLXL(x, y) __CMPLX(x, y, long double)
128+
#endif
121129

122130
#ifdef __cplusplus
123131
}

0 commit comments

Comments
 (0)