Skip to content

wasm2c: use _addcarry_u64 only on MSVC x64, and test a 64-bit memory with MSVC - #2901

Merged
shravanrn merged 3 commits into
WebAssembly:mainfrom
natify-sh:wasm2c-addcarry-x64-only
Oct 26, 2026
Merged

shravanrn merged 3 commits into
WebAssembly:mainfrom
natify-sh:wasm2c-addcarry-x64-only

Conversation

@o-murphy

Copy link
Copy Markdown
Contributor

checked_add_u64 in wasm2c.declarations.c uses _addcarry_u64 for every MSVC
target, but that intrinsic exists only on x64. A module with a 64-bit memory that
loads or stores fails to link with MSVC for x86 and for ARM64:

error LNK2019: unresolved external symbol __addcarry_u64 referenced in function _checked_add_u64   (Win32)
error LNK2019: unresolved external symbol _addcarry_u64 referenced in function checked_add_u64     (ARM64)

This restricts the branch to _M_X64; the other MSVC targets use the existing
portable #else branch.

The problem was not caught by CI because run-spec-wasm2c.py skips the test
whenever memory64 is enabled on Windows. That skip was written for the opt-in
--enable-memory64 (#2086). After #2837 made memory64 the default and renamed the
flag to --disable-memory64, the condition holds for almost every test, so 260 of
the 262 wasm2c tests are skipped on windows-latest, and the C that wasm2c writes
is not compiled by cl.exe at all. This PR:

  • removes that skip;
  • adds test/wasm2c/msvc-compile.txt, a spec test of a module with a 64-bit memory
    (a store and load, and an out-of-bounds access that traps);
  • adds a CI job that builds wabt for Windows x86 (-A Win32) and ARM64
    (windows-11-arm) and runs that test (-DWABT_RUN_TESTS_ARGS=msvc-compile).
    The filter has no slash because the paths have backslashes on Windows.

Regenerated: src/prebuilt/wasm2c_source_declarations.cc and the expected output of
the tests in test/wasm2c/ that contain the template.

Testing: on GitHub Actions (windows-latest) the new test fails without the change
with the two LNK2019 errors above, on x86 and on ARM64, and passes with it.

Fixes #2885

Comment thread test/wasm2c/msvc-compile.txt Outdated
Comment thread test/run-spec-wasm2c.py Outdated
@o-murphy

Copy link
Copy Markdown
Contributor Author

@sbc100 Should I sqash this two commits?

@o-murphy
o-murphy marked this pull request as ready for review October 22, 2026 20:03
@o-murphy
o-murphy requested a review from sbc100 October 22, 2026 20:04
@sbc100

sbc100 commented Oct 22, 2026

Copy link
Copy Markdown
Member

We auto-squash on commit.

Would you mind sending a separate PR for the skip removal?

@o-murphy

Copy link
Copy Markdown
Contributor Author

Would you mind sending a separate PR for the skip removal?

with no extra issue opening?

@sbc100

sbc100 commented Oct 22, 2026

Copy link
Copy Markdown
Member

Yes, no need to for a a separate issue. It seems like memory64 has worked on windows x64 for while but we forgot to remove this block. So fixing that by removing that block seems separable from how we make non-x64 work.

@o-murphy

Copy link
Copy Markdown
Contributor Author

Yes, no need to for a a separate issue. It seems like memory64 has worked on windows x64 for while but we forgot to remove this block. So fixing that by removing that block seems separable from how we make non-x64 work.

yes I can, I did few launches of the CI on my own fork to check it before fix

sbc100 pushed a commit that referenced this pull request Oct 22, 2026
`run-spec-wasm2c.py` skips a test on Windows when memory64 is enabled.
That skip was written
when memory64 was opt-in (`--enable-memory64`, #2086). Since #2837
memory64 is on by default
(`--disable-memory64`), so the condition holds for almost every test and
260 of the 262 wasm2c
tests are skipped on `windows-latest`: the C that wasm2c writes is not
compiled by cl.exe.

This removes the skip. Split out of #2901 at @sbc100's request.
…with MSVC

_addcarry_u64 is an intrinsic of the x64 targets: a module with a 64-bit memory
fails to link with MSVC for x86 and ARM64 (LNK2019, unresolved external symbol
_addcarry_u64). Fall back to the portable branch there.

The problem was not seen because run-spec-wasm2c.py skipped the test whenever
memory64 is enabled on Windows. That skip was written for the opt-in
--enable-memory64; once memory64 became the default it holds for almost every
test, so the C that wasm2c writes was not compiled by cl.exe at all. Remove the
skip, add a test of a 64-bit memory, and a CI job that builds wabt for Windows
x86 and ARM64 and runs it.
@o-murphy
o-murphy force-pushed the wasm2c-addcarry-x64-only branch from 91c7f26 to 3d6ca47 Compare October 22, 2026 21:28
@o-murphy

Copy link
Copy Markdown
Contributor Author

@sbc100 rebased

Comment thread .github/workflows/build.yml Outdated

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me.

@sbc100
sbc100 requested review from keithw and shravanrn October 22, 2026 21:47
@shravanrn
shravanrn enabled auto-merge (squash) October 23, 2026 20:12
@shravanrn

Copy link
Copy Markdown
Collaborator

@o-murphy Thanks for the fix. Would you mind rebasing and squashing into one commit actually. It makes it bit easier for us to land.

@o-murphy

Copy link
Copy Markdown
Contributor Author

@o-murphy Thanks for the fix. Would you mind rebasing and squashing into one commit actually. It makes it bit easier for us to land.

Yes, I will

@shravanrn

shravanrn commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

@o-murphy Thanks for the fix. Would you mind rebasing and squashing into one commit actually. It makes it bit easier for us to land.

Yes, I will

Thanks, once you push this, we can land it

@shravanrn
shravanrn disabled auto-merge October 25, 2026 22:21
@shravanrn
shravanrn merged commit 71c2fb0 into WebAssembly:main Oct 26, 2026
19 checks passed
@o-murphy
o-murphy deleted the wasm2c-addcarry-x64-only branch October 26, 2026 07:58
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.

wasm2c: _addcarry_u64 in the C for 64-bit memories does not build with MSVC on ARM64

3 participants