Skip to content

ios 26.2 shared memory issues #25905

Open

Description

@dr-matt

We're encountering a new issue in our web app since installing ios 26.2 rc as well as the preceding beta versions. This is probably a webkit regression rather than an emscripten bug, but posting here in case others are experienced the same issue and hoping to get a little insight from the wasm / emscripten side.

Our app is multi-threaded and uses growable memory. It works fine in previous ios versions through the current 26.1, but now with 26.2 we are seeing immediate memory-related crashes once wasm processing begins. Rather than out-of-memory, the crashes are due to RuntimeError: Out of bounds memory access buried deep within a dependency library. It has something to do with new allocations - in some cases just a std::vector::resize - but it's been challenging to pinpoint thus far. Release and debug builds both exhibit the problem.

Switching to fixed-memory solves the issue, as does forcing single-threaded mode (pthreads still enabled in the build but limiting threads to 1 at the application level). But the combination of growable memory + multiple threads consistently triggers this crash.

We'll continue to try isolating the problem and come up with a MRE to share here. But in the meantime I wanted to report this to see if there's any corroboration that might help with debugging and/or filing the right bug report.

emcc -v:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.21 (d6f42310010ddec0753a69bab01a4b33aae255b7)
clang version 22.0.0git (https:/github.com/llvm/llvm-project 60513b8d6ebacde46e8fbe4faf1319ac87e990e3)
Target: wasm32-unknown-emscripten
Thread model: posix
command line from cmake:
em++ -O3 -DNDEBUG -flto --bind --no-entry --gc-sections -sFILESYSTEM=0 -sEXPORT_ES6=1 -sENVIRONMENT=web,worker -v -pthread -sPTHREAD_POOL_SIZE_STRICT=0 -SCROSS_ORIGIN=1 -sMALLOC=mimalloc -sALLOW_MEMORY_GROWTH=1 --closure 1 -sASSERTIONS=1 -sNO_DISABLE_EXCEPTION_CATCHING --emit-tsd full.d.ts @CMakeFiles/full.simd.threads.growable.dir/objects1.rsp -o full.simd.threads.growable.js @CMakeFiles/full.simd.threads.growable.dir/linkLibs.rsp

bin/wasm-ld -o full.simd.threads.growable.wasm -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmph1lclr0xlibemscripten_js_symbols.so --import-memory --shared-memory --strip-debug -u__cxa_atexit --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__getTypeName --export=_embind_initialize_bindings --export=_emscripten_thread_free_data --export=_emscripten_thread_crashed --export=__cxa_can_catch --export=__cxa_increment_exception_refcount --export=__cxa_decrement_exception_refcount --export=setThrew --export=__cxa_free_exception --export=__wasm_call_ctors --export=_emscripten_tls_init --export=_emscripten_thread_init --export=_emscripten_stack_restore --export=emscripten_stack_set_limits --export=_emscripten_thread_exit --export=__get_exception_message --export=free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --max-memory=2147483648 --initial-memory=16777216 --no-entry --no-stack-first --table-base=1 --global-base=1024 -lembind-mt-rtti <lots of objects here> -lGL-mt-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-mt-debug -lmimalloc-mt -lcompiler_rt-mt -lc++-debug-mt -lc++abi-debug-mt -lsockets-mt

