Skip to content

feat(relinker): support packed ELF64 relative relocations - #11463

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
Mherberts:codex/feat-elf-relr-relocations
Oct 28, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
Mherberts:codex/feat-elf-relr-relocations

Conversation

@Mherberts

@Mherberts Mherberts commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

An ELF64 x86-64 executable or bundled module containing DT_RELR currently fails conversion. Add decoding of DT_RELR / DT_RELRSZ / DT_RELRENT according to gABI 6.2, Relative Relocation Table.

Expand address entries and 63-bit bitmap windows into ordinary R_X86_64_RELATIVE relocations, taking implicit addends from file data or zero-filled load memory. Executables and bundled modules then use the existing Linux, Windows and macOS relocation writers. The relative-relocation index also consumes RELR so reachability analysis retains its pointer targets; guest lifecycle arrays see the normalized relocations before initializer validation.

Validate complete metadata, entry/table sizes, file and memory bounds, ambiguous mappings, bitmap address overflow and overlapping storage. Cross-segment storage units and relocation composition remain rejected and are recorded in docs/dev/debt/relinker.md.

Tested

Windows x64, build 26200; WinLibs GCC 15.2.0 r7; Ninja, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, Python 3.13. Current head 7c90e64474ec7d3ebc6d143f06f6e2ad3b04a726 is rebased onto upstream main 2ee8e9751a06bd4cb7edb8d17f433d56a39a7025. The previous refreshed head was fabd547a2df833e1bc71e145ea6a656918d18d68. Initial feature validation was at fad2ff38efac4c7f098a31b7ce1ef5bbbe1266ef on 3ead2d7251, followed by the Linux fixture fix eb2dd32a51588d2b36285169182b556512d2f047; results on those heads are identified below.

  • On current head 7c90e64474, the complete relinker-only build passes. 10/10 focused CTests pass in 36.32 s: relr_relocations, dynamic_segment, none_relocations, guest_none_relocations, optional_plt, optional_rela, relr_conversion, guest_relr_conversion, elf_header, strict_nid_filter.

  • Coordination with fix(libc): use the default heap for an executable without process parameters #11979: moved the two RELR conversion-test registrations beside optional_rela, away from its windows_process_parameters insertion after elf_header. Test commands and timeouts are unchanged. git range-diff shows the three previous commits preserved exactly through the rebase, plus this CMake-only move.

  • Integration proof: git merge-tree --write-tree HEAD refs/pr/11979 and its reverse both exit 0 against fix(libc): use the default heap for an executable without process parameters #11979 head 0cb4dde2eec3249a9b96f86e602d3262d853095a, producing the same tree d9c9c37da88b72b568b548e05eae7142b4dba0cd. That tree retains each of relr_relocations, relr_conversion, guest_relr_conversion and windows_process_parameters exactly once, with their test sources present. No landing-order dependency remains between these two PRs.

  • Current registration audits pass: all 40 native test executables and all 203 Python test scripts have a CTest/workflow entry. Conventions against upstream/main and git diff --check pass. The required check against the fork's older origin/main completes with 0 errors and 43 upstream debt warnings.

  • Current overlap recheck used the official branch checker through the public-API adapter with 1,315 open PRs. Only this PR's own previous remote head is reported, on its four new RELR files; fix(libc): use the default heap for an executable without process parameters #11979 is no longer reported. The base-conflicting shared files in feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, fix(libc): use the default heap for an executable without process parameters #6713 and fix(relinker): analyze referenced code beyond SCE scan boundaries #10861 were manually inspected: their changes concern other test registrations, TLS debt and syscall/code-extent analysis, not the relocated RELR registration or decoder.

  • At fabd547a2d, the complete relinker-only build passes. Five focused CTests pass in 8.03 s: relr_relocations, optional_rela, relr_conversion, guest_relr_conversion and strict_nid_filter.

  • Linux CI correction at eb2dd32: the original synthetic entries returned into EntryStubBuilder's intentional UD2, causing the two SIGILL failures. Linux fixtures now call the original entry, compare its expected result (42/11), and reach INT3 only on success; a mismatch reaches UD2. Native assertions require SIGTRAP on x86-64 and use the existing core-dump guard. The five focused tests pass locally (6.91 s), and the new Ubuntu relinker job passes. The original Ubuntu job passed 314/316 tests, failing only those two runtime assertions.

  • At fad2ff3, 88/88 related CTests passed in 85.69 s: ctest --test-dir build-verify -R '(relr|rela|relocation|guest|tls|optional_plt|dynamic_segment|linux_fixed_base|windows_gui|strict_nid_filter)' --output-on-failure --parallel 2. This includes the existing imports, TLS, module lifecycle and reachability coverage. The complete CTest suite was not run.

  • New native tests exercise every bitmap bit, chained/empty windows, independent address entries, implicit and partially zero-filled addends, bounds, invalid metadata, overlaps and overflow. They also verify the relative-relocation index.

  • The two new conversion tests cover 103 conversions/rejections across Linux fixed-address ELF, Linux PIE, PE and Mach-O, for executables and bundled modules. They inspect the exact normalized Linux relocation sets and counts, absence of RELR tags, and load-page congruence. Nine successful cases execute on Windows; module fixtures require a relocated function pointer and an initializer's state change to return the expected result. Cases include mixed RELA/RELR, BSS and partial-file words, even unaligned slots, empty tables and malformed inputs.

  • Negative control: built an isolated, clean git archive snapshot of main 3ead2d7251 with the same GCC 15.2.0 and Release relinker-only configuration. The same conversion tests fail there with DT_RELR relocations are not supported for executables and Unsupported dynamic tag 35 for modules; the feature build passes.

  • At fabd547a2d, python tools/check_conventions.py --base upstream/main, python tools/check_test_registration.py build-verify and git diff --check pass. The required conventions comparison against the fork's older origin/main also completes with zero errors and 32 debt-length warnings in already-merged upstream content.

  • At fabd547a2d, overlap recheck: the official tools/pr_overlap.py branch comparison used the public-API adapter and a fresh inventory of 1,339 open PRs. Its only confirmed entry is this PR's own previous remote head, matched on the four new RELR files. The base-conflicting warnings feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, fix(libc): use the default heap for an executable without process parameters #6713, fix(relinker): trap int 0x80 in a software interrupt table instead of refusing the image #10479 and fix(relinker): analyze referenced code beyond SCE scan boundaries #10861 were manually checked: their shared changes concern other test registrations, TLS notes, software interrupt tables and code-boundary scanning. The include-only collision with fix(relinker): keep embedded data tables out of --to-intel and --to-rosetta conversion #11525 was removed by moving the RELR include away from the header it removes; git merge-tree --write-tree HEAD refs/pr/11525 returns success. No dependency on those PRs.

