fix(relinker): preserve DF_SYMBOLIC on guest modules #5981

Merged
MarcZX10 merged 4 commits from upstream-pr/5981 into main 2026-10-18 18:33:07 +00:00
MarcZX10 commented 2026-10-14 18:05:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T18:05:15Z.


What

Accept DF_SYMBOLIC on guest ELF modules and preserve it when the relinker writes Linux guest modules. The ELF ABI uses this flag to make references from a shared object search that object before the executable and other shared objects. The Linux module writer now emits DF_SYMBOLIC | DF_BIND_NOW for those modules; modules without the input flag keep DF_BIND_NOW only.

Addresses the DF_SYMBOLIC conversion blocker in #5927. It does not address the separate ambiguous undeclared imports or the intermittent Windows relinker crash reported there, and it does not claim RetroArch cores now load or run.

Tested

  • Debian 12 / GCC 12.2, Release Ninja relinker-only build (ANYPS5_RELINKER_ONLY=ON): relinker built.
  • guest_module_directories and guest_intel_trampolines: passed (2/2). The integration case verifies a symbolic guest module converts and its Linux output has flags 0xA, while an ordinary module remains at 0x8; Windows conversion also accepts the input flag.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check passed.
  • No RetroArch core was run.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4862273057 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T18:05:15Z. --- ### What Accept `DF_SYMBOLIC` on guest ELF modules and preserve it when the relinker writes Linux guest modules. The ELF ABI uses this flag to make references from a shared object search that object before the executable and other shared objects. The Linux module writer now emits `DF_SYMBOLIC | DF_BIND_NOW` for those modules; modules without the input flag keep `DF_BIND_NOW` only. Addresses the `DF_SYMBOLIC` conversion blocker in #5927. It does not address the separate ambiguous undeclared imports or the intermittent Windows relinker crash reported there, and it does not claim RetroArch cores now load or run. ### Tested - Debian 12 / GCC 12.2, Release Ninja relinker-only build (`ANYPS5_RELINKER_ONLY=ON`): `relinker` built. - `guest_module_directories` and `guest_intel_trampolines`: passed (2/2). The integration case verifies a symbolic guest module converts and its Linux output has flags `0xA`, while an ordinary module remains at `0x8`; Windows conversion also accepts the input flag. - `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check` passed. - No RetroArch core was run. ### Checklist - [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 - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-14 20:06:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T20:06:01Z.

Review: COMMENTED


macOS data point, including the Mach-O output.

Apple M2 Max, macOS 27.2 (26B5091g), AppleClang, Ninja Release, relinker-only. Head 7ccf79a6f merged without conflicts into main c26982f63.

  • arm64: ctest 163/163.
  • x86_64 under Rosetta 2 (-DCMAKE_OSX_ARCHITECTURES=x86_64, Python 3.9.6): 159/163; the 4 failures (pr_overlap_encoding, stubgen_stdout_newlines, release_package, linux_fixed_base) fail the same way on unmodified main here. hardware_oracle_compare (Python, not touched here) also hit its 20 s timeout once in the parallel run while the machine was loaded; it passes when run alone.
  • With only the two test files applied on main, guest_module_directories fails on both builds with provider.prx: Unsupported guest dynamic flags; with the PR, guest_module_directories and guest_intel_trampolines pass.

The test converts with the Linux and Windows targets only. I added --macos by hand: a provider built with module_with_symbol(True, symbolic=...) plus a type 6 relocation at 0x2320 against its own exported shared, next to the test's consumer module (arm64 and x86_64 relinker binaries, same results):

Target DF_SYMBOLIC provider on main This PR
Linux rejected (Unsupported guest dynamic flags) converts, DT_FLAGS 0xa (non-symbolic: 0x8)
--macos rejected converts to an x86_64 Mach-O dylib
--windows rejected converts to PE

