fix(relinker): preserve executable defined-symbol relocations #5229

Closed
ideabsassistenza wants to merge 1 commit from upstream-pr/5229 into main
ideabsassistenza commented 2026-10-13 15:15:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ideabsassistenza on 2026-10-13T15:15:41Z.


What

A defined function in the main executable is currently rebuilt as an undefined external import. A synthetic executable that jumps through an R_X86_64_64 pointer to its own local function fails Windows conversion with ELF imports have no DT_NEEDED libraries; the equivalent RELATIVE fixture executes and returns 42. Linux output also loses the local definition.

Preserve defined executable symbols for R_X86_64_64, GLOB_DAT and JUMP_SLOT, keeping them separate from external import filtering and registry entries. Rebuild local symbols before globals, remap relocation indices and set .dynsym.sh_info and the ELF hash appropriately. Local PLT definitions are hidden so lazy binding resolves their own address without a global lookup.

Windows applies defined addresses with image relocation, and absolute symbols without image relocation. Filtering uses a private copy with the defined references represented as pointer edges; the output retains the actual symbol definitions and relocation types. Strict filtering reads those edges from both RELA and JMPREL and PLT compaction retains internal slots. Unsupported reserved section indices, symbol kinds and relocation forms throw.

Semantics follow the ELF symbol rules and AMD64 relocation definitions: R64 is S+A, GLOB_DAT/JUMP_SLOT are S, and SHN_ABS receives no image bias.

Related #4952 changes symbol bounds in the same extraction area; this PR's full-entry read is needed to inspect the definition. #4726 addresses export roots and #4593 Linux fixed bases. Their behavior is separate from this fix. No title compatibility claim.

Tested

Windows, supported GCC 15.2.0 WinLibs ucrt-posix-seh r7, CMake 4.4.4, Ninja, Release relinker-only, CPython 3.12.14.

  • Baseline regression fails: the defined local function appears as an external registry entry. Separate Windows reproduction fails conversion; the RELATIVE control executes with return code 42.

  • New synthetic regressions cover local/global/weak definitions, positive/negative R64 addends, absolute data values, GLOB_DAT and JUMP_SLOT, all three filter levels, genuine imports reached through internal pointers, and a two-slot PLT with an unused import removed while the defined thunk index changes. Check actual ELF definitions, local ordering, hash metadata, registry contents, PE pointer values and presence/absence of PE base relocations. Windows outputs execute and return 42.

  • Linux eager/lazy runtime checks are included for x86-64 Linux runners. Locally, Linux output metadata was checked; Linux/macOS runtime, full libraries, GPU and commercial titles were not tested.

  • Rebased onto 0214069e33ccfab4bd97ec973637299895f786d0, preserving upstream's function/data import classification alongside defined-symbol metadata. On current head 2447af9c345ddb2911029f9c295cada32741eb65, Release native CTest passed 150/150 in 236.87 seconds, including the new defined-symbol regressions and upstream Windows import tracing. Conventions checks passed.

  • The previous revision 03283950cacea4e4590fd100d743e5b2e2603f63 passed all executed upstream CI checks, including relinker builds/tests on Linux, Windows and macOS (Build run). The updated revision triggers a new CI run; those earlier results are not claimed for the rebased head.

  • windows_fixed_base was excluded from the final local suite: its intentional occupied-address executable opens a Windows error dialog (0xc0000018) on this desktop and can time out. The same timeout was reproduced on the original upstream converter. Isolated original and corrected runs passed when critical-error dialogs were returned to the test process; the test itself is unchanged. No global system/security settings were changed.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4845402634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5229). Originally posted by [ideabsassistenza](https://github.com/ideabsassistenza) on 2026-10-13T15:15:41Z. --- ### What A defined function in the main executable is currently rebuilt as an undefined external import. A synthetic executable that jumps through an `R_X86_64_64` pointer to its own local function fails Windows conversion with `ELF imports have no DT_NEEDED libraries`; the equivalent RELATIVE fixture executes and returns 42. Linux output also loses the local definition. Preserve defined executable symbols for `R_X86_64_64`, `GLOB_DAT` and `JUMP_SLOT`, keeping them separate from external import filtering and registry entries. Rebuild local symbols before globals, remap relocation indices and set `.dynsym.sh_info` and the ELF hash appropriately. Local PLT definitions are hidden so lazy binding resolves their own address without a global lookup. Windows applies defined addresses with image relocation, and absolute symbols without image relocation. Filtering uses a private copy with the defined references represented as pointer edges; the output retains the actual symbol definitions and relocation types. Strict filtering reads those edges from both RELA and JMPREL and PLT compaction retains internal slots. Unsupported reserved section indices, symbol kinds and relocation forms throw. Semantics follow the [ELF symbol rules](https://refspecs.linuxfoundation.org/elf/gabi4%2B/ch4.symtab.html) and [AMD64 relocation definitions](https://refspecs.linuxfoundation.org/elf/x86_64-SysV-psABI.pdf): R64 is S+A, GLOB_DAT/JUMP_SLOT are S, and SHN_ABS receives no image bias. Related #4952 changes symbol bounds in the same extraction area; this PR's full-entry read is needed to inspect the definition. #4726 addresses export roots and #4593 Linux fixed bases. Their behavior is separate from this fix. No title compatibility claim. ### Tested Windows, supported GCC 15.2.0 WinLibs ucrt-posix-seh r7, CMake 4.4.4, Ninja, Release relinker-only, CPython 3.12.14. - Baseline regression fails: the defined local function appears as an external registry entry. Separate Windows reproduction fails conversion; the RELATIVE control executes with return code 42. - New synthetic regressions cover local/global/weak definitions, positive/negative R64 addends, absolute data values, GLOB_DAT and JUMP_SLOT, all three filter levels, genuine imports reached through internal pointers, and a two-slot PLT with an unused import removed while the defined thunk index changes. Check actual ELF definitions, local ordering, hash metadata, registry contents, PE pointer values and presence/absence of PE base relocations. Windows outputs execute and return 42. - Linux eager/lazy runtime checks are included for x86-64 Linux runners. Locally, Linux output metadata was checked; Linux/macOS runtime, full libraries, GPU and commercial titles were not tested. - Rebased onto `0214069e33ccfab4bd97ec973637299895f786d0`, preserving upstream's function/data import classification alongside defined-symbol metadata. On current head `2447af9c345ddb2911029f9c295cada32741eb65`, Release native CTest passed 150/150 in 236.87 seconds, including the new defined-symbol regressions and upstream Windows import tracing. Conventions checks passed. - The previous revision `03283950cacea4e4590fd100d743e5b2e2603f63` passed all executed upstream CI checks, including relinker builds/tests on Linux, Windows and macOS ([Build run](https://github.com/boykopovar/AnyPS5/actions/runs/38420531720)). The updated revision triggers a new CI run; those earlier results are not claimed for the rebased head. - `windows_fixed_base` was excluded from the final local suite: its intentional occupied-address executable opens a Windows error dialog (`0xc0000018`) on this desktop and can time out. The same timeout was reproduced on the original upstream converter. Isolated original and corrected runs passed when critical-error dialogs were returned to the test process; the test itself is unchanged. No global system/security settings were changed. ### 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 (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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
oneandonlydean commented 2026-10-14 05:36:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:36:42Z.


Closing: the 14 retail executables we checked have no R_X86_64_64, GLOB_DAT or JUMP_SLOT relocation against a defined symbol (they use RELATIVE for that), so this changes no converted title. Reopen with the title or file that fails on current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161700232 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5229#issuecomment-6161700232). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T05:36:42Z. --- Closing: the 14 retail executables we checked have no R_X86_64_64, GLOB_DAT or JUMP_SLOT relocation against a defined symbol (they use RELATIVE for that), so this changes no converted title. Reopen with the title or file that fails on current main.

Pull request closed

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!5229
No description provided.