Skip to content

Commit 9e5d54a

Browse files
committed
Reapply emscripten patches
1 parent a1a7559 commit 9e5d54a

35 files changed

+88
-80
lines changed

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extern struct ps_strings *__ps_strings;
104104
#endif
105105

106106
#if SANITIZER_EMSCRIPTEN
107+
// XXX Emscripten this must be defined before including the internal syscall.h header from musl
107108
#define weak __attribute__(__weak__)
108109
#define hidden __attribute__((__visibility__("hidden")))
109110
#include <syscall.h>

system/lib/libc/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ and use a script (`system/lib/update_musl.py`) to pull in updates.
77

88
Some changes have been made to the version that was taken from upstream, including:
99

10-
* 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.
11-
* Backporting an operator-precedence warning fix from 6e76e1540fc58a418494bf5eb832b556f9c5763e in the upstream version.
10+
* 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.
1211
* Switch to using the wasi `fd_write` syscall instead of `writev`.
1312
* 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.
1413
* Setting `_POSIX_REALTIME_SIGNALS` and `_POSIX_SPAWN` macros to -1, to exclude unsupported functions.

system/lib/libc/musl/src/errno/__errno_location.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <errno.h>
22
#include "pthread_impl.h"
33

4-
#if __EMSCRIPTEN_PTHREADS__
4+
#ifdef __EMSCRIPTEN_PTHREADS__
55
// for pthreads, use the proper location on the thread info, so each
66
// thread has its own errno
77
int *__errno_location(void)
88
{
99
return &__pthread_self()->errno_val;
1010
}
11-
#else
11+
#else // !defined(__EMSCRIPTEN_PTHREADS__)
1212
// for single-threaded mode, avoid linking in pthreads support code
1313
// just for this
1414
static int __errno_storage = 0;

system/lib/libc/musl/src/internal/libm.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ static inline long double fp_barrierl(long double x)
144144
}
145145
#endif
146146

