feat(libSceFreeTypeOptOl): implement PFR queries #9646

Merged
UnhealthyKraken merged 7 commits from upstream-pr/9646 into main 2026-10-26 11:39:18 +00:00
UnhealthyKraken commented 2026-10-22 05:59:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T05:59:43Z.


What

Implement FT_Get_PFR_Metrics, FT_Get_PFR_Advance and FT_Get_PFR_Kerning in the physical libSceFreeTypeOptOl provider through the existing shared FreeType face adapter. Guest positions, scales and vectors retain 64-bit storage on Windows. The optional module forwards to helpers in the existing runtime and creates no second FreeType instance.

A null face returns Invalid_Argument (6), with outputs untouched and no host PFR calls. This follows official FreeType 2.4.11 ftpfr.c, blob 3a0f92d07ae29fa0385e36ee2660d3ededaa40dc, and BunnyFl's firmware 13.42 Unicorn report. The report also attributes a 2.4.11 version to Ol disassembly and finds the same three NIDs in OptOl and Ol under logical library libSceFreeType. This patch implements OptOl only; Ol support remains missing. The reported version was not executed, and no real-face Sony behavior was measured.

Nonnull behavior still follows bundled FreeType 2.13.3 through the existing LP64 adapter: PFR advances/kerning use metric space, invalid PFR advance indices write zero, non-PFR advance failures preserve output, and non-PFR metrics write fallback values before returning the format error. Sony prototypes, private layouts, configuration, module/library versions and real-face equivalence remain unverified in debt. Names/NIDs are attributable to the PS5 3.20 OptOl inventory.

The main refresh adopts one shared public declaration per export, the OptOl umbrella and decltype-based test pointers. The standalone null-face target compiles the actual wrappers/helpers with isolated host spies; it checks literal error 6, all 16 metrics output masks, null/non-null outputs, sentinels/canaries and zero host calls. The full fixture keeps its synthetic face, aliasing, signed-width and lifetime coverage. The patched target now explicitly builds its kernel/libc dependencies.

Tested

Exact head 1248d841c7, after a history-preserving main 504ea3b53b merge. Actual project Release builds and all eight focused CTests pass on hosted Ubuntu 24.04/GCC 13.3 and Windows/WinLibs GCC 15.2, followed by two repetitions per case. Linux, Windows. Both jobs first reproduce the expected failures on the regression-only baseline, then rebuild the candidate and verify the unchanged legacy fixture executable by SHA256. Linux additionally withholds only the patched kernel: the actual loader reports libkernel.prx missing and all three patched cases fail; restoring it gives 8/8 again with the same fixture. Conventions, whitespace and public-header audits pass. No selected candidate case was skipped.

Before the guard change, all three real raw query tests return 35 instead of 6 and the standalone unit records one host call; the native reference case passes. The regression-only baseline therefore has four expected failures and one passing reference. The same committed fixtures run against the corrected implementation. This does not establish real-face firmware behavior from the reported null-only measurements.

