Skip to content

docs: add NID and symbol patching reference - #1937

Closed
klosixgaming-arch wants to merge 1 commit into
boykopovar:mainfrom
klosixgaming-arch:bionic/nid-patching-doc
Closed

klosixgaming-arch wants to merge 1 commit into
boykopovar:mainfrom
klosixgaming-arch:bionic/nid-patching-doc

Conversation

@klosixgaming-arch

Copy link
Copy Markdown
Contributor

Adds docs/dev/NID_PATCHING.md, a reference for the NID and symbol patching rules that are currently scattered across CONTRIBUTING.md (one bullet), core/libs/nid/, ExportMacros.hpp and issue #1827.

It covers:

  • The NID hash algorithm from core/libs/nid/src/NidCompute.cpp (SHA-1 with the fixed 16-byte suffix, first 8 digest bytes reversed, 6-bit encoding over A-Z a-z 0-9 + -, 11 characters). Cross-checked: the C++ and tools/nid_names.py implementations agree with each other and with the aerolib SCE symbol database (159,030/159,042 entries; the 12 exceptions are four sceBgft* names repeated across modules).
  • The patcher CLI and the build wiring: libc patched without a reference, every other library with --preserve-exports pointing at the unpatched libc.prx; what the PE and ELF patchers rewrite (export table, .dynsym/.dynstr/.gnu.hash, DT_NEEDED/.gnu.version_r, .eh_frame rename).
  • The export-side rule in priority order from ResolveNids (exclusion set, _nid_no_patch_cut, _nid_no_patch/SDL_, the X + X_nid_postfix pair, NID rename with _nid_disambig<digits> stripping), with worked examples.
  • The import-side rule (undefined, non-local, unversioned, _nid_postfix or sce prefix) and why cross-library calls must be extern "C": the suffix test is against the literal dynamic symbol name, so mangled C++ names are never rewritten.
  • Each suffix (_nid_postfix, _nid_disambig<digits>, _nid_no_patch, _nid_no_patch_cut, SDL_) with real usage examples from the tree, including the APS5_EXPORT unknown-NID mechanism.
  • The ctest loads the unpatched libraries, so an import that nid_patcher renames only fails when a title loads the patched prx #1827 failure class (tests bind unpatched libraries, titles load patched ones; Windows GetLastError: 127) and how to check a cross-library call against the rules.

Every rule and example in the doc was read from the cited source on main before writing. New file only; no code changes, no tests needed.

AI-assisted: yes

Written with AI assistance.

@github-actions github-actions Bot added the docs label Oct 9, 2026
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

I reviewed the full document against the current source and ran the Conventions check and git diff --check; both pass. The head is based on 4b2413f while current main is f145139 (282 commits ahead; merge base 4b2413f). CONTRIBUTING requires PR branches to stay current, so please rebase onto current main and rerun Conventions before review. The change is documentation-only, but I will wait for the final rebased head before approving.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: a reference that restates NidResolver.cpp and the patchers will drift from them, and notes like this aren't wanted in the repo. #1828's test is what catches the #1613 case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants