fix(relinker): accept RELATIVE relocations against a zero-value section symbol #4203

Merged
saxopa merged 1 commit from upstream-pr/4203 into main 2026-10-12 12:21:35 +00:00
saxopa commented 2026-10-12 01:13:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by saxopa on 2026-10-12T01:13:51Z.


What

Homebrew built with the OpenOrbis PS4 toolchain stops in the relinker on current main (7a84b222). The OpenOrbis graphics sample (toolchain v0.5.4, samples/graphics), relinked with --skip-sce-module:

FAIL: RELATIVE relocation has a nonzero symbol index (offset 0x1d0b80)

Cause: when create-fself copies .rela.dyn, it adds one to every symbol index (OELFGenDynlibData.go#L818). lld writes all 2998 RELATIVE entries of the sample with symbol 0, and create-fself turns them into symbol 1, a local STT_SECTION symbol with value 0. FreeBSD rtld computes RELATIVE as relocbase + r_addend and never reads the symbol (amd64/reloc.c#L381-L383).

The three readers that checked the index now accept index 0, or an in-range STT_SECTION symbol with value 0. Any other symbol still throws, with the same messages.

  • RelinkerPipeline: import scan, and the output RELATIVE table. That table used to skip RELATIVE entries with a nonzero index without an error. It now writes them with index 0.
  • CodeInstructionCollector (Windows and macOS code analysis).
  • StrictNidFilter (unused-filter=2).

This is one item of #3093 ("R_X86_64_RELATIVE with symbol index 1"). With it, the sample converts to Linux with the default options and with --to-intel. --windows, --macos and unused-filter=1 stop at the next item of #3093, PT_SCE_RELRO. The PLTGOT at 0x130000 sits in that segment:

FAIL: ELF address is not contained in PT_LOAD memory (offset 0x130000)

unused-filter=2 gets past the relocations and stops later with Strict filter: direct branch leaves code (offset 0xe40d3), which is out of scope here.

Tested

macOS 27 (Apple Silicon), relinker-only Release build.

  • ctest: 115/115.
  • New cases:
    • none_relocations: a symbol-1 RELATIVE entry against a zero-value section symbol, both layouts (standard and SCE tables), Linux, Windows and macOS output, unused-filter=0/1. The Linux output holds (0x300, 8, 0x210). A STT_NOTYPE symbol and a section symbol with value 0x10 are still rejected.
    • strict_nid_filter: the same rule on the SCE dynlibdata fixture, plus an index outside the symbol table.
  • Each new case fails on main. Reverting any one of the three source files fails a test, and so does keeping the old drop in the output RELATIVE table.
  • OpenOrbis graphics sample: built locally with Apple clang, ld.lld and create-fself built from source at the commit above. Conversion results are listed above. Not run: no x86-64 Linux host here.
  • python3 tools/check_conventions.py --base origin/main passes; git diff --check is clean.

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 in TechnicalDebt — none added
  • 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 — none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823775914 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4203). Originally posted by [saxopa](https://github.com/saxopa) on 2026-10-12T01:13:51Z. --- ### What Homebrew built with the OpenOrbis PS4 toolchain stops in the relinker on current `main` (7a84b222). The OpenOrbis `graphics` sample (toolchain v0.5.4, `samples/graphics`), relinked with `--skip-sce-module`: ``` FAIL: RELATIVE relocation has a nonzero symbol index (offset 0x1d0b80) ``` Cause: when create-fself copies `.rela.dyn`, it adds one to every symbol index ([`OELFGenDynlibData.go#L818`](https://github.com/OpenOrbis/create-fself/blob/f2da6229684ce320f673c06fceac9c218f621788/pkg/oelf/OELFGenDynlibData.go#L818)). lld writes all 2998 RELATIVE entries of the sample with symbol 0, and create-fself turns them into symbol 1, a local `STT_SECTION` symbol with value 0. FreeBSD rtld computes RELATIVE as `relocbase + r_addend` and never reads the symbol ([`amd64/reloc.c#L381-L383`](https://github.com/freebsd/freebsd-src/blob/5180fce1cf7ec7430ccf2adb88358602e5ccee1e/libexec/rtld-elf/amd64/reloc.c#L381-L383)). The three readers that checked the index now accept index 0, or an in-range `STT_SECTION` symbol with value 0. Any other symbol still throws, with the same messages. - `RelinkerPipeline`: import scan, and the output RELATIVE table. That table used to skip RELATIVE entries with a nonzero index without an error. It now writes them with index 0. - `CodeInstructionCollector` (Windows and macOS code analysis). - `StrictNidFilter` (`unused-filter=2`). This is one item of #3093 ("R_X86_64_RELATIVE with symbol index 1"). With it, the sample converts to Linux with the default options and with `--to-intel`. `--windows`, `--macos` and `unused-filter=1` stop at the next item of #3093, `PT_SCE_RELRO`. The PLTGOT at 0x130000 sits in that segment: ``` FAIL: ELF address is not contained in PT_LOAD memory (offset 0x130000) ``` `unused-filter=2` gets past the relocations and stops later with `Strict filter: direct branch leaves code (offset 0xe40d3)`, which is out of scope here. ### Tested macOS 27 (Apple Silicon), relinker-only Release build. - ctest: 115/115. - New cases: - `none_relocations`: a symbol-1 RELATIVE entry against a zero-value section symbol, both layouts (standard and SCE tables), Linux, Windows and macOS output, `unused-filter=0/1`. The Linux output holds `(0x300, 8, 0x210)`. A `STT_NOTYPE` symbol and a section symbol with value 0x10 are still rejected. - `strict_nid_filter`: the same rule on the SCE dynlibdata fixture, plus an index outside the symbol table. - Each new case fails on `main`. Reverting any one of the three source files fails a test, and so does keeping the old drop in the output RELATIVE table. - OpenOrbis `graphics` sample: built locally with Apple clang, ld.lld and create-fself built from source at the commit above. Conversion results are listed above. Not run: no x86-64 Linux host here. - `python3 tools/check_conventions.py --base origin/main` passes; `git diff --check` is clean. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) — none added - [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 — none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code)
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!4203
No description provided.