Skip to content

2026.9.26.2: xlings runs in a directory outside the ANSI code page and never exits silently - #613

Merged
Sunrisepeak merged 2 commits into
mainfrom
fix/utf8-code-page-and-exception-boundary
Sep 25, 2026
Merged

Sunrisepeak merged 2 commits into
mainfrom
fix/utf8-code-page-and-exception-boundary

Conversation

@Sunrisepeak

@Sunrisepeak Sunrisepeak commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

mcpp issue #693 reports that on Windows (system ANSI code page 936), running mcpp --version from a directory whose name contains a character outside the ANSI code page (for example U+1F9EA) exits with 0xC0000409 and prints nothing.

A measurement on a GitHub windows-latest runner (ACP 1252) established that the process which dies is xlings, not the released mcpp.exe. Both xlings --version and the xlings shim mcpp.exe (a copy of xlings.exe) exit 0xC0000409 with no output when the working directory is outside the ACP, and work normally in ASCII directories and in C:\w\café (é is in cp1252). A debugger session on xlings --version in the failing directory recorded a first-chance C++ exception (e06d7363) whose what() is "No mapping for the Unicode character exists in the target multi-byte code page" — the MSVC STL throwing std::system_error while narrowing a std::filesystem::path through the ANSI code page. It is unhandled: src/main.cpp had no try/catch at all, so std::terminate → abort → a fast-fail exit, roughly eleven frames into start-up, before any command runs. Embedding a UTF-8 activeCodePage application manifest (Windows 10 1903+) was separately measured to fix the same class of failure for mcpp.exe: std::filesystem::path::string() then returns UTF-8 and never throws, and the -A Win32 APIs take UTF-8.

Changes

1. A UTF-8 activeCodePage manifest embedded in xlings.exe. mcpp.toml gains a [resources] section:

[resources]
files = ["res/xlings.rc"]
extra-inputs = ["res/xlings.exe.manifest"]

res/xlings.rc embeds res/xlings.exe.manifest at ordinal 1 (CREATEPROCESS_MANIFEST_RESOURCE_ID) as RT_MANIFEST (24). [resources] compiles only on PE targets (mcpp docs/04-mcpp-toml.md §2.15), so Linux and macOS builds are unaffected; a local Linux build with this change applied built cleanly with no resource-related output. The manifest is listed under extra-inputs as well as files, because mcpp's .rc scanner recognizes the MANIFEST keyword but not the numeric resource type (24) used here (confirmed by reading src/build/resources.cppm's is_file_resource_keyword), so without extra-inputs an edit to the manifest would not trigger a relink. Only files and extra-inputs are used — both have shipped since [resources]'s original release (mcpp 2026.8.7.1), before the bootstrap pin this project uses (2026.8.8.4).

The shims xlings creates on Windows are hard links or, failing that, file copies of xlings.exe (create_shim in src/core/xself/init.cpp), so they carry the same manifest — no shim-specific work is needed.

