Skip to content

SUPPORT_BIG_ENDIAN+PThread does not work on big-endian machines #23689

Description

@slavek-kucera

Trivial program (int main(){}) fails during startup with the following error messages

TypeError: wait.value.then is not a function
    at __emscripten_thread_mailbox_await (***/main.js:1:19568)
    at wasm://wasm/00015506:wasm-function[14]:0x553
    at callRuntimeCallbacks (***/main.js:1:17193)
    at initRuntime (***/main.js:1:7154)
    at doRun (***/main.js:1:27532)
    at run (***/main.js:1:27802)
    at removeRunDependency (***/main.js:1:8194)
    at ***/main.js:1:14279

while running on a big-endian machine with PThreads and SUPPORT_BIG_ENDIAN.

Using emscriptern 4.0.2., I built the program with the following command:

em++ -o main.js -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1 -s PTHREAD_POOL_SIZE=8 -s SUPPORT_BIG_ENDIAN=1 -pthread -s EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -O2 main.cpp

If I manually adjust (byteswap) values in the following code (both pthread_ptr in Atomics.waitAsync and 1 in Atomics.store), everything starts working again

var wait = Atomics.waitAsync(HEAP32, {{{ getHeapOffset('pthread_ptr', 'i32') }}}, pthread_ptr);
#if ASSERTIONS
assert(wait.async);
#endif
wait.value.then(checkMailbox);
var waitingAsync = pthread_ptr + {{{ C_STRUCTS.pthread.waiting_async }}};
Atomics.store(HEAP32, {{{ getHeapOffset('waitingAsync', 'i32') }}}, 1);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions