Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Game overrides registered from the static library are silently never applied (static-initializer discard)

Aperta
#264 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cmake, cpp

Direzione di ricerca

Start from the Game Override Hooks section of the README, game_overrides.h (PS2_REGISTER_GAME_OVERRIDE / AutoRegister), src/lib/game_overrides.cpp, and ps2xRuntime/CMakeLists.txt (target_sources(ps2_runtime …) vs the executable sources). Confirm applyMatching() only logs when appliedCount > 0. Done is either a README plus header comment on placement, a glob of override .cpp files into the executable, whole-archive linking of ps2_runtime, and/or an unconditional registry-size log so a missing descriptor is visible.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

A game override registered with PS2_REGISTER_GAME_OVERRIDE is silently inactive when its translation unit is compiled into the ps2_runtime static library instead of into the executable.

The descriptor registers through a static initializer (ps2_game_overrides::AutoRegister, constructed from a file-scope static const Descriptor). Nothing else in the program references that translation unit, so the linker never pulls the object out of the archive, the initializer never runs, descriptorRegistry() stays empty, and applyMatching() returns immediately.

There is no diagnostic of any kind. No warning at build time, no message at run time, no [game_overrides] line. The override simply does not exist, and the game runs with the unpatched function as if nothing had been asked.

How we hit it

Writing an override for #262 (vcallmsr reading ctx->vi[27]). The obvious placement -- next to src/lib/game_overrides.cpp in the target_sources(ps2_runtime PRIVATE ...) list of ps2xRuntime/CMakeLists.txt -- builds and links cleanly and does nothing.

game_overrides.cpp itself survives because applyMatching is called from ps2_runtime.cpp, so that object is always pulled in. A new file has no such anchor.

Measured

Searching the build artefacts for a string only present in the override file (grep -a, validated first against strings known to be in the binary):

artefact function body symbol Vu0StartMicroProgramReg_0x2c4850 descriptor string SLUS_200.02 log string
the .obj present absent absent
ps2EntryRunner.exe, override in ps2_runtime -- absent absent
ps2EntryRunner.exe, override in the executable -- present present

The replacement function was compiled. It was the descriptor that never reached the binary.

After moving the file into the executable's sources, it works on the first run:

[game_overrides] applying 'Ridge Racer V (NTSC-U) - vcallmsr reads CMSAR0'
[game_overrides] applied 1 matching override(s).

Why this is worth fixing rather than just knowing

The README's Game Override Hooks section documents the header, the macro and the bindAddressHandler helper, and describes overrides as "runtime-side, build-scoped patch modules". It does not say where the file has to live, and the natural reading -- "runtime-side" -- points at exactly the placement that silently fails.

Static-initializer registration from a static library is a well-known trap, but it is invisible here: the mechanism gives the author no feedback distinguishing "my descriptor did not match" from "my descriptor was never registered".

Suggested fixes, cheapest first

1. Document it. One sentence in the README section and a comment in game_overrides.h above the macro would be enough to save the next person the afternoon.

2. Give it a drop-in directory. A globbed folder appended to the executable's sources makes the correct placement the only placement:

file(GLOB GAME_OVERRIDE_SRC CONFIGURE_DEPENDS
    "${CMAKE_CURRENT_SOURCE_DIR}/src/lib/game_overrides/*.cpp"
)
list(APPEND RUNNER_SRC_FILES ${GAME_OVERRIDE_SRC})

3. Or make the library placement work. Linking the runtime with whole-archive semantics ($<LINK_LIBRARY:WHOLE_ARCHIVE,ps2_runtime>, CMake 3.24+) would keep every override object regardless of where it sits -- at the cost of a larger binary.

4. Independently of the above, make the silence impossible. applyMatching() currently logs only when appliedCount > 0. Logging the registry size unconditionally -- even just [game_overrides] 0 descriptors registered -- would turn a silent no-op into a one-line clue.


Found while statically recompiling Ridge Racer V (NTSC-U, SLUS_200.02) with PS2Recomp.
Tested on commit 75d729ce; main was c5a9d02 at the time of writing.
Host: Windows 11 x64, clang-cl 22.1.3 + Ninja, MSVC toolset 14.51.36231, CMake 4.2.3, -flto=thin.
Not specific to this game, and not specific to Windows -- any static-library placement on any toolchain has the same behaviour.

Lingua principale
C++
Stelle
3.3k
Fork
149
Merge medio
5g 10h
PR unite (30g)
4

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ran-j/PS2Recomp

Tutte le issue di ran-j/PS2Recomp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.