2. An exception boundary in src/main.cpp. Everything after argv handling — the owner-anchored home lookup, Config::paths(), capture_ambient_home_env(), the profile auto-upgrade, cli::run, and shim_dispatch — now runs inside a try/catch. On std::exception it logs internal error: {what()} through xlings::log::error (the same call xlings::cli::run's own top-level handler already uses) and returns a non-zero code; on any other exception it logs a generic internal error: unknown exception line. xlings::cli::run already wraps its own dispatch (added for issue #583); shim_dispatch and everything that runs before either of them did not have a handler. This is the fallback for hosts where the manifest has no effect — Windows older than 1903, or a build where the resource could not be embedded — so the failure is reported instead of silent. The macOS _Exit behavior after dispatch is unchanged.

3. A Windows CI regression step. .github/workflows/xlings-ci-windows.yml runs a new step, tests/e2e/ansi_code_page_directory_test.ps1, right after Build (windows_release). The script:

  • reads the runner's ANSI code page from the registry (HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP) and fails with an explicit message if it is already 65001 (UTF-8), since the step would then prove nothing;
  • builds a repro directory name from code points ([char]0x6D4B, [char]0x8BD5, [char]::ConvertFromUtf32(0x1F9EA)), so the workflow source stays plain ASCII, combining CJK characters and the exact U+1F9EA character from the mcpp#693 report;
  • runs the freshly built xlings.exe --version in that directory and asserts exit code 0 and that the output contains the expected version string;
  • also runs xlings.exe config there, exercising the project-config search from that working directory;
  • extracts the manifest from the built xlings.exe with mt.exe -inputresource:<exe>;#1 and asserts the extracted XML contains activeCodePage.

Version

2026.9.20.1 → 2026.9.26.2 in mcpp.toml and src/core/config.cppm (the only two version literals in the repository; confirmed by diffing the previous release commit and grepping the tree). #612 merged and released 2026.9.26.1 for an unrelated fix while this PR was in review, so this branch was rebased onto the new main and takes the next number in the day's sequence rather than reusing one already published.

Verification

  • Local Linux build (mcpp build) succeeds with the [resources] section present, producing xlings v2026.9.26.2 with no resources-related warnings or errors — confirming the section is inert on a non-PE target. Rebuilt again after rebasing onto main past fix: a dependency means the package in its own index; a subos's user data leaves only when the user says so (2026.9.26.1) #612, which also touched src/main.cpp (a new destructive_log::set_command call in the same block this PR wraps in try); the merge keeps that call, ordered before the std::move it needs to precede.
  • The Windows-specific behavior (resource compilation, manifest embedding, the ACP mitigation itself) can only be verified on a real Windows host; that is what the new CI step is for. All 9 CI checks passed on the pre-rebase commit (Windows, Linux ×2, Linux e2e, Linux root ×2, macOS, aarch64 ×2); re-running after the rebase to confirm the merge.

…ode page and never exits silently (2026.9.26.2)

mcpp#693 reports that on Windows, running mcpp --version from a directory
whose name contains a character outside the system's ANSI code page (for
example U+1F9EA) exits with 0xC0000409 and prints nothing. Measured on a
GitHub windows-latest runner (ACP 1252): the process that dies is xlings,
not the released mcpp.exe. Both `xlings --version` and the xlings shim
`mcpp.exe` (a copy of xlings.exe) exit 0xC0000409 with no output when the
working directory is outside the ACP, and work normally in ASCII
directories and in directories whose non-ASCII characters fall inside
cp1252. A debugger session recorded an unhandled C++ exception whose
message is "No mapping for the Unicode character exists in the target
multi-byte code page" — the MSVC STL throwing std::system_error while
narrowing a std::filesystem::path through the ANSI code page. src/main.cpp
installed no try/catch, so the exception reached std::terminate, abort,
and a fast-fail exit roughly eleven frames into start-up, before any
command ran.

Three changes.

A UTF-8 activeCodePage application manifest is now embedded in
xlings.exe. mcpp.toml gains a [resources] section compiling res/xlings.rc,
a hand-written resource script that embeds res/xlings.exe.manifest at
ordinal 1 (CREATEPROCESS_MANIFEST_RESOURCE_ID) as RT_MANIFEST (24). On
Windows 10 1903 and later, this manifest makes the process's own ANSI
code page UTF-8: std::filesystem::path::string() then returns UTF-8
instead of throwing, and the -A Win32 APIs accept UTF-8. [resources]
compiles only on PE targets, so the Linux and macOS builds are
unaffected; a local Linux build with the change applied produced no
resource-related output. The manifest is listed under [resources]
extra-inputs as well, because mcpp's .rc scanner recognises the MANIFEST
keyword but not the numeric resource type (24) used here, and an
undeclared input would not trigger a relink when the manifest changes.
The shims xlings creates on Windows are hard links or file copies of
xlings.exe (create_shim in src/core/xself/init.cpp), so they carry the
same manifest.

