From c2b5df07de05c2d84c9246868cd05a1ee1ea1669 Mon Sep 17 00:00:00 2001 From: whoalin1 <207920491+whoalin1@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:28:02 +0200 Subject: [PATCH 1/2] runtime: link no-relocation fixtures without incremental linking --- runtime/CMakeLists.txt | 13 +++++--- tests/test_runtime_incremental_link.py | 46 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/test_runtime_incremental_link.py diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 411a52b6ca..daf56f3f21 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1243,7 +1243,12 @@ if(BUILD_TESTING) target_link_libraries(tiny_game_fixed PRIVATE xgameruntime_stub) target_compile_definitions(tiny_game_fixed PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS) target_compile_options(tiny_game_fixed PRIVATE /W4 /permissive- /utf-8 /EHsc) - target_link_options(tiny_game_fixed PRIVATE /FIXED /DYNAMICBASE:NO /BASE:0x140000000) + # /INCREMENTAL:NO, here and on the fixtures linked with /NODEFAULTLIB below: such an image can have no base + # relocations, and VS 2026 18.6's linker (MSVC 14.51) crashes on an incremental relink of one ("LNK1000: Internal + # error during IncrCalcPtrs"). CMake's Ninja and Makefile generators relink every target once in each clean Debug + # or RelWithDebInfo build (/debug /INCREMENTAL by default), with only its manifest resource changed, to embed it. + # Fixed in VS 2026 18.7; tests/test_runtime_incremental_link.py keeps a new fixture of this kind covered. + target_link_options(tiny_game_fixed PRIVATE /FIXED /DYNAMICBASE:NO /BASE:0x140000000 /INCREMENTAL:NO) set_target_properties(tiny_game_fixed PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fixtures/game/$" ) @@ -1363,7 +1368,7 @@ if(BUILD_TESTING) add_library(tiny_tls_cb_only SHARED test/fixtures/tiny_tls_cb_only.cpp) target_compile_definitions(tiny_tls_cb_only PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) target_compile_options(tiny_tls_cb_only PRIVATE /W4 /permissive- /utf-8 /GS-) - target_link_options(tiny_tls_cb_only PRIVATE /NODEFAULTLIB /ENTRY:DllMainCRTStartup) + target_link_options(tiny_tls_cb_only PRIVATE /NODEFAULTLIB /ENTRY:DllMainCRTStartup /INCREMENTAL:NO) target_link_libraries(tiny_tls_cb_only PRIVATE kernel32) set_target_properties(tiny_tls_cb_only PROPERTIES OUTPUT_NAME tiny_tls_cb_only @@ -1448,7 +1453,7 @@ if(BUILD_TESTING) # DllMain's only work is that one call. No game files. add_library(dll_thread_calls SHARED test/fixtures/dll_thread_calls.cpp) target_compile_options(dll_thread_calls PRIVATE /W4 /permissive- /utf-8 /GS-) - target_link_options(dll_thread_calls PRIVATE /NODEFAULTLIB /ENTRY:dll_thread_calls_main) + target_link_options(dll_thread_calls PRIVATE /NODEFAULTLIB /ENTRY:dll_thread_calls_main /INCREMENTAL:NO) target_link_libraries(dll_thread_calls PRIVATE kernel32) set_target_properties(dll_thread_calls PROPERTIES OUTPUT_NAME dll_thread_calls @@ -1518,7 +1523,7 @@ if(BUILD_TESTING) if(GAMEINPUT_LIBRARY) add_library(gameinput_host SHARED test/fixtures/gameinput_host.cpp) target_compile_options(gameinput_host PRIVATE /W4 /permissive- /utf-8 /GS-) - target_link_options(gameinput_host PRIVATE /NODEFAULTLIB /ENTRY:gameinput_host_main) + target_link_options(gameinput_host PRIVATE /NODEFAULTLIB /ENTRY:gameinput_host_main /INCREMENTAL:NO) target_link_libraries(gameinput_host PRIVATE kernel32 ${GAMEINPUT_LIBRARY}) set_target_properties(gameinput_host PROPERTIES OUTPUT_NAME gameinput_host diff --git a/tests/test_runtime_incremental_link.py b/tests/test_runtime_incremental_link.py new file mode 100644 index 0000000000..5b931f0256 --- /dev/null +++ b/tests/test_runtime_incremental_link.py @@ -0,0 +1,46 @@ +"""The runtime fixtures that can have no base relocations link with /INCREMENTAL:NO (no build run). + +VS 2026 18.6's linker (MSVC 14.51) crashes with "LNK1000: Internal error during IncrCalcPtrs" on an incremental +relink of an image with no base relocations. CMake's Ninja and Makefile generators relink every target once, with only +its manifest resource changed, in each clean Debug or RelWithDebInfo build (default link flags /debug /INCREMENTAL). +A fixture linked with /FIXED has its relocations stripped, and one linked with /NODEFAULTLIB has no CRT and often no +absolute address to relocate, so each of them links with /INCREMENTAL:NO. +https://developercommunity.visualstudio.com/t/MSVC-v1451-Linker-Crash-in-IncrCalcPtrs/11090307 + + python -I tests/test_runtime_incremental_link.py +""" +import os +from pathlib import Path +import re +import unittest + +ROOT = Path(__file__).resolve().parents[1] +CMAKE = Path(os.environ.get("LEONIDA_RUNTIME_CMAKE", str(ROOT / "runtime" / "CMakeLists.txt"))) + + +def link_options(text): + """Each target named in a target_link_options call, with every option the calls give it.""" + options = {} + for target, args in re.findall(r"target_link_options\(\s*([A-Za-z0-9_]+)\s+([^)]*)\)", text): + options.setdefault(target, []).extend(args.split()) + return options + + +class FixturesWithoutRelocationsLinkNonIncrementally(unittest.TestCase): + def test_every_fixed_or_crt_free_target_links_with_incremental_no(self): + options = link_options(CMAKE.read_text(encoding="utf-8")) + targets = {t for t, opts in options.items() if "/FIXED" in opts or "/NODEFAULTLIB" in opts} + # The scan has to see the fixtures that crashed the linker, or it checks nothing. + self.assertLessEqual({"tiny_game_fixed", "dll_thread_calls", "gameinput_host"}, targets) + missing = sorted(t for t in targets if "/INCREMENTAL:NO" not in options[t]) + self.assertEqual(missing, [], "linked with /FIXED or /NODEFAULTLIB but not /INCREMENTAL:NO") + + def test_the_scan_reads_options_across_lines(self): + text = ("target_link_options(a PRIVATE /FIXED\n /INCREMENTAL:NO)\n" + "target_link_options(b PRIVATE /NODEFAULTLIB)\n") + self.assertEqual(link_options(text), {"a": ["PRIVATE", "/FIXED", "/INCREMENTAL:NO"], + "b": ["PRIVATE", "/NODEFAULTLIB"]}) + + +if __name__ == "__main__": + unittest.main() From 867eb160b5fc931754bbed43dc3a1a803a83b2a9 Mon Sep 17 00:00:00 2001 From: Man Alin Date: Sun, 29 Nov 2026 06:05:04 +0000 Subject: [PATCH 2/2] runtime: link fixed-base probe non-incrementally Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- runtime/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index daf56f3f21..8e0ac2a8d0 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1487,7 +1487,7 @@ if(BUILD_TESTING) add_library(fixed_base_probe SHARED test/fixtures/fixed_base_probe.cpp) target_compile_options(fixed_base_probe PRIVATE /W4 /permissive- /utf-8 /GS-) target_link_options(fixed_base_probe PRIVATE /NODEFAULTLIB /ENTRY:fixed_base_probe_main /FIXED /DYNAMICBASE:NO - /BASE:0x7E0000000) + /BASE:0x7E0000000 /INCREMENTAL:NO) target_link_libraries(fixed_base_probe PRIVATE kernel32) set_target_properties(fixed_base_probe PROPERTIES OUTPUT_NAME fixed_base_probe