In the Mach-O output the self-reference is a rebase, not a bind: the rebase opcodes are 11 22 a0 06 51 23 08 51 00 (segment 2 offset 0x320, segment 3 offset 0x8) and the bind table is empty, with or without DF_SYMBOLIC in the input. From reading WriteMacOs, relocations against symbols the module defines appear to be resolved inside the module, so on macOS accepting the flag looks sufficient; I only checked this one fixture.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5523947452 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#pullrequestreview-5523947452). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-14T20:06:01Z. **Review:** COMMENTED --- macOS data point, including the Mach-O output. Apple M2 Max, macOS 27.2 (26B5091g), AppleClang, Ninja Release, relinker-only. Head `7ccf79a6f` merged without conflicts into `main` `c26982f63`. - arm64: ctest 163/163. - x86_64 under Rosetta 2 (`-DCMAKE_OSX_ARCHITECTURES=x86_64`, Python 3.9.6): 159/163; the 4 failures (`pr_overlap_encoding`, `stubgen_stdout_newlines`, `release_package`, `linux_fixed_base`) fail the same way on unmodified `main` here. `hardware_oracle_compare` (Python, not touched here) also hit its 20 s timeout once in the parallel run while the machine was loaded; it passes when run alone. - With only the two test files applied on `main`, `guest_module_directories` fails on both builds with `provider.prx: Unsupported guest dynamic flags`; with the PR, `guest_module_directories` and `guest_intel_trampolines` pass. The test converts with the Linux and Windows targets only. I added `--macos` by hand: a provider built with `module_with_symbol(True, symbolic=...)` plus a type 6 relocation at `0x2320` against its own exported `shared`, next to the test's consumer module (arm64 and x86_64 relinker binaries, same results): | Target | `DF_SYMBOLIC` provider on `main` | This PR | |---|---|---| | Linux | rejected (`Unsupported guest dynamic flags`) | converts, `DT_FLAGS` `0xa` (non-symbolic: `0x8`) | | `--macos` | rejected | converts to an x86_64 Mach-O dylib | | `--windows` | rejected | converts to PE | In the Mach-O output the self-reference is a rebase, not a bind: the rebase opcodes are `11 22 a0 06 51 23 08 51 00` (segment 2 offset `0x320`, segment 3 offset `0x8`) and the bind table is empty, with or without `DF_SYMBOLIC` in the input. From reading `WriteMacOs`, relocations against symbols the module defines appear to be resolved inside the module, so on macOS accepting the flag looks sufficient; I only checked this one fixture. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-16 16:13:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T16:13:52Z.