src/main.cpp now runs everything after argv handling — the
owner-anchored home lookup, Config::paths(), capture_ambient_home_env(),
the profile auto-upgrade, cli::run, and shim_dispatch — inside a
try/catch, reporting std::exception and any other exception through
xlings::log::error (the convention xlings::cli::run's own top-level
handler already uses) and returning a non-zero exit code, instead of
letting the exception reach std::terminate. xlings::cli::run already
wraps its own dispatch; shim_dispatch and everything that runs before
either of them did not have a handler. This is the fallback for hosts
where the manifest has no effect — Windows older than 1903, or a build
where the resource could not be embedded — and turns a silent,
unattributable crash into a reported error. The macOS _Exit behaviour
after dispatch is unchanged.

.github/workflows/xlings-ci-windows.yml runs a new regression step,
tests/e2e/ansi_code_page_directory_test.ps1, right after the release
build. The script asserts the runner's registry ANSI code page is not
already 65001 (otherwise the step could not exercise the code path it
exists to test), builds a directory name from code points — so the
workflow source stays ASCII — combining CJK characters and the U+1F9EA
character from the original report, and in that directory runs the
freshly built xlings.exe --version (asserting exit code 0 and the
expected version string) and xlings.exe config (exercising the
project-config search from that working directory). It then extracts
the manifest from the built executable with mt.exe and asserts it
declares activeCodePage.

Version 2026.9.20.1 -> 2026.9.26.2 (mcpp.toml, src/core/config.cppm). #612
merged 2026.9.26.1 for an unrelated fix while this change was in review, so
this PR takes the next number in the day's sequence rather than reusing one
already released.
@Sunrisepeak
Sunrisepeak force-pushed the fix/utf8-code-page-and-exception-boundary branch from eb6be62 to ad2ee85 Compare September 25, 2026 18:23
@Sunrisepeak Sunrisepeak changed the title 2026.9.26.1: xlings runs in a directory outside the ANSI code page and never exits silently 2026.9.26.2: xlings runs in a directory outside the ANSI code page and never exits silently Sep 25, 2026
@Sunrisepeak
Sunrisepeak merged commit 2e3df6d into main Sep 25, 2026
9 checks passed
Sunrisepeak pushed a commit to mcpp-community/mcpp that referenced this pull request Sep 25, 2026
…ink measured on four legs