Activity

  1. dr-matt commented on Dec 16, 2025

    @dr-matt
    Author

    iOS 26.2 has officially been released and this bug is still present. I was able to create a MRE that (for me) triggers the error. This was run on an iphone 13, you may need to raise the number of threads and/or chunk sizes to reproduce on other hardware.

    #include <iostream>
    #include <thread>
    #include <vector>
    #include <chrono>
    
    const int num_chunks = 10;
    const int chunk_size_bytes = 1024*1024*2;
    const int num_threads = 2;
    
    void thread_func(int id) {
      std::cout << "starting thread " << id << std::endl;
      std::vector<std::vector<std::uint8_t>> chunks(num_chunks);
      for (auto& chunk : chunks) chunk.resize(chunk_size_bytes);
      std::this_thread::sleep_for(std::chrono::seconds(2));
      std::cout << "thread " << id << " complete" << std::endl;
    }
    
    int main() {
      std::cout << "starting main thread" << std::endl;
    
      std::vector<std::thread> threads;
      for (int i = 1; i <= num_threads; ++i) {
          threads.emplace_back(thread_func, i);
          std::cout << "spawned thread " << i << std::endl;
      }
    
      for (auto& t : threads) t.join();
      std::cout << "all threads finished" << std::endl;
      return 0;
    }
    

    I compiled with:

    emcc main.cpp -o main.js \
    	-std=c++17 \
    	-s WASM=1 \
    	-s USE_PTHREADS=1 \
    	-s PTHREAD_POOL_SIZE=4 \
    	-s PROXY_TO_PTHREAD=1 \
    	-s ALLOW_MEMORY_GROWTH=1 \
    	-s EXPORTED_FUNCTIONS="['_main']" \
    	-s EXPORTED_RUNTIME_METHODS="['ccall','cwrap']" \
    	-s MODULARIZE=1 \
    	-s EXPORT_NAME="Module" \
    	-s ENVIRONMENT="web" \
    	-s ASSERTIONS=2 \
    	-s NO_DISABLE_EXCEPTION_CATCHING \
    	-O2

    The behavior I see is the same out of bounds memory access as in my original application.

    [Warning] w:4,t:0x0001ad70: – "Heap resize call from 16777216 to 20185088 took 2.5400390625 msecs. Success: true" (main.js, line 1)
    [Error] worker: onmessage() captured an uncaught exception: RuntimeError: Out of bounds memory access (evaluating 'getWasmTableEntry(index)(a1,a2)')
    	handleMessage (main.js:1:9962)
    

    Maybe of interest:

    • With a single thread, I can't trigger the error.
    • With very small memory allocations, or a small number of them, no error.
    • It seems to happen just after resizing the heap, perhaps too many allocations are attempted too quickly?

    I hope this is enough information for emscripten experts to begin taking a look. It would be great to verify that this is a regression introduced by ios 26.2 so that we can file a bug report, and maybe identify a better workaround than single-threaded or fixed-memory.

    [edited to avoid blocking main thread]

  2. sbc100 commented on Dec 16, 2025

    @sbc100
    Collaborator

    If you structure you main entry point so that it doesn't block the main thread does that help?

    One way to do that it simply to add -sPROXY_TO_PTHREAD.

    Anther way to do it would be to make std::vector<std::thread> threads; global and remove the .join calls.

  3. dr-matt commented on Dec 16, 2025

    @dr-matt
    Author

    You're right, this does block the main thread (it was put together quickly), but the original application doesn't block, and unfortunately adding PROXY_TO_PTHREAD does not change the error behavior.

  4. Vincentzyx commented on Dec 21, 2025

    @Vincentzyx
    Image Same issue here, are there any workaround that we can use?
  5. kleisauke commented on Dec 23, 2025

    @kleisauke
    Collaborator

    Sounds like this is the same bug as https://bugs.webkit.org/show_bug.cgi?id=304386, which was fixed with commit WebKit/WebKit@192a3bc.

    This issue can also be reproduced with Bun v1.3.5. Running tests against wasm-vips produces the following errors:

    Out of bounds memory access (evaluating 'getWasmTableEntry(ptr)(arg)')
    Unaligned memory access (evaluating 'getWasmTableEntry(ptr)(arg)')
    Out of bounds call_indirect (evaluating 'getWasmTableEntry(ptr)(arg)')
    call_indirect to a signature that does not match (evaluating 'getWasmTableEntry(ptr)(arg)')
    

    (and related variants)

  6. dr-matt commented on Dec 23, 2025

    @dr-matt
    Author

    @Vincentzyx if you need multiple threads, the only workaround I know of is to disable growable memory (-sALLOW_MEMORY_GROWTH=0) and set a large enough fixed memory size for your application via -sINITIAL_MEMORY.

  7. kripken commented on Dec 24, 2025

    @kripken
    Member

    This may also be related to

    https://bugs.webkit.org/show_bug.cgi?id=303387

    which looks like it was recently fixed.

    If there is a nightly build of Bun perhaps that could be tested? (@kleisauke - very cool that Bun can be used for this kind of thing!)

  8. kleisauke commented on Dec 24, 2025

    @kleisauke
    Collaborator

    Ah, indeed. WebKit issue https://bugs.webkit.org/show_bug.cgi?id=303387 appears to be more relevant when building with -sALLOW_MEMORY_GROWTH (wasm-vips still builds without this linker flag).

    If there is a nightly build of Bun perhaps that could be tested?

    It looks like you can use Bun's canary builds for this. For example:

    $ bun upgrade --canary
    [2.08s] Upgraded.
    
    Welcome to Bun's latest canary build!
    
    Report any bugs:
    
        https://github.com/oven-sh/bun/issues
    
    Changelog:
    
        https://github.com/oven-sh/bun/compare/1e86cebd7...8484e1b82

    However, this doesn't seem to resolve the issue. I suspect that https://github.com/oven-sh/WebKit needs to be updated first to include the commits referenced in those WebKit issues.

  9. milky2028 commented on Jan 29, 2026

    @milky2028

    Hello, for anyone else in the future seeing this issue, I work on Photoshop Web and we solved this problem by determining at runtime if the browser is a broken Safari version, then changing the initial memory allocation based on that. As of this writing, the fix is out in Safari Technology Preview and will hopefully ship with Safari 26.3.

    Our fix:

    const cannotGrowMemory = isHigherThanSafari26 && isLowerThanSafari26dot3
    
    const initialMemory = cannotGrowMemory ? 2.5 : 0.45
    const maximumMemory = 4
    
    try {
      wasmMemory = new WebAssembly.Memory({
        initial: (initialMemory * ONE_GIBIBYTE) / WASM_BLOCK_SIZE,
        maximum: (maximumMemory * ONE_GIBIBYTE) / WASM_BLOCK_SIZE,
        shared: true,
      })
    } catch (error) { ... } 
  10. Alexufo commented on Feb 17, 2026

    @Alexufo

    It seems that version 23.3 solves the issue, but do you have multi-threaded speed? It seems that the speed is the same as single-threaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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