Commit Graph

13 Commits

Author SHA1 Message Date
mugurc f3c514744b feat(nid): patch NIDs in Mach-O libraries
nid_patcher turns the _nid_postfix names of a library into NIDs for ELF
and PE. A library built on macOS is a Mach-O dylib, whose exports are in
a dyld export trie and whose imports are in the chained fixups, so it
gets its own patcher.

- The export trie is read, every exported C name (without Mach-O's
  leading underscore) is resolved to its NID, and the trie is rebuilt the
  way ld64 lays it out: the offsets are uleb128, so the layout is repeated
  until it is stable. A trie that no longer fits is appended to
  __LINKEDIT, which has to end the file, and a signed image is refused.
- Weak definitions that are not marked _nid_postfix or _nid_no_patch keep
  their names: dyld coalesces those across images by name.
- In the chained imports, names bound to a .prx dylib that are guest
  facing (a _nid_postfix name or an sce prefix) are patched in place; a
  name that would grow, or that shares storage with another import, is an
  error. Images that use bind opcodes instead of chained fixups are
  refused.
- ExportExclusions reads the exports of a reference Mach-O, so the
  exclusion list works for libraries built on macOS as well.
2026-10-09 15:40:29 +03:00
MGXAe 049539ac3d fix(nid): reject libraries that define symbol versions
The patcher rewrites .dynstr in place and reorders .dynsym for
.gnu.hash, but .gnu.version_d kept pointing at name offsets that the
rewrite had recycled: a library carrying symbol version definitions
came out with renamed or blanked version names while its symbols
still advertised a version.

No library in the build defines symbol versions, so fail on
.gnu.version_d during the section scan and leave the input untouched
instead of carrying version remapping that nothing exercises. The
test covers the rejection and that a library without version
definitions is still patched.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
2026-10-08 03:04:07 +00:00
alfalfa-star 1d9d5ab491 fix(libs): keep a $ORIGIN runpath in the patched prx libraries
The NID patcher rebuilds .dynstr keeping only the DT_NEEDED and
DT_SONAME strings, so DT_RUNPATH kept a stale offset and the patched
libraries shipped with an empty runpath. A library could then load only
those sibling prx that the executable already loads itself:
libSceVideoOut.prx needs libSceKeyboard.prx, which a title that does
not import libSceKeyboard never loads, so it fails at startup.

The patcher now keeps DT_RPATH and DT_RUNPATH strings, and the prx
libraries are linked with a $ORIGIN runpath instead of the build
directory, so they find each other wherever they are copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 20:20:14 +02:00
owner 63209b584f fix: correct sscanf %x signedness and avoid a substr copy
libSceSysmodule/Export.cpp parsed /proc/self/maps device major/minor
numbers into signed int with a %x format, which is undefined behaviour
per the C standard even though it happened to work on this target;
switched to unsigned int to match the format specifier.

NidPatcherUtils.hpp's StripNidPostfix built a truncated copy with
substr(0, n) where the prefix is already the string itself; resize(n)
does the same truncation without the extra allocation and copy.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-26 14:11:50 -06:00
boykopovar a43f73163d feat(libs): no patch already exported from libc.prx symbols 2026-09-22 18:21:08 +03:00
boykopovar 1e4740ed4b fix(nid): no patch sdl exports for nid 2026-09-14 10:52:04 +03:00
boykopovar a369e0126c feat(libs): nid patching for non-std imports from prx 2026-09-09 08:12:27 +03:00
boykopovar 14f8c16ac4 fix(libs): add _nid_no_patch_cut postfix and global cxa/unwind exports 2026-09-07 10:56:34 +03:00
boykopovar 53b20aec77 refactor(nid): separate nid resolving logic 2026-09-07 07:52:09 +03:00
boykopovar 58aef08fe1 feat(nid): add nid_no_patch rule 2026-09-06 13:49:24 +03:00
boykopovar 6dfd5a9296 refactor(nid): rename spec cpp + move utils 2026-08-21 15:16:25 +03:00
boykopovar c6550929e9 refactor(nid): windows and linux pathing separating via interface 2026-08-21 15:00:55 +03:00
boykopovar 9e21a054e0 feat(libs): add rpx library build as libs target 2026-08-20 17:06:41 +03:00