No local builds/runtime tests, games, proprietary modules/captures or physical-console execution. The full repository test suite was not run; validation used one cloud build job at a time and compiler/test parallelism 1.

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:4962849598 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9646). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T05:59:43Z. --- ### What Implement FT_Get_PFR_Metrics, FT_Get_PFR_Advance and FT_Get_PFR_Kerning in the physical libSceFreeTypeOptOl provider through the existing shared FreeType face adapter. Guest positions, scales and vectors retain 64-bit storage on Windows. The optional module forwards to helpers in the existing runtime and creates no second FreeType instance. A null face returns Invalid_Argument (6), with outputs untouched and no host PFR calls. This follows official [FreeType 2.4.11 ftpfr.c](https://github.com/freetype/freetype/blob/VER-2-4-11/src/base/ftpfr.c), blob 3a0f92d07ae29fa0385e36ee2660d3ededaa40dc, and [BunnyFl's firmware 13.42 Unicorn report](https://github.com/boykopovar/AnyPS5/pull/9646#issuecomment-6405909027). The report also attributes a 2.4.11 version to Ol disassembly and finds the same three NIDs in OptOl and Ol under logical library libSceFreeType. This patch implements OptOl only; Ol support remains missing. The reported version was not executed, and no real-face Sony behavior was measured. Nonnull behavior still follows bundled FreeType 2.13.3 through the existing LP64 adapter: PFR advances/kerning use metric space, invalid PFR advance indices write zero, non-PFR advance failures preserve output, and non-PFR metrics write fallback values before returning the format error. Sony prototypes, private layouts, configuration, module/library versions and real-face equivalence remain unverified in debt. Names/NIDs are attributable to the [PS5 3.20 OptOl inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceFreeTypeOptOl.c). The main refresh adopts one shared public declaration per export, the OptOl umbrella and decltype-based test pointers. The standalone null-face target compiles the actual wrappers/helpers with isolated host spies; it checks literal error 6, all 16 metrics output masks, null/non-null outputs, sentinels/canaries and zero host calls. The full fixture keeps its synthetic face, aliasing, signed-width and lifetime coverage. The patched target now explicitly builds its kernel/libc dependencies. ### Tested Exact head 1248d841c7b5dbcac6cd347432b0d9c10b991d77, after a history-preserving main 504ea3b53b23 merge. Actual project Release builds and all eight focused CTests pass on hosted Ubuntu 24.04/GCC 13.3 and Windows/WinLibs GCC 15.2, followed by two repetitions per case. [Linux](https://github.com/UnhealthyKraken/AnyPS5/actions/runs/40264736645/job/121384527090), [Windows](https://github.com/UnhealthyKraken/AnyPS5/actions/runs/40264736645/job/121389909276). Both jobs first reproduce the expected failures on the regression-only baseline, then rebuild the candidate and verify the unchanged legacy fixture executable by SHA256. Linux additionally withholds only the patched kernel: the actual loader reports libkernel.prx missing and all three patched cases fail; restoring it gives 8/8 again with the same fixture. Conventions, whitespace and public-header audits pass. No selected candidate case was skipped. Before the guard change, all three real raw query tests return 35 instead of 6 and the standalone unit records one host call; the native reference case passes. The regression-only baseline therefore has four expected failures and one passing reference. The same committed fixtures run against the corrected implementation. This does not establish real-face firmware behavior from the reported null-only measurements. No local builds/runtime tests, games, proprietary modules/captures or physical-console execution. The full repository test suite was not run; validation used one cloud build job at a time and compiler/test parallelism 1. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
jotitadev commented 2026-10-22 07:09:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T07:09:19Z.

Review: COMMENTED