Thanks for the macOS results and the exact source pins. The arm64 163/163 result is useful; I’ll keep the Rosetta failures and the parallel-only timeout recorded as platform-specific results that also reproduce on your unmodified main, rather than attributing them to this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6219693578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6219693578). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T16:13:52Z. --- Thanks for the macOS results and the exact source pins. The arm64 163/163 result is useful; I’ll keep the Rosetta failures and the parallel-only timeout recorded as platform-specific results that also reproduce on your unmodified main, rather than attributing them to this PR.
github-actions[bot] commented 2026-10-17 23:36:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T23:36:51Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6879 core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp
PR 6977 core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/relinker/include/relinker/guest/GuestImage.hpp
core/relinker/relinker/src/guest/GuestImageReader.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243164569 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6243164569). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T23:36:51Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp`<br>`core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp`<br>`core/relinker/relinker/include/relinker/guest/GuestImage.hpp`<br>`core/relinker/relinker/src/guest/GuestImageReader.cpp` |
MarcZX10 commented 2026-10-18 00:22:03 +00:00 (Migrated from github.com)

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


I manually compared the shared-file patches with #6977 after the overlap bot could not compare them against its conflicting base. The hunks are currently independent: this PR carries GuestImage::Symbolic, reads DF_SYMBOLIC, and emits it with DF_BIND_NOW; #6977 changes HasInit, PS4 module-import parsing, and own-TLS relocation handling. I do not see a same-line conflict or a dependency between these changes. The branches may still need conflict resolution when #6977 is rebased because they edit the same files.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243670808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6243670808). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T00:22:03Z. --- I manually compared the shared-file patches with #6977 after the overlap bot could not compare them against its conflicting base. The hunks are currently independent: this PR carries `GuestImage::Symbolic`, reads `DF_SYMBOLIC`, and emits it with `DF_BIND_NOW`; #6977 changes `HasInit`, PS4 module-import parsing, and own-TLS relocation handling. I do not see a same-line conflict or a dependency between these changes. The branches may still need conflict resolution when #6977 is rebased because they edit the same files.
oneandonlydean commented 2026-10-18 17:22:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T17:22:38Z.


Linux looks right. On Windows the flag is accepted but no writer uses image.Symbolic, so a symbolic module's references to its own exports resolve the ordinary way. Could Windows either keep refusing DF_SYMBOLIC until symbolic resolution is implemented there, or record the gap in the relinker debt file?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252854768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6252854768). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T17:22:38Z. --- Linux looks right. On Windows the flag is accepted but no writer uses `image.Symbolic`, so a symbolic module's references to its own exports resolve the ordinary way. Could Windows either keep refusing `DF_SYMBOLIC` until symbolic resolution is implemented there, or record the gap in the relinker debt file?
MarcZX10 commented 2026-10-18 17:30:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:30:31Z.


Good catch. The Windows writer currently has no DF_SYMBOLIC handling, so accepting the flag would silently give the wrong lookup semantics. I updated the branch in 86d3c085e to reject DF_SYMBOLIC guest modules explicitly in the Windows writer, and added a regression to windows_guest_export_alias_tests. The changed writer and test translation units cross-compile with MinGW; conventions, diff checks, and the overlap scan pass. I have not run the Windows-specific test executable in this Linux environment, so the hosted Windows test remains the runtime validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252939187 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6252939187). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T17:30:31Z. --- Good catch. The Windows writer currently has no `DF_SYMBOLIC` handling, so accepting the flag would silently give the wrong lookup semantics. I updated the branch in 86d3c085e to reject `DF_SYMBOLIC` guest modules explicitly in the Windows writer, and added a regression to `windows_guest_export_alias_tests`. The changed writer and test translation units cross-compile with MinGW; conventions, diff checks, and the overlap scan pass. I have not run the Windows-specific test executable in this Linux environment, so the hosted Windows test remains the runtime validation.
MarcZX10 commented 2026-10-18 17:34:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:34:16Z.


The first hosted run caught a fixture interaction: guest_module_directories passes one symbolic provider through both Linux and Windows writer modes. Commit 2f7eb66c6 keeps the symbolic provider for Linux (where this PR implements it) and uses a non-symbolic provider for the Windows directory-discovery case; the dedicated Windows writer regression still asserts that symbolic input is rejected. I rebuilt the relinker and reran guest_module_directories locally: 1/1 passed. The rerun on this head will exercise the remaining Windows-specific check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252977329 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6252977329). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T17:34:16Z. --- The first hosted run caught a fixture interaction: `guest_module_directories` passes one symbolic provider through both Linux and Windows writer modes. Commit `2f7eb66c6` keeps the symbolic provider for Linux (where this PR implements it) and uses a non-symbolic provider for the Windows directory-discovery case; the dedicated Windows writer regression still asserts that symbolic input is rejected. I rebuilt the relinker and reran `guest_module_directories` locally: 1/1 passed. The rerun on this head will exercise the remaining Windows-specific check.
MarcZX10 commented 2026-10-18 17:35:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:35:42Z.


I added an end-to-end assertion in guest_module_directories that --windows conversion of a DF_SYMBOLIC module exits with the explicit unsupported error and does not write an output. The relinker-only build succeeds and the focused CTest passes (1/1) locally. This exercises the Windows writer path on Linux CI as well as retaining the direct writer regression for Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252992239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6252992239). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T17:35:42Z. --- I added an end-to-end assertion in `guest_module_directories` that `--windows` conversion of a `DF_SYMBOLIC` module exits with the explicit unsupported error and does not write an output. The relinker-only build succeeds and the focused CTest passes (1/1) locally. This exercises the Windows writer path on Linux CI as well as retaining the direct writer regression for Windows.
oneandonlydean commented 2026-10-18 18:33:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T18:33:24Z.


Merged while @adriadam10 is away: the review passed and full CI is green on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253583819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5981#issuecomment-6253583819). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T18:33:24Z. --- Merged while @adriadam10 is away: the review passed and full CI is green on this head.
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!5981
No description provided.