build: link the CRT-free startup and lifetime fixtures at /O2 #385

Manually merged
github merged 1 commit from gh-pr/385/head into gh-pr/385/base 2026-11-26 21:47:44 +00:00
Owner

@⁠grahamster2 on GitHub · 2026-11-22 00:02 UTC · original
grahamster2:build/crt-free-byte-copies → main · +22 −4 · 3 files · 1 commits · merged 2026-11-22 00:25 UTC

Solves an independent problem: a Release (/O2) build of the repository does not link.

Problem

cpu_startup_a, cpu_startup_a_alt, cpu_life_sink, cpu_startup_exe, cpu_startup_exe_create and cpu_startup_exe_timeout are CRT-free (/Zl, /NODEFAULTLIB). At /O2, MSVC's loop idiom recognition replaces their byte-copy loops with calls to memcpy, which nothing provides:

startup_a.cpp.obj : error LNK2019: unresolved external symbol memcpy referenced in function a_snapshot
startup_exe.cpp.obj : error LNK2019: unresolved external symbol memcpy referenced in function "void __cdecl `anonymous namespace'::write_line(...)"

The dev preset is Debug (/Od), so CI never sees it. The three EXEs only show up once the DLLs they link against are fixed.

Change

The four fixed-length copy loops (a_snapshot, sink_log, sink_snapshot, write_line) now copy with the __movsb intrinsic, which always emits rep movsb inline and never calls a library function. A zero or negative count still copies nothing, as before. The NUL-terminated prefix loop in write_line is left as it is, since MSVC does not turn it into a call. No CMake or test changes.

Evidence

Windows 11 Pro build 26200, VS Build Tools 2026 18.3 (MSVC 19.50.35725), Windows SDK 10.0.26100, Python 3.12, at 6c0c52e on 4f6c39d.

cmake -S . -B out/build/release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=cl
cmake --build out/build/release
ctest --test-dir out/build/release --no-tests=error -E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$'
  • Before: the Release build fails with the LNK2019 above (three DLLs, then three EXEs).
  • After: the Release build links every target with no warnings, and 143 of 143 tests pass, including cpu_native_startup, cpu_native_exe_start, cpu_native_lifetime and cpu_native_crt_lifecycle. The same 143 pass in the Debug dev preset.
  • The three excluded tests were not run on this machine.

A Release job in CI would catch this class of failure. I've left that for a separate change.

**@⁠grahamster2** on GitHub · 2026-11-22 00:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/385) `grahamster2:build/crt-free-byte-copies` → `main` · +22 −4 · 3 files · 1 commits · merged 2026-11-22 00:25 UTC Solves an independent problem: a Release (`/O2`) build of the repository does not link. ## Problem `cpu_startup_a`, `cpu_startup_a_alt`, `cpu_life_sink`, `cpu_startup_exe`, `cpu_startup_exe_create` and `cpu_startup_exe_timeout` are CRT-free (`/Zl`, `/NODEFAULTLIB`). At `/O2`, MSVC's loop idiom recognition replaces their byte-copy loops with calls to `memcpy`, which nothing provides: startup_a.cpp.obj : error LNK2019: unresolved external symbol memcpy referenced in function a_snapshot startup_exe.cpp.obj : error LNK2019: unresolved external symbol memcpy referenced in function "void __cdecl `anonymous namespace'::write_line(...)" The `dev` preset is Debug (`/Od`), so CI never sees it. The three EXEs only show up once the DLLs they link against are fixed. ## Change The four fixed-length copy loops (`a_snapshot`, `sink_log`, `sink_snapshot`, `write_line`) now copy with the `__movsb` intrinsic, which always emits `rep movsb` inline and never calls a library function. A zero or negative count still copies nothing, as before. The NUL-terminated prefix loop in `write_line` is left as it is, since MSVC does not turn it into a call. No CMake or test changes. ## Evidence Windows 11 Pro build 26200, VS Build Tools 2026 18.3 (MSVC 19.50.35725), Windows SDK 10.0.26100, Python 3.12, at `6c0c52e` on `4f6c39d`. cmake -S . -B out/build/release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=cl cmake --build out/build/release ctest --test-dir out/build/release --no-tests=error -E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$' - Before: the Release build fails with the LNK2019 above (three DLLs, then three EXEs). - After: the Release build links every target with no warnings, and 143 of 143 tests pass, including `cpu_native_startup`, `cpu_native_exe_start`, `cpu_native_lifetime` and `cpu_native_crt_lifecycle`. The same 143 pass in the Debug `dev` preset. - The three excluded tests were not run on this machine. A Release job in CI would catch this class of failure. I've left that for a separate change.
cpu_startup_a, cpu_startup_a_alt, cpu_life_sink and the three
cpu_startup_exe images are built with /Zl and /NODEFAULTLIB. At /O2,
MSVC's loop idiom recognition turns their byte-copy loops into calls to
memcpy, which nothing provides, so a Release build fails with LNK2019.
The Debug preset that CI uses does not optimize and never hits this.

Copy with the __movsb intrinsic instead, which always emits rep movsb
inline. Each copy keeps the old loop's behavior for a zero or negative
count.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:47:43 +00:00
github manually merged commit 6c0c52efde into gh-pr/385/base 2026-11-26 21:47:44 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.