Skip to content

Commit b06fb97

Browse files
authored
Merge branch 'main' into bulkmem
2 parents 07c1b90 + 814ec05 commit b06fb97

Some content is hidden

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

43 files changed

+342
-397
lines changed

embuilder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
'crtbegin',
114114
'libsanitizer_common_rt',
115115
'libubsan_rt',
116-
'libwasm_workers_stub-debug',
116+
'libwasm_workers-debug-stub',
117117
'libfetch',
118118
'libfetch-mt',
119119
'libwasmfs',

src/library_glemu.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ var LibraryGLEmulation = {
20472047
GLImmediate.rendererComponents[name] = 1;
20482048
#if ASSERTIONS
20492049
if (GLImmediate.enabledClientAttributes[name]) {
2050-
out("Warning: glTexCoord used after EnableClientState for TEXTURE_COORD_ARRAY for TEXTURE0. Disabling TEXTURE_COORD_ARRAY...");
2050+
warnOnce("Warning: glTexCoord used after EnableClientState for TEXTURE_COORD_ARRAY for TEXTURE0. Disabling TEXTURE_COORD_ARRAY...");
20512051
}
20522052
#endif
20532053
GLImmediate.enabledClientAttributes[name] = true;
@@ -2980,11 +2980,10 @@ var LibraryGLEmulation = {
29802980
var attr = attributes[i];
29812981
var srcStride = Math.max(attr.sizeBytes, attr.stride);
29822982
if ((srcStride & 3) == 0 && (attr.sizeBytes & 3) == 0) {
2983-
var size4 = attr.sizeBytes>>2;
2984-
var srcStride4 = Math.max(attr.sizeBytes, attr.stride)>>2;
29852983
for (var j = 0; j < count; j++) {
2986-
for (var k = 0; k < size4; k++) { // copy in chunks of 4 bytes, our alignment makes this possible
2987-
HEAP32[((start + attr.offset + bytes*j)>>2) + k] = HEAP32[(attr.pointer>>2) + j*srcStride4 + k];
2984+
for (var k = 0; k < attr.sizeBytes; k+=4) { // copy in chunks of 4 bytes, our alignment makes this possible
2985+
var val = {{{ makeGetValue('attr.pointer', 'j*srcStride + k', 'i32') }}};
2986+
{{{ makeSetValue('start + attr.offset', 'bytes*j + k', 'val', 'i32') }}};
29882987
}
29892988
}
29902989
} else {
@@ -3533,7 +3532,7 @@ var LibraryGLEmulation = {
35333532
if (!GLctx.currentElementArrayBufferBinding) {
35343533
assert(type == GLctx.UNSIGNED_SHORT); // We can only emulate buffers of this kind, for now
35353534
}
3536-
out("DrawElements doesn't actually prepareClientAttributes properly.");
3535+
warnOnce("DrawElements doesn't actually prepareClientAttributes properly.");
35373536
#endif
35383537
GLImmediate.prepareClientAttributes(count, false);
35393538
GLImmediate.mode = mode;

src/library_webgpu.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ var LibraryWebGPU = {
410410
'mapped': 3,
411411
},
412412
Int_CompilationMessageType : {
413-
'error': 0,
414-
'warning': 1,
415-
'info': 2,
413+
'error': 1,
414+
'warning': 2,
415+
'info': 3,
416416
},
417417
Int_DeviceLostReason: {
418418
'undefined': 1,

system/lib/compiler-rt/stack_limits.S

+3-51
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
#endif
1616

1717
.globaltype __stack_pointer, PTR
18+
.globl __stack_pointer
1819

1920
.section .globals,"",@
2021

2122
# TODO(sbc): It would be nice if these we initialized directly
2223
# using PTR.const rather than using the `emscripten_stack_init`
2324
.globaltype __stack_end, PTR
2425
__stack_end:
26+
.globl __stack_end
2527
.globaltype __stack_base, PTR
28+
.globl __stack_base
2629
__stack_base:
2730

2831
.section .text,"",@
@@ -82,57 +85,6 @@ emscripten_stack_get_free:
8285
PTR.sub
8386
end_function
8487

85-
#ifdef __EMSCRIPTEN_WASM_WORKERS__
86-
# TODO: Relocate the following to its own file wasm_worker.S, but need to figure out how to reference
87-
# __stack_base and __stack_end globals from a separate file as externs in order for that to work.
88-
.globl _emscripten_wasm_worker_initialize
89-
_emscripten_wasm_worker_initialize:
90-
.functype _emscripten_wasm_worker_initialize (PTR /*stackLowestAddress*/, i32 /*stackSize*/) -> ()
91-
92-
// __stack_end = stackLowestAddress + (__builtin_wasm_tls_size() + 15) & -16;
93-
local.get 0
94-
.globaltype __tls_size, PTR, immutable
95-
global.get __tls_size
96-
PTR.add
97-
PTR.const 0xf
98-
PTR.add
99-
PTR.const -0x10
100-
PTR.and
101-
global.set __stack_end
102-
103-
// __stack_base = stackLowestAddress + stackSize;
104-
local.get 0
105-
local.get 1
106-
#ifdef __wasm64__
107-
i64.extend_i32_u
108-
#endif
109-
PTR.add
110-
global.set __stack_base
111-
112-
// TODO: We'd like to do this here to avoid JS side calls to __set_stack_limits.
113-
// (or even better, we'd like to avoid duplicate versions of the stack variables)
114-
// See https://github.com/emscripten-core/emscripten/issues/16496
115-
// global.get __stack_base
116-
// global.get __stack_end
117-
// .functype __set_stack_limits (PTR, PTR) -> ()
118-
// call __set_stack_limits
119-
120-
// __wasm_init_tls(stackLowestAddress);
121-
local.get 0
122-
.functype __wasm_init_tls (PTR) -> ()
123-
call __wasm_init_tls
124-
125-
// N.b. The function __wasm_init_tls above does not need
126-
// __stack_pointer initialized, and it destroys the value it was set to.
127-
// So we must initialize __stack_pointer only *after* completing __wasm_init_tls:
128-
129-
// __stack_pointer = __stack_base;
130-
global.get __stack_base
131-
global.set __stack_pointer
132-
133-
end_function
134-
#endif
135-
13688
# Add emscripten_stack_init to static ctors
13789
.section .init_array.1,"",@
13890
.p2align ALIGN

system/lib/dlmalloc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
/* XXX Emscripten Tracing API. This defines away the code if tracing is disabled. */
2222
#include <emscripten/trace.h>
2323

24-
#ifdef __EMSCRIPTEN_WASM_WORKERS__
24+
#ifdef __EMSCRIPTEN_SHARED_MEMORY__
2525
#define USE_LOCKS 1
2626
#endif
2727

2828
/* Make malloc() and free() threadsafe by securing the memory allocations with pthread mutexes. */
2929
#if __EMSCRIPTEN_PTHREADS__
30-
#define USE_LOCKS 1
3130
#define USE_SPIN_LOCKS 0 // Ensure we use pthread_mutex_t.
3231
#endif
3332

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
#include <errno.h>
22
#include "pthread_impl.h"
33

4-
#if __EMSCRIPTEN_PTHREADS__
5-
// for pthreads, use the proper location on the thread info, so each
6-
// thread has its own errno
7-
int *__errno_location(void)
8-
{
9-
return &__pthread_self()->errno_val;
10-
}
11-
#else
12-
// for single-threaded mode, avoid linking in pthreads support code
13-
// just for this
14-
static int __errno_storage = 0;
4+
#if __EMSCRIPTEN__
5+
// For emscripten we use TLS here instead of `__pthread_self`, so that in single
6+
// threaded builds this gets lowered away to normal global variable.
7+
static _Thread_local int __errno_storage = 0;
8+
#endif
159

1610
int *__errno_location(void)
1711
{
12+
#if __EMSCRIPTEN__
1813
return &__errno_storage;
19-
}
14+
#else
15+
return &__pthread_self()->errno_val;
2016
#endif
17+
}
2118

2219
weak_alias(__errno_location, ___errno_location);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.extern __stack_pointer
2+
.extern __stack_base
3+
.extern __stack_end
4+
5+
#ifdef __wasm64__
6+
#define PTR i64
7+
#define ALIGN 3
8+
#define PTRSTORE .int64
9+
#else
10+
#define PTR i32
11+
#define ALIGN 2
12+
#define PTRSTORE .int32
13+
#endif
14+
15+
.globaltype __stack_pointer, PTR
16+
.globaltype __stack_end, PTR
17+
.globaltype __stack_base, PTR
18+
19+
.globl _emscripten_wasm_worker_initialize
20+
_emscripten_wasm_worker_initialize:
21+
.functype _emscripten_wasm_worker_initialize (PTR /*stackLowestAddress*/, i32 /*stackSize*/) -> ()
22+
23+
// __stack_end = stackLowestAddress + (__builtin_wasm_tls_size() + 15) & -16;
24+
local.get 0
25+
.globaltype __tls_size, PTR, immutable
26+
global.get __tls_size
27+
PTR.add
28+
PTR.const 0xf
29+
PTR.add
30+
PTR.const -0x10
31+
PTR.and
32+
global.set __stack_end
33+
34+
// __stack_base = stackLowestAddress + stackSize;
35+
local.get 0
36+
local.get 1
37+
#ifdef __wasm64__
38+
i64.extend_i32_u
39+
#endif
40+
PTR.add
41+
global.set __stack_base
42+
43+
// TODO: We'd like to do this here to avoid JS side calls to __set_stack_limits.
44+
// (or even better, we'd like to avoid duplicate versions of the stack variables)
45+
// See https://github.com/emscripten-core/emscripten/issues/16496
46+
// global.get __stack_base
47+
// global.get __stack_end
48+
// .functype __set_stack_limits (PTR, PTR) -> ()
49+
// call __set_stack_limits
50+
51+
// __wasm_init_tls(stackLowestAddress);
52+
local.get 0
53+
.functype __wasm_init_tls (PTR) -> ()
54+
call __wasm_init_tls
55+
56+
// N.b. The function __wasm_init_tls above does not need
57+
// __stack_pointer initialized, and it destroys the value it was set to.
58+
// So we must initialize __stack_pointer only *after* completing __wasm_init_tls:
59+
60+
// __stack_pointer = __stack_base;
61+
global.get __stack_base
62+
global.set __stack_pointer
63+
64+
end_function

test/code_size/hello_wasm_worker_wasm.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"a.js.gz": 455,
66
"a.ww.js": 115,
77
"a.ww.js.gz": 127,
8-
"a.wasm": 1850,
9-
"a.wasm.gz": 1050,
10-
"total": 3248,
11-
"total_gz": 2016
8+
"a.wasm": 1894,
9+
"a.wasm.gz": 1077,
10+
"total": 3292,
11+
"total_gz": 2043
1212
}

test/core/test_dlfcn_self.exports

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ __progname_full
99
__sig_actions
1010
__sig_pending
1111
__signgam
12+
__stack_base
1213
__stack_chk_guard
14+
__stack_end
1315
__threwValue
1416
__timezone
1517
__tzname

test/core/test_em_asm_unicode.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hello world…
1+
hello world…

test/core/test_longjmp.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
first
22
result: 1 1
33
second
4-
result: 2 -1
4+
result: 2 -1

test/test_browser.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -3050,8 +3050,6 @@ def test_sdl2_gl_read(self):
30503050
# SDL, OpenGL, readPixels
30513051
self.btest_exit('test_sdl2_gl_read.c', args=['-sUSE_SDL=2'])
30523052

3053-
@no_4gb('https://github.com/libsdl-org/SDL/issues/9052')
3054-
@no_2gb('https://github.com/libsdl-org/SDL/issues/9052')
30553053
@requires_graphics_hardware
30563054
def test_sdl2_glmatrixmode_texture(self):
30573055
self.reftest('test_sdl2_glmatrixmode_texture.c', 'test_sdl2_glmatrixmode_texture.png',
@@ -3105,8 +3103,6 @@ def test_sdl2_fog_linear(self):
31053103
def test_sdl2_unwasteful(self):
31063104
self.btest_exit('test_sdl2_unwasteful.c', args=['-sUSE_SDL=2', '-O1'])
31073105

3108-
@no_2gb('https://github.com/libsdl-org/SDL/issues/9052')
3109-
@no_4gb('https://github.com/libsdl-org/SDL/issues/9052')
31103106
def test_sdl2_canvas_write(self):
31113107
self.btest_exit('test_sdl2_canvas_write.c', args=['-sUSE_SDL=2'])
31123108

@@ -5011,9 +5007,13 @@ def test_wasm_worker_futex_wait(self, args):
50115007

50125008
# Tests Wasm Worker thread stack setup
50135009
@also_with_minimal_runtime
5014-
def test_wasm_worker_thread_stack(self):
5015-
for mode in (0, 1, 2):
5016-
self.btest('wasm_worker/thread_stack.c', expected='0', args=['-sWASM_WORKERS', f'-sSTACK_OVERFLOW_CHECK={mode}'])
5010+
@parameterized({
5011+
'0': (0,),
5012+
'1': (1,),
5013+
'2': (2,),
5014+
})
5015+
def test_wasm_worker_thread_stack(self, mode):
5016+
self.btest('wasm_worker/thread_stack.c', expected='0', args=['-sWASM_WORKERS', f'-sSTACK_OVERFLOW_CHECK={mode}'])
50175017

50185018
# Tests emscripten_malloc_wasm_worker() and emscripten_current_thread_is_wasm_worker() functions
50195019
@also_with_minimal_runtime

test/wasm_worker/c11__Thread_local.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
_Thread_local int __attribute__((aligned(64))) tls = 1;
77

8-
void main_thread_func()
9-
{
8+
void main_thread_func() {
109
assert(!emscripten_current_thread_is_wasm_worker());
1110
EM_ASM(out($0), tls);
1211
#ifdef REPORT_RESULT
1312
REPORT_RESULT(tls);
1413
#endif
1514
}
1615

17-
void worker_main()
18-
{
16+
void worker_main() {
1917
assert(emscripten_current_thread_is_wasm_worker());
2018
assert(((intptr_t)&tls % 64) == 0);
2119
assert(tls != 42);
@@ -27,8 +25,7 @@ void worker_main()
2725

2826
char stack[1024];
2927

30-
int main()
31-
{
28+
int main() {
3229
EM_ASM(out($0), tls);
3330
assert(((intptr_t)&tls % 64) == 0);
3431
assert(!emscripten_current_thread_is_wasm_worker());

test/wasm_worker/cancel_all_wait_asyncs.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ volatile int32_t addr = 1;
99

1010
bool testSucceeded = 1;
1111

12-
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
13-
{
12+
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
1413
emscripten_console_log("asyncWaitFinishedShouldNotBeCalled");
1514
testSucceeded = 0;
1615
assert(0); // We should not reach here
1716
}
1817

19-
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
20-
{
18+
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
2119
emscripten_console_log("asyncWaitFinishedShouldBeCalled");
2220
#ifdef REPORT_RESULT
2321
REPORT_RESULT(testSucceeded);
2422
#endif
2523
}
2624

27-
int main()
28-
{
25+
int main() {
2926
emscripten_console_log("Async waiting on address should give a wait token");
3027
ATOMICS_WAIT_TOKEN_T ret = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3128
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));

test/wasm_worker/cancel_all_wait_asyncs_at_address.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ volatile int32_t addr = 1;
99

1010
bool testSucceeded = 1;
1111

12-
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
13-
{
12+
void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
1413
emscripten_console_log("asyncWaitFinishedShouldNotBeCalled");
1514
testSucceeded = 0;
1615
assert(0); // We should not reach here
1716
}
1817

19-
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData)
20-
{
18+
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
2119
emscripten_console_log("asyncWaitFinishedShouldBeCalled");
2220
#ifdef REPORT_RESULT
2321
REPORT_RESULT(testSucceeded);
2422
#endif
2523
}
2624

27-
int main()
28-
{
25+
int main() {
2926
emscripten_console_log("Async waiting on address should give a wait token");
3027
ATOMICS_WAIT_TOKEN_T ret = emscripten_atomic_wait_async((int32_t*)&addr, 1, asyncWaitFinishedShouldNotBeCalled, (void*)42, EMSCRIPTEN_WAIT_ASYNC_INFINITY);
3128
assert(EMSCRIPTEN_IS_VALID_WAIT_TOKEN(ret));

0 commit comments

Comments
 (0)