147+
#ifdef __EMSCRIPTEN__
148+
/*
149+
* wasm doesn't have user-accessible floating point exceptions, so there's
150+
* no point in trying to force expression evaluations to produce them.
151+
*/
152+
#define fp_force_evalf(x)
153+
#define fp_force_eval(x)
154+
#define fp_force_evall(x)
155+
#define FORCE_EVAL(x)
156+
#else
147157
/* fp_force_eval ensures that the input value is computed when that's
148158
otherwise unused. To prevent the constant folding of the input
149159
expression, an additional fp_barrier may be needed or a compilation
@@ -177,13 +187,6 @@ static inline void fp_force_evall(long double x)
177187
}
178188
#endif
179189

180-
#ifdef __EMSCRIPTEN__
181-
/*
182-
* asm.js doesn't have user-accessible floating point exceptions, so there's
183-
* no point in trying to force expression evaluations to produce them.
184-
*/
185-
#define FORCE_EVAL(x)
186-
#else
187190
#define FORCE_EVAL(x) do { \
188191
if (sizeof(x) == sizeof(float)) { \
189192
fp_force_evalf(x); \

system/lib/libc/musl/src/internal/pthread_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static inline void __wake(volatile void *addr, int cnt, int priv)
189189
if (priv) priv = FUTEX_PRIVATE;
190190
if (cnt<0) cnt = INT_MAX;
191191
#ifdef __EMSCRIPTEN__
192-
emscripten_futex_wake(addr, (cnt)<0?INT_MAX:(cnt));
192+
emscripten_futex_wake(addr, cnt);
193193
#else
194194
__syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS ||
195195
__syscall(SYS_futex, addr, FUTEX_WAKE, cnt);

system/lib/libc/musl/src/internal/syscall.h

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
typedef long syscall_arg_t;
2424
#endif
2525

26-
#ifdef __cplusplus
26+
#ifdef __cplusplus // XXX Emscripten we need C linkage for this
2727
extern "C" {
2828
#endif
2929
hidden long __syscall_ret(unsigned long),
@@ -33,14 +33,7 @@ hidden long __syscall_ret(unsigned long),
3333
}
3434
#endif
3535

36-
#ifndef __EMSCRIPTEN__
37-
#define __syscall1(n,a) __syscall1(n,__scc(a))
38-
#define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b))
39-
#define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c))
40-
#define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d))
41-
#define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
42-
#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
43-
#else // __EMSCRIPTEN__
36+
#ifdef __EMSCRIPTEN__
4437
#define __syscall_emscripten(n, ...) n(__VA_ARGS__)
4538
#define __syscall_emscripten0(n) __syscall_emscripten(n)
4639
#define __syscall_emscripten1(n,a) __syscall_emscripten(n,__scc(a))
@@ -49,26 +42,35 @@ hidden long __syscall_ret(unsigned long),
4942
#define __syscall_emscripten4(n,a,b,c,d) __syscall_emscripten(n,__scc(a),__scc(b),__scc(c),__scc(d))
5043
#define __syscall_emscripten5(n,a,b,c,d,e) __syscall_emscripten(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
5144
#define __syscall_emscripten6(n,a,b,c,d,e,f) __syscall_emscripten(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
52-
#endif // __EMSCRIPTEN__
45+
#else // !defined(__EMSCRIPTEN__)
46+
#define __syscall1(n,a) __syscall1(n,__scc(a))
47+
#define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b))
48+
#define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c))
49+
#define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d))
50+
#define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
51+
#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
52+
#endif // !defined(__EMSCRIPTEN__)
5353

5454
#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
5555
#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,)
5656
#define __SYSCALL_CONCAT_X(a,b) a##b
5757
#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b)
5858
#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
5959

60-
#ifndef __EMSCRIPTEN__
61-
#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
62-
#else
60+
#ifdef __EMSCRIPTEN__
6361
#define __syscall(...) __SYSCALL_DISP(__syscall_emscripten,__VA_ARGS__)
62+
#else
63+
#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
6464
#endif
6565

6666
#define syscall(...) __syscall_ret(__syscall(__VA_ARGS__))
6767

6868
#define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f))
6969
#define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f))
7070

71-
#ifndef __EMSCRIPTEN__
71+
#ifdef __EMSCRIPTEN__
72+
#define __syscall_cp(...) __syscall(__VA_ARGS__)
73+
#else // !defined(__EMSCRIPTEN__)
7274
#define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0)
7375
#define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0)
7476
#define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0)
@@ -78,9 +80,7 @@ hidden long __syscall_ret(unsigned long),
7880
#define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
7981

8082
#define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
81-
#else // __EMSCRIPTEN__
82-
#define __syscall_cp(...) __syscall(__VA_ARGS__)
83-
#endif // __EMSCRIPTEN__
83+
#endif // !defined(__EMSCRIPTEN__)
8484

8585
#define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
8686

@@ -404,7 +404,12 @@ static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, l
404404
#define SIOCGSTAMPNS_OLD 0x8907
405405
#endif
406406

407-
#ifndef __EMSCRIPTEN__
407+
#ifdef __EMSCRIPTEN__
408+
#define __sys_open2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
409+
#define __sys_open3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
410+
#define __sys_open_cp2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
411+
#define __sys_open_cp3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
412+
#else // !defined(__EMSCRIPTEN__)
408413
#ifdef SYS_open
409414
#define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE)
410415
#define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
@@ -416,20 +421,14 @@ static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, l
416421
#define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
417422
#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
418423
#endif
419-
#else // __EMSCRIPTEN__
420-
#define __sys_open2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
421-
#define __sys_open3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
422-
#define __sys_open_cp2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
423-
#define __sys_open_cp3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
424-
#endif
425-
424+
#endif // !defined(__EMSCRIPTEN__)
426425
#define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__)
427426
#define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__))
428427

429428
#define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__)
430429
#define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__))
431430

432-
#ifdef __cplusplus
431+
#ifdef __cplusplus // XXX Emscripten static array size is a C99 feature, not permitted in C++
433432
hidden void __procfdname(char __buf[], unsigned);
434433
#else
435434
hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned);

system/lib/libc/musl/src/linux/sbrk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !__EMSCRIPTEN__ /* Emscripten controls sbrk itself */
1+
#ifndef __EMSCRIPTEN__ /* Emscripten controls sbrk itself */
22
#define _BSD_SOURCE
33
#include <unistd.h>
44
#include <stdint.h>
@@ -11,4 +11,3 @@ void *sbrk(intptr_t inc)
1111
return (void *)__syscall(SYS_brk, 0);
1212
}
1313
#endif
14-

system/lib/libc/musl/src/math/sqrt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ double sqrt(double x)
2525
{
2626
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin
2727
// See https://github.com/emscripten-core/emscripten/issues/9236
28-
#ifdef __wasm__
28+
#ifdef __EMSCRIPTEN__
2929
return __builtin_sqrt(x);
3030
#else
3131
uint64_t ix, top, m;

system/lib/libc/musl/src/math/sqrtf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ float sqrtf(float x)
1616
{
1717
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin
1818
// See https://github.com/emscripten-core/emscripten/issues/9236
19-
#ifdef __wasm__
19+
#ifdef __EMSCRIPTEN__
2020
return __builtin_sqrtf(x);
2121
#else
2222
uint32_t ix, m, m1, m0, even, ey;

system/lib/libc/musl/src/sched/sched_yield.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <sched.h>
22
#include "syscall.h"
33

4-
#if __EMSCRIPTEN__
4+
#ifdef __EMSCRIPTEN__
55
#include <emscripten/threading.h>
66
#endif
77

88
int sched_yield()
99
{
10-
#if __EMSCRIPTEN__
10+
#ifdef __EMSCRIPTEN__
1111
// SharedArrayBuffer and wasm threads do not support explicit yielding.
1212
// For now we at least process our event queue so that other threads who
1313
// are waiting on this one to perform actions can make progesss.

0 commit comments

Comments
 (0)