loader: refresh imports after dynamic module loads #511
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!511
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/511/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@OldKrab on GitHub · 2026-09-08 13:57 UTC · original
OldKrab:shushakov/castlevania-module-reload→main· +1 −1 · 1 files · 1 commits · merged 2026-09-23 17:04 UTCCastlevania Dominus Collection crashes after unloading and reloading
dra03.prxbecause the main executable retains an invalid address for an imported object.UnloadProgram()already callsRelocateAll(). Once the module is removed, this replaces its object's address in the main executable's GOT with an invalid-object placeholder. Loading the module again currently relocates only the newly loaded module, leaving that GOT entry unchanged.I propose calling
RelocateAll()fromRelocateProgram()as well, so existing imports receive the loaded module's addresses before it starts.Validation: Linux build passed. Order of Ecclesia passed the original crash point and ran for roughly five minutes without another crash. Windows and audio remain untested.
Fixes #307.
@francoisatt on GitHub · 2026-09-08 17:30 UTC · original
Built and tested on Windows (clang-cl 19.1.5, Ninja, clean build) at
0e2d667.35/36 tests pass — the only failure is
kernel_file_system, which fails onclean main too (#505). No regression from this change.
I can't run Castlevania, so I can't confirm the fix itself — only that it
builds and doesn't break the suite on the platform you couldn't test.
Two things a reviewer will probably ask about, worth addressing up front:
GTA V has ~171k relocations in the main executable alone, so a title that
loads modules frequently might notice.
RelocateAll on the grounds that it "would rewrite every live import slot" —
it added a classifier so only linker-owned pending values were touched. Your
approach is much simpler; the question is whether any import slot can
legitimately be modified by guest code and get clobbered here.
Also worth noting: SharpEmu does a dedicated pass for this and logs it as
Imported data rebind: rebound=11, unresolved=0, so the general idea issound — it's the scope that differs between the two approaches.