Linux and macOS artifacts were converted and inspected on Windows; native execution on those hosts, commercial titles and GPUs were not tested locally.

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current Ubuntu relinker job has two reproducible failures on this head. Internal ctest changing into directory: /marc/AnyPS5/build-relinker builds successfully, but both and fail at on the / case: execution returns (SIGILL) instead of the fixture's expected 42/11. The preceding output-format and relocation-set assertions pass, so this is specifically the generated Linux executable's runtime behavior. Windows relinker and ASan pass; macOS jobs are still queued. Please reproduce and correct the Linux execution failure (or establish that the runner/test setup is at fault with evidence) before merge, then rerun the focused conversion tests.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current Ubuntu relinker job has two failures on this head. Its log shows that the relinker builds successfully, but both relr_conversion and guest_relr_conversion fail at test_relr_relocations.py:129 on the addresses / linux case: execution returns -4 (SIGILL) instead of the fixture's expected 42/11. The preceding output-format and relocation-set assertions pass, so this is specifically the generated Linux executable's runtime behavior.

The Windows relinker and ASan jobs pass; macOS jobs are still queued. Please reproduce and correct the Linux execution failure, or establish with evidence that the runner/test setup is at fault, before merge; then rerun the focused conversion tests.

@MarcZX10

Copy link
Copy Markdown
Contributor

Correction and local reproduction detail for my review above: I built this exact head on Linux and reran both focused CTests; both fail identically at the stated assertion. Inspecting the generated ELF shows the failure is in the test fixture's entry convention, not evidence of an incorrect RELR relocation: the Linux entry stub calls the original entry point and deliberately emits ud2 if it returns (EntryStubBuilder::BuildEntryStub). The addresses main fixture jumps to a helper that returns 42, and the guest executable fixture ends its entry code with ret, so both return into that intentional trap. Please change the Linux runtime fixtures to terminate through a Linux _start-appropriate exit path while still checking the relocated pointer, or keep the runtime-return assertion on Windows and use Linux's already-checked relocation bytes/metadata for these cases. The CI failure remains real and should be cleared by correcting the test, but I withdraw the implication that the RELR implementation itself caused the SIGILL.

