fix(libs): give each .native wrapper a dependency edge to its plain twin #1009

Closed
Dextroid17 wants to merge 1 commit from upstream-pr/1009 into main
Dextroid17 commented 2026-10-06 23:13:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-06T23:13:54Z.


What

Gives each .native wrapper a DT_NEEDED edge to its plain twin (the first option in #906). Closes #906.

A guest module's DT_NEEDED names the .native wrapper, but symbols that only the plain twin exports were unreachable — the wrapper had no edge to the twin, so the defining object never entered the new module's lookup scope and RTLD_NOW binding failed:

31418  [dl] dlopen(/app0/Media/Plugins/PSN.prx, 0x2) -> (nil) error: undefined symbol: wTpfglkmv34

All nine wrappers lacked the edge (libSceAjm.native, libSceAudiodec.native, libSceAvPlayer.native, libSceFont.native, libSceMsgDialog.native, libSceNgs2.native, libSceSaveDataDialog.native, libSceSaveData.native, libSceShare.native), and all nine plain twins exist.

The change links each .native library against its plain twin on ELF targets. Windows is left alone: PE resolution binds against every module already loaded and the relinker points guest imports at the implementing library, so the edge is not needed there.

This is option 1 of the three listed in the issue; option 2 (the relinker emits the implementing library in the converted guest module's DT_NEEDED) would also work and touches the relinker instead of the library graph. Happy to switch if you prefer that direction.

Tested

  • Linux, CachyOS (Arch), GCC 16.2.1, Release.
  • readelf -d on all nine wrappers: no NEEDED libSceX.prx before the change, present after.
  • dlopen probe with RTLD_LOCAL (the way a guest module binds), checking /proc/self/maps:
    • before: dlopen(libSceMsgDialog.native.prx) leaves libSceMsgDialog.prx unmapped
    • after: it is mapped (same result for libSceAudiodec.native and libSceAjm.native)
  • cmake --build build --target libs → 106 .prx built.
  • Full suite: ctest --test-dir build -j 8 --timeout 120 → 369/369 pass.
  • Not tested on a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source — not applicable
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4765679789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1009). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-06T23:13:54Z. --- ### What Gives each `.native` wrapper a `DT_NEEDED` edge to its plain twin (the first option in #906). Closes #906. A guest module's `DT_NEEDED` names the `.native` wrapper, but symbols that only the plain twin exports were unreachable — the wrapper had no edge to the twin, so the defining object never entered the new module's lookup scope and `RTLD_NOW` binding failed: ``` 31418 [dl] dlopen(/app0/Media/Plugins/PSN.prx, 0x2) -> (nil) error: undefined symbol: wTpfglkmv34 ``` All nine wrappers lacked the edge (`libSceAjm.native`, `libSceAudiodec.native`, `libSceAvPlayer.native`, `libSceFont.native`, `libSceMsgDialog.native`, `libSceNgs2.native`, `libSceSaveDataDialog.native`, `libSceSaveData.native`, `libSceShare.native`), and all nine plain twins exist. The change links each `.native` library against its plain twin on ELF targets. Windows is left alone: PE resolution binds against every module already loaded and the relinker points guest imports at the implementing library, so the edge is not needed there. This is option 1 of the three listed in the issue; option 2 (the relinker emits the implementing library in the converted guest module's `DT_NEEDED`) would also work and touches the relinker instead of the library graph. Happy to switch if you prefer that direction. ### Tested - Linux, CachyOS (Arch), GCC 16.2.1, Release. - `readelf -d` on all nine wrappers: no `NEEDED libSceX.prx` before the change, present after. - `dlopen` probe with `RTLD_LOCAL` (the way a guest module binds), checking `/proc/self/maps`: - before: `dlopen(libSceMsgDialog.native.prx)` leaves `libSceMsgDialog.prx` unmapped - after: it is mapped (same result for `libSceAudiodec.native` and `libSceAjm.native`) - `cmake --build build --target libs` → 106 `.prx` built. - Full suite: `ctest --test-dir build -j 8 --timeout 120` → 369/369 pass. - Not tested on a title. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source — not applicable - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-06 23:14:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-06T23:14:45Z.


Closing this: @jeffrey12cali measured on PPSA28997 that this exact approach regresses the title (see #906).

Pulling the plain twin in through a DT_NEEDED edge puts it in the executable's global scope on Linux, and the pairs share NIDs (libSceAvPlayer 30/30 overlapping, libSceSaveData 14/41, libSceMsgDialog 6/7), so other modules rebind to the wrong implementation and the title fails earlier than before. The static checks in the description (readelf, dlopen) all pass and are exactly why they are not sufficient here — the edge is added, and that is the problem.

The twin has to stay out of the global scope. I will pick this up again on that basis — most likely the relinker emitting the implementing library in the converted guest module's DT_NEEDED (the issue's option 2, which is also the stopgap described in #906) rather than a library-graph edge, or the wrapper re-exporting what the plain library provides.

Branch fix/native-wrapper-dependency-edge is left in place for reference. Sorry for the noise, and thank you for the measurement.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027172697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1009#issuecomment-6027172697). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-06T23:14:45Z. --- Closing this: @jeffrey12cali measured on PPSA28997 that this exact approach regresses the title (see #906). Pulling the plain twin in through a `DT_NEEDED` edge puts it in the executable's **global** scope on Linux, and the pairs share NIDs (`libSceAvPlayer` 30/30 overlapping, `libSceSaveData` 14/41, `libSceMsgDialog` 6/7), so other modules rebind to the wrong implementation and the title fails *earlier* than before. The static checks in the description (`readelf`, `dlopen`) all pass and are exactly why they are not sufficient here — the edge is added, and that is the problem. The twin has to stay out of the global scope. I will pick this up again on that basis — most likely the relinker emitting the implementing library in the converted guest module's `DT_NEEDED` (the issue's option 2, which is also the stopgap described in #906) rather than a library-graph edge, or the wrapper re-exporting what the plain library provides. Branch `fix/native-wrapper-dependency-edge` is left in place for reference. Sorry for the noise, and thank you for the measurement.

Pull request closed

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
boykopovar/AnyPS5!1009
No description provided.