Fix simd (default) build on clang >=16: undeclared libm fns in shim math.h - #1
Open
Leonardo-Rocha wants to merge 1 commit into
Open
Fix simd (default) build on clang >=16: undeclared libm fns in shim math.h#1Leonardo-Rocha wants to merge 1 commit into
Leonardo-Rocha wants to merge 1 commit into
Conversation
The bundled wasm-sse2 compat headers (emscripten's SSE2->wasm128 shims, under shims/include/wasm-sse2/) reference fabs/lrint/lrintf/llrint/llrintf in their inline conversion helpers, but the freestanding shim math.h never declares them and stdb.rs exports only the float libm functions. clang 16 promoted -Wimplicit-function-declaration to a default error, so on any clang >= 16 a default (simd) build fails while parsing those headers: xmmintrin.h:600: error: call to undeclared function 'lrint' emmintrin.h:388: error: call to undeclared function 'fabs' Older clang (implicit decl = warning) or a toolchain whose own headers declare these hides the gap. It reproduces cleanly under zig cc (clang 18) in a strict -ffreestanding include setup where nothing leaks the decls. Add static inline definitions that lower to native wasm ops (f64.abs, f64.nearest + trunc conversions) — no libcall and no Rust-side libm export needed, so the fix is self-contained in the shim regardless of whether any path actually references them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: assisted by Claude Fable 5.
What
The bundled
wasm-sse2compat headers (emscripten's SSE2→wasm128 shims, undercrates/box3d-sys/shims/include/wasm-sse2/) referencefabs/lrint/lrintf/llrint/llrintfin their inline conversion helpers. But the freestanding shimmath.hnever declares them, andstdb.rsexports only the float libm functions (sinf…logf) — these five doubles are declared nowhere.Why it fails now
clang 16 promoted
-Wimplicit-function-declarationfrom a warning to a default error (the C99 non-conformance cleanup; GCC 14 followed). So a defaultcargo build—simdis on by default — hard-fails on any clang ≥16 while parsing those headers:It's a frontend diagnostic, not a link failure — the helpers are mostly unused and would be dropped at link, but the parse error fires regardless. It stays hidden on older clang (implicit-decl still a warning) or a toolchain whose own headers declare these ahead of the shim. Reproduces cleanly under
zig cc(clang 18) with a strict-ffreestandinginclude layout where nothing leaks the decls.The fix
Add static inline definitions to the shim
math.h. They lower to native wasm ops (f64.abs,f64.nearest+ trunc conversions) — no libcall, and no Rust-side libm export needed, so the fix is self-contained in the header. Zero behavior change for toolchains that already build: clang lowersfabs/lrintto the same native ops today; this only makes the declarations always visible.Alternatives considered
Bare
externdeclarations (matching the existing float-decl style) + exporting the doubles fromstdb.rslikesinf/etc. Works too, but needs a Rust export and a libcall; the inline-builtin form avoids both. Happy to switch to whichever you prefer for consistency.Verification (wasm32-unknown-unknown)
simddefault, clang 18 via zig cc): fails with the errors above.cargo build -p box3d-sys --target wasm32-unknown-unknowncompiles clean.Repro note (zig cc only)
If reproducing with
zig cc, also rewrite-isystem <dir>→-I <dir>for the shim dirs: zig prepends its bundled x86 intrinsic headers ahead of caller-isystemdirs and would otherwise shadow the compat shims with real x86 SSE2. Not relevant to the fix itself — noted in case it helps anyone verifying.