fix(nid): share string suffixes when rebuilding .dynstr #242

Merged
adriadam10 merged 1 commit from upstream-pr/242 into main 2026-10-04 02:40:54 +00:00
adriadam10 commented 2026-10-01 18:10:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T18:10:00Z.


What

nid_patcher rebuilds .dynstr in place and fails when the new table is larger than the original section ("rebuilt .dynstr (N bytes) exceeds original section size"). The linker tail-merges dynamic strings (a name that is the suffix of another, like cos inside acos or sin@... inside asin@..., is stored once), but the patcher wrote every string separately and lost that sharing. Libraries with many exports get away with it because NIDs are shorter than most export names; a library with few exports and many imports does not: libSceAudioIn linked against SDL (3 exports, ~220 imports) overflows by 5 bytes.

The patcher now collects the final strings, sorts them by their reversed text, and lets a string that ends the previous one point into it (standard suffix merging). Offsets for symbols, DT_NEEDED/DT_SONAME and verneed entries are mapped as before.

Tested

Linux (CachyOS, GCC): rebuilt libs with the old and the new patcher and compared, for all 106 patched .prx, the dynamic symbol names (nm -D) and DT_NEEDED/DT_SONAME (readelf -d): identical. Full test suite passes. The SDL-backed libSceAudioIn (follow-up PR) patches only with this change. Windows only through CI (PE patching is not touched).

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4707654539 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/242). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T18:10:00Z. --- ### What `nid_patcher` rebuilds `.dynstr` in place and fails when the new table is larger than the original section ("rebuilt .dynstr (N bytes) exceeds original section size"). The linker tail-merges dynamic strings (a name that is the suffix of another, like `cos` inside `acos` or `sin@...` inside `asin@...`, is stored once), but the patcher wrote every string separately and lost that sharing. Libraries with many exports get away with it because NIDs are shorter than most export names; a library with few exports and many imports does not: `libSceAudioIn` linked against SDL (3 exports, ~220 imports) overflows by 5 bytes. The patcher now collects the final strings, sorts them by their reversed text, and lets a string that ends the previous one point into it (standard suffix merging). Offsets for symbols, `DT_NEEDED`/`DT_SONAME` and verneed entries are mapped as before. ### Tested Linux (CachyOS, GCC): rebuilt `libs` with the old and the new patcher and compared, for all 106 patched `.prx`, the dynamic symbol names (`nm -D`) and `DT_NEEDED`/`DT_SONAME` (`readelf -d`): identical. Full test suite passes. The SDL-backed `libSceAudioIn` (follow-up PR) patches only with this change. Windows only through CI (PE patching is not touched). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!242
No description provided.