feat(tools): add export_gap, which reports the exports a library lacks #8588

Merged
juanpimg merged 6 commits from upstream-pr/8588 into main 2026-11-07 19:14:29 +00:00
juanpimg commented 2026-10-20 17:35:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by juanpimg on 2026-10-20T17:35:14Z.


What

Adds tools/export_gap.py, which reports the system library exports that AnyPS5 does not provide.

AnyPS5 resolves a title's imports by NID, so a title that imports a system function that no AnyPS5 library provides fails to load with an unresolved import. The pull requests that declare those exports — #8021, #8028, #8330, #8331, #8333, #7795, #8240, #8328, #6584, #8255 — all build the same list by hand:

The list is the intersection of the export table of the console's library (function symbols only), the pinned aerolib names and the functions not yet defined anywhere in the repo. All the names recompute to their NIDs with tools/nid_names.py.

The tool computes that list and writes it in the format tools/stubgen.py --nids takes, so the whole job becomes two commands:

python3 tools/export_gap.py --module libScePad --export-table <dir> --db <aerolib.csv> --out missing.txt
python3 tools/stubgen.py --module libScePad --nids missing.txt --db <aerolib.csv>

It recognises what a module already provides in all five ways this project does it: an APS5_VABI declaration, a name ending in _nid_postfix (whose NID is the one of the base name), an APS5_EXPORT binding, a symbol produced by a macro, and a definition emitted by APS5_ASM_FUNCTION or APS5_SIGNAL_ASM_FUNCTION.

Two things it gets right that a hand-built list does not, and that cost real pull requests while this tool was being written:

  • A library can declare its exports through a macro. libSceVoiceChat declares sixteen of them through VOICECHAT_OFFLINE_REQUEST(NAME). A text scan of APS5_VABI does not see them, so the list counts them as missing and a pull request that declares them again exports the same NID twice. The tool reports all sixteen as already provided.
  • A declaration is a global symbol. Declaring a name that the library itself calls makes the library's own call bind to the new declaration. core/libs/prx/libScePosixForWebKit/Resolver.cpp:186 calls the host's ::gethostbyname_r, so declaring gethostbyname_r in that library broke its resolver and guest_resolver failed with "gethostbyname_r not implemented". The tool reports that export as needing a renamed helper bound with APS5_EXPORT, the way libSceAmpr re-exports the libc functions, with the file and the line of the call.

It also reports the NIDs the database does not carry, which the maintainer's rule leaves out of the list.

Tested

CachyOS Linux, kernel 7.2.9-2-cachyos, Python 3.14.8, Release build.

  • New ctest entry export_gap: 39 test cases, all passing, no network access. The cases cover a module whose exports are all missing, a module that provides an export under each of the three postfixes, a module that provides an export through a macro, a module that emits a definition with APS5_ASM_FUNCTION (with and without an APS5_EXPORT alias), a module that binds a NID explicitly with APS5_EXPORT, a NID the database does not carry, a missing export the module calls itself, the same result from the --nids input as from the --export-table input, and the error paths.
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed.
  • cmake --build build --parallel: no error.
  • ctest --test-dir build -R export_gap --output-on-failure: 1/1 passed.
  • The two real cases the tool exists for:
    • libSceVoiceChat reports 0 missing, 30 already provided, and names the sixteen macro-produced symbols as provided through the macro.
    • libScePosixForWebKit reports 24 missing, 12 already provided and names gethostbyname_r as called at core/libs/prx/libScePosixForWebKit/Resolver.cpp:186.

