Repository navigation
RR plugin: build with the static C/C++ runtime (/MT) - #13
Merged
Merged
Conversation
WrongGPU-RR.asi was the only release binary built against the shared runtime (/MD); WrongGPU.asi and wronggpu_runtime.dll are /MT. Built with linker 14.51, its std::mutex is constant-initialised, which needs msvcp140.dll 14.40 or newer (Microsoft STL changelog, VS 2022 17.10). With an older msvcp140.dll (a Wine/Proton prefix, or an old VC++ redistributable on Windows) the first lock reads a null pointer inside msvcp140 and the process dies in InitializeASI. Only plain C structures and function pointers cross the plugin's boundaries (game interface, OptiScaler's plugin table, the RR runtime table), so nothing needs a shared C runtime. The rebuilt plugin imports only KERNEL32 and VERSION. The fake runtime library and the two test programs that load it share std:: containers (tests/fake_runtime.h), so those three keep /MD. The setupapi identity test no longer depends on the order the linker puts two imports in, which changes with the runtime library. Reported-by: j0nsh1n Fixes #9 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 13, 2026 15:31
phantoslayer21
force-pushed
the
fix/rr-plugin-old-msvcp
branch
from
November 13, 2026 15:31
ba5f217 to
6f71930
Compare
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.
Reported by @j0nsh1n in #9.
What was wrong
WrongGPU-RR.asiwas the only binary of the release built against the shared C/C++ runtime (/MDinclean/rr_f/proxy/tools/build.py).WrongGPU.asiandwronggpu_runtime.dllare built with the static runtime, asBUILDING.md's CMake flags say (
CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded).The 0.6.0 plugin was built with linker version 14.51. Its
std::mutexobjects are constant-initialised.dumpbin /importsofthe shipped plugin shows
_Mtx_lockand_Mtx_unlockfrom MSVCP140.dll and no_Mtx_init_in_situ. With an oldermsvcp140.dll(a Proton prefix, or an old VC++ 2015-2022 redistributable on Windows) the first lock reads a nullpointer inside msvcp140 and the process dies in
InitializeASI.The 14.40 threshold is from Microsoft, not from a measurement here. Microsoft's STL changelog lists, under
VS 2022 17.10, "Fixed
mutex's constructor to beconstexpr" and warns that programs that don't follow the binarycompatibility restrictions "may encounter null dereferences in
mutexmachinery"(https://github.com/microsoft/STL/wiki/VS-2022-Changelog). VS 2022 17.10 is MSVC Build Tools 14.40
(https://learn.microsoft.com/en-us/cpp/overview/compiler-versions), and the restriction is that the Redistributable
must be at least as new as the latest build tools used by any app component
(https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017). So a plugin built with a constexpr
std::mutexneeds
msvcp140.dll14.40 or newer. What was measured here is one old and one new runtime (see Results): 14.29.30157.0crashes, 14.51.36247.0 doesn't. No runtime between them was tried.
Why the plugin was /MD
No reason for
/MDwas found in the code or its comments. The project's rule is static-runtime release builds. Nothingin the plugin needs the shared runtime: only plain C structures and function pointers cross its boundaries (the game
interface, OptiScaler's plugin table, the RR runtime table in
include/wg_rr_adapter.h). NoFILE*, heap block or C++object passes between modules.
What changed
build.py:CLFLAGSuses/MT. The plugin (release and probe), the file-replacement proxies and the test programsthat compile the plugin's sources all build with it.
live_harness.pybuildstest_live_harnesswith the sameCLFLAGS, so that program is/MTtoo. It shares no C++ object with another module (it reaches the plugin throughC functions only). It needs the GPU and was not built or run here.
test_proxy_dll,test_hook_dll) keep/MD(
SHARED_CRT_CLFLAGS). They share C++ containers throughtests/fake_runtime.h, so they need one heap. Theplugin under test never sees those objects.
test_setupapi_identity.cpp: one check expected the exe's two SetupAPI imports in a fixed order. The linker picksthat order, and it changed with the runtime library, so the check now accepts either order. The redirect itself
(both slots patched) was unchanged.
We did not use
/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR: it would still tie the plugin to whatevermsvcp140.dllthegame process has loaded. With
/MTthe plugin loads none.Static runtime and
DllMain: the hook plugin's and the proxy'sDllMaincallDisableThreadLibraryCalls, whichMicrosoft's documentation advises against in a DLL linked with the static runtime. This change makes those DLLs
static-runtime. The shipped static-runtime binaries (
WrongGPU.asiand the RR runtime DLL) already make the same call,the plugin's
thread_localvariables are plain pointers and flags with constant initialisers, and the tests below pass.No failure was found; the calls are left as they are in this change.
Results
WrongGPU-RR.asiimports only KERNEL32 and VERSION: no MSVCP140, VCRUNTIME140 or api-ms-win-crtimport. The probe plugin and the 2.14 release and probe proxies match (KERNEL32, plus VERSION for the probe plugin).
The plugin grows from 366080 to 560128 bytes.
msvcp140.dll,vcruntime140.dllandvcruntime140_1.dll14.29.30157.0. Those were taken from Microsoft'sVC++ 2015-2019 redistributable without running it. The host then calls
InitializeASI:MSVCP140.dll+0x13080, read of address 0. In thatmsvcp140.dll,_Mtx_lockjumps to the lock routine, which dereferences the mutex's implementation pointer; the old runtimeexpects
_Mtx_init_in_situto have set it. Nowronggpu-rr.logis written, as in the report.msvcp140.dllis loaded at all.InitializeASIreturns normally and writes its log.How it was tested
python clean\rr_f\proxy\tools\build.py --out <absolute path>\out\rr-proxywith its tests. They are CPU-only: theD3D12 parts use WARP, with no GPU and no game. Everything passes with 0 failures:
test_replay_profile 1782259.
Not tested
dxgi.dllimports_Mtx_init_in_situis unverified here; the fix doesn't depend on it.test_live_harnesswas not built or run (it needs the GPU).Fixes #9.