- kXlingsVersion and every xlings pin in .github move to 2026.9.26.2
  (openxlings/xlings#613): xlings.exe declares the UTF-8 code page and its
  main has an exception boundary, so a working directory or an MCPP_HOME
  outside the ANSI code page no longer ends it with 0xC0000409 and no output.
- test_cache_key stated the old rule, that a package's `c_standard = "c11"`
  is keyed; a package that spells the default and one that says nothing
  compile identically and now share a key. CI run 1 failed that test on every
  platform, and nothing else in the unit suites.
- e2e 778 pins each leg to the openkal-musl and openkal-llvm-runtime pair that
  belongs together (the runtime pins openkal-musl exactly, and a root that
  pins another is refused as irreconcilable), and adds the report's aarch64
  case under qemu-aarch64 and a host `-L` refused by the hermetic check. The
  openkal job asserts each leg ran.
- docs: a macOS file name is UTF-8; `allow_host_libs` lifts the graph-link
  refusal rather than turning it into a warning.
- The plan's implementation record carries CI run 1: every Windows row of the
  regression job passes, and the two xcode-27 legs fail as on main (#669).
Sunrisepeak pushed a commit to mcpp-community/mcpp that referenced this pull request Sep 25, 2026
…ithout the host, and the level that was declared (#698)

* 2026.9.26.1: paths in UTF-8, a C standard per package, a graph link without the host, and the level that was declared

#693. mcpp held paths in the Windows ANSI code page, and the JSON it writes
holds UTF-8 only, so every build under a non-ASCII project directory or home
failed with an internal JSON exception, including names the code page can
spell; a Latin-1 directory name fails the same way on Linux. mcpp.exe now
declares the UTF-8 code page (res/mcpp.rc), build programs are linked with the
same manifest, host tools default to it, and the new target key
`windows_code_page` states it for a project's own executables. A path with no
UTF-8 spelling is refused (project directory, MCPP_HOME), skipped and reported
(a name inside a project), or refused by key (a build.mcpp directive), never an
internal exception. The response files of the msvc dialect begin with a byte
order mark, which cl.exe, link.exe and lib.exe need to read UTF-8 (measured),
and Ninja's own encoding is checked when build.ninja is not ASCII.

#695. `[build] c_standard` reached every C unit of the graph through the
file-level $cflags, and a dependency's own value was not applied. Each package's
C units now compile at that package's standard; an undeclared package at c11.

#696. A link over a graph-supplied C library searched the host's library
directories, so `-lm` linked glibc objects into a musl image. Such a link on ELF
now carries --sysroot naming an empty directory, the hermetic check holds every
-L to the store, the build directory and the graph's packages, and an
unanswered -l fails with a note naming openkal-musl 0.19.2.

#694. The musl -Og workaround is removed; the compile and the Finished line
read one realised optimization level.

Plan and measurements: .agents/docs/2026-09-25-issues-693-696-triage-and-repair-plan.md

* xlings 2026.9.26.2, the key rule a test still stated, and the graph link measured on four legs

- kXlingsVersion and every xlings pin in .github move to 2026.9.26.2
  (openxlings/xlings#613): xlings.exe declares the UTF-8 code page and its
  main has an exception boundary, so a working directory or an MCPP_HOME
  outside the ANSI code page no longer ends it with 0xC0000409 and no output.
- test_cache_key stated the old rule, that a package's `c_standard = "c11"`
  is keyed; a package that spells the default and one that says nothing
  compile identically and now share a key. CI run 1 failed that test on every
  platform, and nothing else in the unit suites.
- e2e 778 pins each leg to the openkal-musl and openkal-llvm-runtime pair that
  belongs together (the runtime pins openkal-musl exactly, and a root that
  pins another is refused as irreconcilable), and adds the report's aarch64
  case under qemu-aarch64 and a host `-L` refused by the hermetic check. The
  openkal job asserts each leg ran.
- docs: a macOS file name is UTF-8; `allow_host_libs` lifts the graph-link
  refusal rather than turning it into a warning.
- The plan's implementation record carries CI run 1: every Windows row of the
  regression job passes, and the two xcode-27 legs fail as on main (#669).

* SPEC-002 rule three: a link over a graph-supplied C library searches no host directory (v1.1)

---------

Co-authored-by: speak-agent <[email protected]>
Sunrisepeak pushed a commit to mcpp-community/mcpp that referenced this pull request Sep 25, 2026
…gs (#700)

The plan's status moves to landed, and its implementation record (§12.4 to
§12.6, Appendix A.15) states what was released and measured:

- mcpp 2026.9.26.1 (#698), xlings 2026.9.26.2 (openxlings/xlings#613),
  openkal-musl 0.19.2 and openkal-llvm-runtime 0.15.2, each mirrored to GitCode
  and checked against its GitHub sha256, and registered or indexed;
- the sandbox check of the published artefacts (12 ok) and the same script
  against 2026.9.25.1 (exactly the six criteria the release changes fail);
- mcpp-index#469's sweep (green on every platform) and its openkal
  measurement over four targets, where the one cell #696 makes visible,
  mimalloc's `-latomic` on the linux-musl rows, is filed with its owner
  (mcpplibs/openkal-llvm-runtime#31);
- the self-review, and what remains open with the reason for each.

Co-authored-by: speak-agent <[email protected]>
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.

2 participants