No title was run: the contributor has no PS5 and no game dumps.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939812473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8588). Originally posted by [juanpimg](https://github.com/juanpimg) on 2026-10-20T17:35:14Z. --- ### What Adds `tools/export_gap.py`, which reports the system library exports that AnyPS5 does not provide. AnyPS5 resolves a title's imports by NID, so a title that imports a system function that no AnyPS5 library provides fails to load with an unresolved import. The pull requests that declare those exports — #8021, #8028, #8330, #8331, #8333, #7795, #8240, #8328, #6584, #8255 — all build the same list by hand: > The list is the intersection of the export table of the console's library (function symbols only), the pinned aerolib names and the functions not yet defined anywhere in the repo. All the names recompute to their NIDs with `tools/nid_names.py`. The tool computes that list and writes it in the format `tools/stubgen.py --nids` takes, so the whole job becomes two commands: ```sh python3 tools/export_gap.py --module libScePad --export-table <dir> --db <aerolib.csv> --out missing.txt python3 tools/stubgen.py --module libScePad --nids missing.txt --db <aerolib.csv> ``` It recognises what a module already provides in all five ways this project does it: an `APS5_VABI` declaration, a name ending in `_nid_postfix` (whose NID is the one of the base name), an `APS5_EXPORT` binding, a symbol produced by a macro, and a definition emitted by `APS5_ASM_FUNCTION` or `APS5_SIGNAL_ASM_FUNCTION`. Two things it gets right that a hand-built list does not, and that cost real pull requests while this tool was being written: - **A library can declare its exports through a macro.** `libSceVoiceChat` declares sixteen of them through `VOICECHAT_OFFLINE_REQUEST(NAME)`. A text scan of `APS5_VABI` does not see them, so the list counts them as missing and a pull request that declares them again exports the same NID twice. The tool reports all sixteen as already provided. - **A declaration is a global symbol.** Declaring a name that the library itself calls makes the library's own call bind to the new declaration. `core/libs/prx/libScePosixForWebKit/Resolver.cpp:186` calls the host's `::gethostbyname_r`, so declaring `gethostbyname_r` in that library broke its resolver and `guest_resolver` failed with "gethostbyname_r not implemented". The tool reports that export as needing a renamed helper bound with `APS5_EXPORT`, the way `libSceAmpr` re-exports the libc functions, with the file and the line of the call. It also reports the NIDs the database does not carry, which the maintainer's rule leaves out of the list. ### Tested CachyOS Linux, kernel 7.2.9-2-cachyos, Python 3.14.8, Release build. - New ctest entry `export_gap`: 39 test cases, all passing, no network access. The cases cover a module whose exports are all missing, a module that provides an export under each of the three postfixes, a module that provides an export through a macro, a module that emits a definition with `APS5_ASM_FUNCTION` (with and without an `APS5_EXPORT` alias), a module that binds a NID explicitly with `APS5_EXPORT`, a NID the database does not carry, a missing export the module calls itself, the same result from the `--nids` input as from the `--export-table` input, and the error paths. - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. - `cmake --build build --parallel`: no error. - `ctest --test-dir build -R export_gap --output-on-failure`: 1/1 passed. - The two real cases the tool exists for: - `libSceVoiceChat` reports `0 missing, 30 already provided`, and names the sixteen macro-produced symbols as provided through the macro. - `libScePosixForWebKit` reports `24 missing, 12 already provided` and names `gethostbyname_r` as called at `core/libs/prx/libScePosixForWebKit/Resolver.cpp:186`. No title was run: the contributor has no PS5 and no game dumps. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-21 22:21:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:21:21Z.

Review: COMMENTED


export_gap does not run on Python 3.9 (the repo's floor).

Machine: Apple M2 Max, macOS 27.2. Pythons: /usr/bin/python3 = CPython 3.9.6 (Xcode), and 3.14.7.
PR head: 2fadfee8993924362927945491a9ace11c1af434, run as python3 tools/tests/test_export_gap.py.

  • CPython 3.14.7: OK (27 tests).
  • CPython 3.9.6: FAILED (errors=22), every one:
    TypeError: write_text() got an unexpected keyword argument 'newline'
    at tools/export_gap.py:321 and :323:
    destination.write_text("".join(nid + "\n" for nid in missing_nids), encoding="utf-8", newline="\n")
    ...
    destination.write_text("", encoding="utf-8", newline="\n")
    

Path.write_text's newline keyword was added in Python 3.10, so on 3.9 the tool raises before
writing anything. CI did not catch it because the runners use Python 3.12/3.13, not 3.9.

To keep the explicit-LF behavior on 3.9, write through open instead, e.g.:

with open(destination, "w", encoding="utf-8", newline="\n") as handle:
    handle.write("".join(nid + "\n" for nid in missing_nids))

Written with AI assistance (Claude Code). I ran these Python tests on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5606949138 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8588#pullrequestreview-5606949138). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-21T22:21:21Z. **Review:** COMMENTED --- `export_gap` does not run on Python 3.9 (the repo's floor). Machine: Apple M2 Max, macOS 27.2. Pythons: `/usr/bin/python3` = CPython 3.9.6 (Xcode), and 3.14.7. PR head: 2fadfee8993924362927945491a9ace11c1af434, run as `python3 tools/tests/test_export_gap.py`. - CPython 3.14.7: `OK` (27 tests). - CPython 3.9.6: `FAILED (errors=22)`, every one: `TypeError: write_text() got an unexpected keyword argument 'newline'` at `tools/export_gap.py:321` and `:323`: ```python destination.write_text("".join(nid + "\n" for nid in missing_nids), encoding="utf-8", newline="\n") ... destination.write_text("", encoding="utf-8", newline="\n") ``` `Path.write_text`'s `newline` keyword was added in Python 3.10, so on 3.9 the tool raises before writing anything. CI did not catch it because the runners use Python 3.12/3.13, not 3.9. To keep the explicit-LF behavior on 3.9, write through `open` instead, e.g.: ```python with open(destination, "w", encoding="utf-8", newline="\n") as handle: handle.write("".join(nid + "\n" for nid in missing_nids)) ``` Written with AI assistance (Claude Code). I ran these Python tests on my machine.
THEMANnt commented 2026-10-24 23:04:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-24T23:04:57Z.

Review: CHANGES_REQUESTED


Reviewed 2fadfee89939 against author merge base 6f9de5738615. Requesting changes because the new gap report incorrectly treats unpatched helper names as providers of a hashed NID.

Do not count _nid_no_patch and _nid_no_patch_cut as hashed exports — tools/export_gap.py:124–128, 167–175. base_of strips all three suffixes, then collect_provided hashes the base name. However, the exact repository resolver in core/libs/nid/src/NidResolver.cpp:15–20,45–51 keeps _nid_no_patch names unchanged and strips _nid_no_patch_cut to a literal name without hashing. Only _nid_postfix has the hashed-base behavior. With a console table requesting T2IWNGg3cnI (sceExampleNoPatchBase) and a source defining only sceExampleNoPatchBase_nid_no_patch, the submitted Python tool reports 0 missing, 1 already provided; the cut variant produces the same false result. Thus the emitted stub list omits an export that remains unresolved. This is reproduced in disposable source/table/database fixtures; resolver semantics are verified directly from the pinned source. Please model the actual resolver and correct the test that currently expects both unpatched variants to satisfy this NID. Preserve explicit APS5_EXPORT bindings as valid providers.

Windows x64 / CPython 3.11: all 27 export-gap tests, 37 NID-name tests and 16 stub-generator tests pass. Supporting suites also pass on the author merge base. The new suite cannot run there because the new module does not exist; that import error is not regression-sensitivity evidence. Conventions, whitespace and registration pass. Hosted relinker matrix/ASan and conventions jobs succeed; full product jobs are skipped. An attempted standalone native resolver control did not link because its dependency set was incomplete; no successful native execution is claimed and those link errors are not author defects.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640493395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8588#pullrequestreview-5640493395). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-24T23:04:57Z. **Review:** CHANGES_REQUESTED --- Reviewed [2fadfee89939](https://github.com/boykopovar/AnyPS5/commit/2fadfee8993924362927945491a9ace11c1af434) against author merge base [6f9de5738615](https://github.com/boykopovar/AnyPS5/commit/6f9de5738615a61a3f39e3289325038a1b72a346). Requesting changes because the new gap report incorrectly treats unpatched helper names as providers of a hashed NID. **Do not count `_nid_no_patch` and `_nid_no_patch_cut` as hashed exports** — `tools/export_gap.py:124–128, 167–175`. `base_of` strips all three suffixes, then `collect_provided` hashes the base name. However, the exact repository resolver in `core/libs/nid/src/NidResolver.cpp:15–20,45–51` keeps `_nid_no_patch` names unchanged and strips `_nid_no_patch_cut` to a literal name without hashing. Only `_nid_postfix` has the hashed-base behavior. With a console table requesting `T2IWNGg3cnI` (`sceExampleNoPatchBase`) and a source defining only `sceExampleNoPatchBase_nid_no_patch`, the submitted Python tool reports `0 missing, 1 already provided`; the cut variant produces the same false result. Thus the emitted stub list omits an export that remains unresolved. This is reproduced in disposable source/table/database fixtures; resolver semantics are verified directly from the pinned source. Please model the actual resolver and correct the test that currently expects both unpatched variants to satisfy this NID. Preserve explicit `APS5_EXPORT` bindings as valid providers. Windows x64 / CPython 3.11: all 27 export-gap tests, 37 NID-name tests and 16 stub-generator tests pass. Supporting suites also pass on the author merge base. The new suite cannot run there because the new module does not exist; that import error is not regression-sensitivity evidence. Conventions, whitespace and registration pass. Hosted relinker matrix/ASan and conventions jobs succeed; full product jobs are skipped. An attempted standalone native resolver control did not link because its dependency set was incomplete; no successful native execution is claimed and those link errors are not author defects.
THEMANnt commented 2026-10-28 10:32:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T10:32:21Z.

Review: DISMISSED


Re-reviewed c4563f10df5a5900a0c2f210a112585e42f78de4. The earlier suffix-resolution finding is fixed: independent fixtures now match the pinned resolver for both literal no-patch variants, hashed _nid_postfix, and numeric disambiguators.

[P2] Protect export-table inputs from --out — tools/export_gap.py:322–324,349–354. The existing alias guard checks --nids and --db, but omits the selected <export-table>/<module>.c files. Running --module libSceExample --export-table tables --db names.txt --out tables/libSceExample.c reads a valid table, then opens that same input with "w", replaces its contents with T2IWNGg3cnI\n, and exits 0. This silently destroys the export inventory. The same fixture with a separate output preserves the table; the existing database-alias guard correctly refuses its analogous case.

Please include every selected export-table file in the input/output alias validation before writing, including resolved-path and hardlink aliases, and add preservation regressions.

Windows/Python 3.11: export-gap 36/36, NID-name 45/45 and stub-generator 23/23 passed. The independent reproduction runs a byte-identical copy of the submitted CLI in a disposable fixture. The hosted Windows relinker job merged this head and passed export_gap; that suite does not cover this alias. Initial supporting-suite sparse-checkout/sandbox failures were corrected; no product defect is inferred from them. No game execution was performed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681219418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8588#pullrequestreview-5681219418). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T10:32:21Z. **Review:** DISMISSED --- Re-reviewed `c4563f10df5a5900a0c2f210a112585e42f78de4`. The earlier suffix-resolution finding is fixed: independent fixtures now match the pinned resolver for both literal no-patch variants, hashed `_nid_postfix`, and numeric disambiguators. **[P2] Protect export-table inputs from `--out` — `tools/export_gap.py:322–324,349–354`.** The existing alias guard checks `--nids` and `--db`, but omits the selected `<export-table>/<module>.c` files. Running `--module libSceExample --export-table tables --db names.txt --out tables/libSceExample.c` reads a valid table, then opens that same input with `"w"`, replaces its contents with `T2IWNGg3cnI\n`, and exits 0. This silently destroys the export inventory. The same fixture with a separate output preserves the table; the existing database-alias guard correctly refuses its analogous case. Please include every selected export-table file in the input/output alias validation before writing, including resolved-path and hardlink aliases, and add preservation regressions. Windows/Python 3.11: export-gap 36/36, NID-name 45/45 and stub-generator 23/23 passed. The independent reproduction runs a byte-identical copy of the submitted CLI in a disposable fixture. The hosted Windows relinker job merged this head and passed `export_gap`; that suite does not cover this alias. Initial supporting-suite sparse-checkout/sandbox failures were corrected; no product defect is inferred from them. No game execution was performed.
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!8588
No description provided.