Linux run, since the description lists only Windows. The implementation passes, but on Linux the three *_patched cases fail. The cause is how the test executable is linked.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head 5a35e3400 merged --no-commit onto main d6eafa54d (clean).

  • As submitted, guest_freetype_pfr_{metrics,advance,kerning}_patched fail 3 of 3 runs, before any PFR check:

    .../build/core/libs/libs/libkernel.prx: undefined symbol: g5PTgiKQ9Eo
    PFR check failed at line 136
    

    guest_freetype_pfr_tests links libc on every platform, so it starts with the unpatched libc.prx loaded (its RUNPATH is libs/unpatched). Then dlopen(libs/libSceFreeType.prx) pulls the patched libkernel.prx through $ORIGIN. The libc.prx dependency is satisfied by the copy already loaded, which exports *_nid_postfix names and not NIDs. So the patched libkernel.prx import g5PTgiKQ9Eo (exported by the patched libc.prx) cannot resolve. LD_DEBUG=files shows libc.prx loaded as "needed by guest_freetype_pfr_tests" and libkernel.prx as "needed by .../libs/libSceFreeType.prx".

  • The CMAC patched test (#9571, Cmac.cmake) avoids this by linking libc only on Windows. The same change here fixes it:

    target_link_libraries(guest_freetype_pfr_tests PRIVATE freetype ${CMAKE_DL_LIBS})
    if(WIN32)
        target_link_libraries(guest_freetype_pfr_tests PRIVATE libc)
    endif()
    

    With it, all 7 guest_freetype_pfr_* tests pass, plus guest_freetype and guest_freetype_charmap, 3 of 3 runs. The raw cases still load the unpatched libc.prx through the prx's own $ORIGIN RUNPATH.

  • Red with that change and main's libSceFreeTypeOptOl/Export.cpp: reference passes, and the six raw/patched cases fail on Missing FT_Get_PFR_{Metrics,Advance,Kerning}, as *_nid_postfix (raw) and as OqaxEkRhr+8 / NVuvsPgTXto / qBohKqdkAqE (patched). This matches your baseline. On this LP64 host, the 64-bit signed results and untouched high-bit output checks pass.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5610450267 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9646#pullrequestreview-5610450267). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T07:09:19Z. **Review:** COMMENTED --- Linux run, since the description lists only Windows. The implementation passes, but on Linux the three `*_patched` cases fail. The cause is how the test executable is linked. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `5a35e3400` merged `--no-commit` onto `main` `d6eafa54d` (clean). - As submitted, `guest_freetype_pfr_{metrics,advance,kerning}_patched` fail 3 of 3 runs, before any PFR check: ```text .../build/core/libs/libs/libkernel.prx: undefined symbol: g5PTgiKQ9Eo PFR check failed at line 136 ``` `guest_freetype_pfr_tests` links `libc` on every platform, so it starts with the **unpatched** `libc.prx` loaded (its RUNPATH is `libs/unpatched`). Then `dlopen(libs/libSceFreeType.prx)` pulls the **patched** `libkernel.prx` through `$ORIGIN`. The `libc.prx` dependency is satisfied by the copy already loaded, which exports `*_nid_postfix` names and not NIDs. So the patched `libkernel.prx` import `g5PTgiKQ9Eo` (exported by the patched `libc.prx`) cannot resolve. `LD_DEBUG=files` shows `libc.prx` loaded as "needed by guest_freetype_pfr_tests" and `libkernel.prx` as "needed by .../libs/libSceFreeType.prx". - The CMAC patched test (#9571, `Cmac.cmake`) avoids this by linking `libc` only on Windows. The same change here fixes it: ```cmake target_link_libraries(guest_freetype_pfr_tests PRIVATE freetype ${CMAKE_DL_LIBS}) if(WIN32) target_link_libraries(guest_freetype_pfr_tests PRIVATE libc) endif() ``` With it, all 7 `guest_freetype_pfr_*` tests pass, plus `guest_freetype` and `guest_freetype_charmap`, 3 of 3 runs. The raw cases still load the unpatched `libc.prx` through the prx's own `$ORIGIN` RUNPATH. - Red with that change and `main`'s `libSceFreeTypeOptOl/Export.cpp`: `reference` passes, and the six raw/patched cases fail on `Missing FT_Get_PFR_{Metrics,Advance,Kerning}`, as `*_nid_postfix` (raw) and as `OqaxEkRhr+8` / `NVuvsPgTXto` / `qBohKqdkAqE` (patched). This matches your baseline. On this LP64 host, the 64-bit signed results and untouched high-bit output checks pass. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
fogydes commented 2026-10-22 08:12:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:12:54Z.


Reviewed; the wrapper behavior matches the pinned freetype tree it links (3rdparty/freetype, 2.13.3 ftpfr.c): the non-PFR fallback (units_per_EM for both resolutions, size->metrics scaling, Unknown_File_Format), the font-format-gated advance zeroing for PFR against the non-PFR unchanged output, and the kerning fallback to FT_Get_Kerning(FT_KERNING_UNSCALED). Exports follow the established _nid_postfix discovery with no table edit, and the test registration mirrors guest_freetype_tests. The debt entry documents the gap honestly.

One nit: GuestFreeTypePfr.cpp uses offsetof without including <cstddef>; it compiles today through transitive includes, but the include should state the dependency.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336033195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9646#issuecomment-6336033195). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-22T08:12:54Z. --- Reviewed; the wrapper behavior matches the pinned freetype tree it links (3rdparty/freetype, 2.13.3 `ftpfr.c`): the non-PFR fallback (units_per_EM for both resolutions, `size->metrics` scaling, `Unknown_File_Format`), the font-format-gated advance zeroing for PFR against the non-PFR unchanged output, and the kerning fallback to `FT_Get_Kerning(FT_KERNING_UNSCALED)`. Exports follow the established `_nid_postfix` discovery with no table edit, and the test registration mirrors `guest_freetype_tests`. The debt entry documents the gap honestly. One nit: `GuestFreeTypePfr.cpp` uses `offsetof` without including `<cstddef>`; it compiles today through transitive includes, but the include should state the dependency.
MarcZX10 commented 2026-10-22 09:18:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:18:53Z.

Review: DISMISSED


The implementation behavior tracks the pinned FreeType 2.13.3 helper semantics, and the synthetic output/canary coverage is detailed. There are two concrete items still unresolved at the current head 5a35e3400: 1. The independent Linux run on this exact head reports all three guest_freetype_pfr_{metrics,advance,kerning}_patched tests fail before their PFR assertions: the test executable preloads unpatched libc.prx, then loads patched libkernel.prx, whose NID import cannot resolve against that already-loaded libc. The reproduced correction is to link libc only under if(WIN32), as in the CMAC patched test. This matters because the current test report claims those patched cases pass, while Linux product CI was skipped. Please apply the platform-specific linkage and rerun the seven PFR cases on Linux and Windows. 2. Add <cstddef> directly to GuestFreeTypePfr.cpp for its offsetof use. The exact-head report and CI show conventions, eligibility, intake, labels and progress report pass; product build/test jobs are skipped. I did not rerun the full FreeType build in this environment.

I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611928703 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9646#pullrequestreview-5611928703). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T09:18:53Z. **Review:** DISMISSED --- The implementation behavior tracks the pinned FreeType 2.13.3 helper semantics, and the synthetic output/canary coverage is detailed. There are two concrete items still unresolved at the current head `5a35e3400`: 1. The independent Linux run on this exact head reports all three `guest_freetype_pfr_{metrics,advance,kerning}_patched` tests fail before their PFR assertions: the test executable preloads unpatched `libc.prx`, then loads patched `libkernel.prx`, whose NID import cannot resolve against that already-loaded libc. The reproduced correction is to link `libc` only under `if(WIN32)`, as in the CMAC patched test. This matters because the current test report claims those patched cases pass, while Linux product CI was skipped. Please apply the platform-specific linkage and rerun the seven PFR cases on Linux and Windows. 2. Add `<cstddef>` directly to `GuestFreeTypePfr.cpp` for its `offsetof` use. The exact-head report and CI show conventions, eligibility, intake, labels and progress report pass; product build/test jobs are skipped. I did not rerun the full FreeType build in this environment. I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
UnhealthyKraken commented 2026-10-22 14:26:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T14:26:48Z.


Fixed both concrete review items in 1df8b3cd063baaf7a20869b8405678b164d28216, together with a history-preserving merge of current main 329efe1bfd. The test links guest libc only on Windows, so Linux patched cases no longer preload the raw runtime. <cstddef> is now included directly for offsetof.

Rebuilt the full affected Windows libraries and reran the seven PFR cases, the existing FreeType/charmap cases and the loader: 10/10 pass. Conventions/current PR body, whitespace, and test registration pass (1176 executables, none unregistered).

I could not rerun Linux locally: the installed Ubuntu WSL has no CMake, Ninja, g++ or pkg-config; I installed nothing. @jotitadev's original-head Linux reproduction and successful run with this same linkage correction remain attributed evidence, not a Linux run of this new head by me. A fresh Linux rerun is still welcome. The PR description now states that limitation explicitly. @MarcZX10 @fogydes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343201377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9646#issuecomment-6343201377). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T14:26:48Z. --- Fixed both concrete review items in `1df8b3cd063baaf7a20869b8405678b164d28216`, together with a history-preserving merge of current main `329efe1bfd`. The test links guest `libc` only on Windows, so Linux patched cases no longer preload the raw runtime. `<cstddef>` is now included directly for `offsetof`. Rebuilt the full affected Windows libraries and reran the seven PFR cases, the existing FreeType/charmap cases and the loader: **10/10 pass**. Conventions/current PR body, whitespace, and test registration pass (1176 executables, none unregistered). I could not rerun Linux locally: the installed Ubuntu WSL has no CMake, Ninja, g++ or pkg-config; I installed nothing. @jotitadev's original-head Linux reproduction and successful run with this same linkage correction remain attributed evidence, not a Linux run of this new head by me. A fresh Linux rerun is still welcome. The PR description now states that limitation explicitly. @MarcZX10 @fogydes
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!9646
No description provided.