c-abi probe: strip Windows host macros; wchar always emitted for freestanding (2026.9.18.3) - #672
Closed
Sunrisepeak wants to merge 3 commits into
Closed
Sunrisepeak wants to merge 3 commits into
Sunrisepeak wants to merge 3 commits into
Conversation
…e wchar realisation on a freestanding target no longer assumes the toolchain default is 32 bits (2026.9.18.3)
…ionally bb0437d dropped the freestanding ? 32 : native_wchar_bits(os) special case that 7097acd had added, on the grounds that it was wrong on Windows hosts. That is right for the -U_<WIN32>-stripped probe, but for the REAL compile (the one whose cflags the engine broadcasts to the package's own translation units) the toolchain's freestanding default on Windows is host-contaminated: clang on Windows emits a 16-bit wchar_t by default for -target=riscv64-none-elf unless told otherwise. So a declaration of wchar=32 needs -fno-short-wchar on every freestanding target regardless of what native_wchar_bits(os) says, and the previous "if (decl.wcharBits != native)" gate lets a 32-bit declaration through to a 16-bit compile on Windows freestanding. Symmetric for wchar=16: a freestanding Linux/macOS host's default wchar is 32, and the declaration 16 needs -fshort-wchar. The "hosted" branch (the else-if) keeps the old behaviour; only the freestanding branch is restructured. Verified locally with openkal-musl#37 and openkal-llvm-runtime#24's matrix against mcpp built from this branch.
…o-short-wchar
The previous parameter order put hostStripMacros before cacheRoot. That
meant callers passing a custom cache directory (the test suite does this
in every TEST) had to also pass an empty hostStripMacros, even though
they did not care about the strip. Reordering puts cacheRoot first so
the strip's default value (`{}`) is what callers that override cache
actually mean, and tests that want to assert the strip's behaviour pass
both. prepare.cppm's call passes both, in the reordered order.
The "presents = none" wchar branch used to assert tokens.empty(). That
is wrong under the new freestanding-wchar rule: -fno-short-wchar is
emitted regardless of presents, because the wchar realisation is
about width (the toolchain's host-contaminated default), not about
identity (what macros the preprocessor states). Updated to assert the
flag's presence and the absence of any identity macros.
Sunrisepeak
marked this pull request as draft
September 18, 2026 05:55
Sunrisepeak
force-pushed
the
fix/c-abi-probe-strips-windows-host-macros
branch
from
September 18, 2026 05:56
c98fedb to
e2ed1e1
Compare
Member
Author
|
Superseded by #673 — same fix, plus an additional test refinement commit. All openkal ecosystem CI was triggered against this branch's content (the rebased 3-commit series e2ed1e1 / f661260 / 534b1ee carries the same fix as #673's first three); #673 adds a fourth test refinement. Closing this in favor of #673 for clarity. |
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.
What this PR fixes
The c-abi probe fails on two real pairings today, both on Windows
hosts cross-compiling to a non-Windows target where the host's
toolchain leaks macros the target's --target= substitution does not
strip:
openkal-llvm-runtime#24:
Windows host × riscv64-none-elf (freestanding)
The probe reports:
SIZEOF_WCHAR_T declared 32 measured 16
_WIN32 declared undefined measured defined
Both are defects at the engine boundary, not in either package's
manifest, and neither is reachable on Linux or macOS hosts (both pass
today). The structural root causes are:
clang on a Windows host defines _WIN32 in its preprocessor output
for ANY --target= triple (hosted --target= rewrites host macros;
freestanding --target= does not). The probe has no way to
compensate.
musl's [c-abi] declaration says wchar = 32, because musl's
wchar_t is 32 bits on every target it covers. For freestanding,
the toolchain's host-contaminated default controls the actual
compile (16 on Windows hosts), and the engine was relying on a
"freestanding skips the wchar flag" rule that does not hold on
Windows hosts.
What this PR does
c-abi probe gains a
hostStripMacrosparameter (defaulting to {} forbackwards compat) that the build layer can use to insert -U
tokens before -E -dM. The cache key folds the strip list in so two
probes that differ only in strip list do not share a slot.
The build layer (prepare.cppm) passes
_WIN32,_WIN64,__MINGW32__,__MINGW64__to hostStripMacros on every c-abi probeit runs, regardless of target. This is the four names the build's
own measurements have surfaced as Windows-host leaks; the parameter
is a list (not a fixed set) so a future host whose compiler leaks a
different macro can be handled the same way without further changes
to this module.
The wchar realisation (cenv.cppm) is restructured so a freestanding
target gets -fno-short-wchar unconditionally for wchar=32 (and
-fshort-wchar for wchar=16); the hosted branch keeps the old
"compare against native_wchar_bits(os)" gate. Without this, the
Windows-host × freestanding pairing still leaks 16-bit wchar_t into
the compile the engine then measures.
Versioning
This is 2026.9.18.3. mcpp.toml and modules/versioning are bumped;
docs/22 and CHANGELOG are updated.
Measured
openkal-musl#37 (this fix's 2026.9.18.3 binary, locally built):
5/5 CI green, including cross-link for the other system (the
freestanding QEMU path).
openkal-llvm-runtime#24 (this fix's 2026.9.18.3 binary):
mcpp's own unit tests for cenv and cenv_probe (test_cenv.cpp,
test_cenv_probe.cpp, added by this PR): PASS locally on x86_64-linux.
The new test_cenv_probe.cpp covers both the strip-list folding into
the cache key and the four Windows-host macros' effect on a probe
that asks for them undefined.