Independent local validation: clean ANYPS5_RELINKER_ONLY=ON Release build of head fad2ff38efac4c7f098a31b7ce1ef5bbbe1266ef succeeded; ctest -R '^(relr_conversion|guest_relr_conversion)$' reproduced both failures.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 10861 core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L7

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 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 6713 core/relinker/CMakeLists.txt
PR 7173 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7531 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 9793 core/relinker/CMakeLists.txt
PR 11192 docs/dev/debt/relinker.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the updated head eb2dd32a51588d2b36285169182b556512d2f047. The Linux fixture now validates the generated entry's result before reaching the relinker's intentional return trap; I rebuilt the relinker locally and both relr_conversion and guest_relr_conversion pass. Current checks also pass for git diff --check, conventions, and a clean merge-tree preview against main.

The updated hosted run 40345897734 has Ubuntu and ASan passing; Windows is running and both macOS jobs are queued. The original Linux failure is resolved by the fixture correction, not a change to RELR conversion logic.

One repository rule remains: this branch's merge base is 3ead2d725174, while current main is 7903201bb426. I found no intervening changes under the touched relinker paths, and the merge preview is clean, but CONTRIBUTING requires branches to stay current with main. Please sync the branch before merge. I am requesting changes only for that branch-freshness requirement; the prior Linux runtime finding is withdrawn.

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed eb2dd32a5158 against 2dbe9b99f577. No actionable findings.

The parser rejects incomplete metadata, invalid mappings, bitmap overflow and overlapping relocation storage before normalizing RELR into the existing RELA pipeline. Guest-image conversion and reachability indexing consume the decoded entries; fixtures check relocation output and guest initializer/input side effects.

Validation: The local Release relinker-only build passed (312 build steps); relr_relocations, relr_conversion, guest_relr_conversion and optional_rela passed (4/4), as did an independent PT_LOAD-end overflow check. Hosted relinker jobs merged the PR head into checkout 7903201bb426: Windows CTest 312/312, Ubuntu 316/316 and macOS 306/306 on both runners (0 failures; no skipped tests listed). Hosted ASAN passed 34/34 tls_function_coverage tests; it did not run RELR tests.

The local full CTest run did not complete: unrelated shader-cache tests failed while creating or using temporary CMake/Ninja builds. My cached-binary control was fixture-incompatible, so the author's pinned-base negative control remains unverified. Other hosted workflow jobs were skipped.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran on macOS: Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release. Head fabd547a2d applied on current main cb45ae2ddf (clean merge). Two builds: arm64 native, and x86_64 under Rosetta with /usr/bin/python3 3.9.6. Full suite: arm64 312/312, Rosetta 310/310 (main: 309/309 and 307/307, plus the 3 new tests).

One addition from macOS. For --macos, test_relr_relocations.py checks only the Mach-O magic; it executes outputs only on Windows and Linux hosts. So I executed the macOS outputs:

  • Run. I converted the five positive executable cases (addresses, bitmap, mixed, zero-fill-addends, even-unaligned-slot) with --macos --skip-sce-module. I ran each Mach-O under Rosetta with stub x86_64 dylibs for libkernel.prx and libc.prx, where Aps5StartGuest_nid_no_patch calls the entry and exits with its return value (the START pattern of test_macos_trace_imports.py).
  • Result. All five exit 42, so the entry's jmp [0x800] reaches 0x210 through the RELR-relocated slot. The result is the same whether the relinker was built arm64 or x86_64.
  • On main, the same inputs fail with DT_RELR relocations are not supported.

If you want that covered by the test itself, the run fits under sys.platform == "darwin" the same way test_macos_trace_imports.py does it. That is optional and not a blocker.

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

@Mherberts
Mherberts force-pushed the codex/feat-elf-relr-relocations branch from fabd547 to 7c90e64 Compare October 27, 2026 15:04
@oneandonlydean
oneandonlydean merged commit adbcdcd into boykopovar:main Oct 28, 2026
14 checks passed
adriadam10 pushed a commit that referenced this pull request Nov 1, 2026
CodeInstructionCollector took code pointers from DT_RELA and DT_JMPREL
but not from DT_RELR, which the pipeline has applied since #11463. A
function reachable only through a RELR pointer was therefore no entry
root, and a Windows TLS rewrite or GS trap could overwrite it without
the "would overwrite an executable entry point" refusal that the same
pointer as a RELA R_X86_64_RELATIVE triggers. Read the RELR table with
ReadRelrRelocations and record its slots like relative relocations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants