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

Merged
grahamster2 merged 1 commit from upstream-pr/385 into main 2026-11-22 00:25:59 +00:00
grahamster2 commented 2026-11-22 00:02:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by grahamster2 on 2026-11-22T00:02:22Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536091820 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/385). Originally posted by [grahamster2](https://github.com/grahamster2) on 2026-11-22T00:02:22Z. --- 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.
upstream-sync closed this pull request 2026-11-24 06:42:45 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!379
No description provided.