Skip to content

Fix CheckTypeSize when flags imply shared memory - #22304

Closed
m4burns wants to merge 1 commit into
emscripten-core:mainfrom
WavTool:fix-checktypesize-shared-memory
Closed

m4burns wants to merge 1 commit into
emscripten-core:mainfrom
WavTool:fix-checktypesize-shared-memory

Conversation

@m4burns

@m4burns m4burns commented Jul 31, 2024

Copy link
Copy Markdown
Contributor

This PR fixes emscripten's patched CheckTypeSize CMake module to work when compiler flags imply shared memory use.

Before this change, trying to configure a CMake project that uses check_type_size when compiler flags implied shared memory (e.g. -sWASM_WORKERS) caused an error:

usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_ae175.dir/link.txt --verbose=1
/.../emcc  -O3 -msimd128 -sWASM_WORKERS  @CMakeFiles/cmTC_ae175.dir/objects1 -o cmTC_ae175.js @CMakeFiles/cmTC_ae175.dir/linkLibs.rsp
error: library_pthread_stub.js: library_pthread_stub.js:11: #error "STANDALONE_WASM does not support shared memories yet"

This PR resolves the issue by changing oformat to bare, which skips the post-link phase. Type size information can still be extracted from the output.

@kripken

kripken commented Aug 1, 2024

Copy link
Copy Markdown
Member

I see we have test_cmake_threads in test/test_other.py. That enables shared memory here:

find_package(Threads REQUIRED)

Is that not enough to show the problem this PR fixes? (If not, can we add to that test, or add a new one?)

@m4burns

m4burns commented Aug 2, 2024

Copy link
Copy Markdown
Contributor Author

I'm guessing nothing in that test calls check_type_size - I will try to add a test for this.

@sbc100

sbc100 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Seems like someone else was experiencing this in #27932. I'll see if I can revive this PR

@sbc100

sbc100 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

I created #27934, unless @m4burns you want to update this one instead?

@m4burns

m4burns commented Oct 9, 2026 via email

Copy link
Copy Markdown
Contributor Author

@sbc100

sbc100 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of #27934

@sbc100 sbc100 closed this Oct 9, 2026
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 9, 2026
Supersedes emscripten-core#22304.

Instead of linking an executable with `--oformat=wasm` or
`--oformat=bare`, set `CMAKE_TRY_COMPILE_TARGET_TYPE` to
`STATIC_LIBRARY` so `try_compile` only compiles and archives the object
file without running the linker.

Pass `-fno-lto` so that even when `-flto` is present in `CFLAGS`, a
standard Wasm object file (containing the plain ASCII `INFO:size[...]`
string) is emitted rather than LLVM bitcode.

Also add `-sWASM_WORKERS`, `-sEXIT_RUNTIME`, and `-flto` coverage to
`test_cmake_check_type_size`.

Fixes: emscripten-core#27932
sbc100 added a commit that referenced this pull request Oct 9, 2026
Supersedes #22304.

Instead of linking an executable with `--oformat=wasm` or
`--oformat=bare`, set `CMAKE_TRY_COMPILE_TARGET_TYPE` to
`STATIC_LIBRARY` so `try_compile` only compiles and archives the object
file without running the linker.

Pass `-fno-lto` so that even when `-flto` is present in `CFLAGS`, a
standard Wasm object file (containing the plain ASCII `INFO:size[...]`
string) is emitted rather than LLVM bitcode.

Also add `-sWASM_WORKERS`, `-sEXIT_RUNTIME`, and `-flto` coverage to
`test_cmake_check_type_size`.

Fixes: #27932

---------

Co-authored-by: Marc Burns <m4burns@uwaterloo.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants