fix(relinker): preserve executable defined-symbol relocations #5229
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5229"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_64pointer to its own local function fails Windows conversion withELF 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_DATandJUMP_SLOT, keeping them separate from external import filtering and registry entries. Rebuild local symbols before globals, remap relocation indices and set.dynsym.sh_infoand 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 head2447af9c345ddb2911029f9c295cada32741eb65, 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
03283950cacea4e4590fd100d743e5b2e2603f63passed 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_basewas 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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.
Pull request closed