fix(relinker): resolve relocations against null symbol entries to 0 #4452

Merged
orishamir merged 1 commit from upstream-pr/4452 into main 2026-10-12 18:26:14 +00:00
orishamir commented 2026-10-12 12:08:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-12T12:08:27Z.


What

A relocation whose dynamic symbol entry is all zero, the same bytes as the null symbol, now takes the value 0 plus its addend, as the gABI defines for STN_UNDEF. Until now the relinker turned such a reference into an import with an empty name:

  • Windows and macOS: the relink fails with Empty import symbol name.
  • Linux: the relink succeeds, and the host loader then stops at symbol lookup error: ./app.elf: undefined symbol: with an empty name.

With this change:

  • RelinkerPipeline accepts an unnamed symbol only when its whole entry is zero, and leaves such references out of the call registry. Any other unnamed entry fails the relink with Unnamed import symbol is not a null symbol entry.
  • SysVDynamicSectionBuilder imports it as an unnamed weak symbol (STB_WEAK, STT_NOTYPE), which the Linux loader resolves to 0.
  • WindowsRelocationBuilder, which builds the imports of Windows and macOS executables, writes the value into the slot and adds no import.
  • TechnicalDebt records that what the console's loader does with such an entry is not measured.

Title. OliSe Player (PPSA01153, catalog 02.001.000, GPL-3.0) has seven such relocations: six GLOB_DAT and one JUMP_SLOT against the all-zero entries 247 and 326 to 330 (#4437). Its code uses them as weak references. It reads 0x18c5bb8 at 16 places, each a compare with 0 that skips the call through the PLT stub of 0x18c60c8 when the slot is 0. Each of the other five slots has a wrapper that jumps through it when it is not 0 and otherwise returns 0 or -1. The title is built with the ps5-payload-dev SDK, so it relinks only with --trap-sdk-syscall-stubs (#3804).

On main 3d8ffeb2:

  • Windows 11, RTX 4080: FAIL: Empty import symbol name (offset 0x18c5bb8)
  • Linux (Ubuntu 24.04 container): ./app.elf: symbol lookup error: ./app.elf: undefined symbol:

With this change merged onto that main, both get past these slots and stop at the next absent import, XU4yLKvcDh0 (__divti3, open in #4037):

  • Windows: FAIL: unresolved ELF import XU4yLKvcDh0 from libSceLibcInternal.prx
  • Linux: ./app.elf: symbol lookup error: ./app.elf: undefined symbol: XU4yLKvcDh0

tools/import_audit.py then lists statvfs and fdopendir as its other two absent imports.

Fixes #4437.

Tested

  • New test null_symbol_relocations. A fixture has a GLOB_DAT and an R_X86_64_64 (addend 0x1234) against an all-zero symbol entry. It relinks for Linux, Windows and macOS at unused-filter=0 and =1, each with an empty registry. The Linux output imports both as unnamed weak symbols. On Windows the executable reads 0 and 0x1234 from the slots and returns 42. An unnamed entry that is not all zero fails the relink on all three targets.
  • Revert-pin, one file at a time. With WindowsRelocationBuilder.cpp reverted the Windows relink fails. With SysVDynamicSectionBuilder.cpp reverted the Linux symbols are GLOBAL FUNC. With RelinkerPipeline.cpp reverted the registry lists two empty NIDs.
  • Relinker suite. Relinker-only Release builds with BUILD_TESTING=ON:
    • Linux (Ubuntu 26.04, GCC 15.2.0): 130/130.
    • Windows 11 (WinLibs GCC 15.2.0 r7): 125/125, on main 3d8ffeb2 with this commit; the new test runs its Windows executable there.
  • Whole homebrew catalog. The 58 catalog titles that download and unpack today were relinked for Linux, Windows and macOS with --trap-sdk-syscall-stubs, by the relinker of main 029c1bc1 with and without this change. 171 of the 174 outputs are byte-identical, registries included. The 3 that differ are OliSe Player's: its Linux output, and its Windows and macOS relinks, which now succeed.
  • tools/check_conventions.py --base origin/main passes, and tools/pr_overlap.py --branch reports no overlap.

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
  • 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: PPSA01153
  • AI-assisted: yes (Claude Code Opus 5.5 xhigh)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4829172693 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4452). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-12T12:08:27Z. --- ### What A relocation whose dynamic symbol entry is all zero, the same bytes as the null symbol, now takes the value 0 plus its addend, as the gABI defines for `STN_UNDEF`. Until now the relinker turned such a reference into an import with an empty name: - Windows and macOS: the relink fails with `Empty import symbol name`. - Linux: the relink succeeds, and the host loader then stops at `symbol lookup error: ./app.elf: undefined symbol:` with an empty name. With this change: - `RelinkerPipeline` accepts an unnamed symbol only when its whole entry is zero, and leaves such references out of the call registry. Any other unnamed entry fails the relink with `Unnamed import symbol is not a null symbol entry`. - `SysVDynamicSectionBuilder` imports it as an unnamed weak symbol (`STB_WEAK`, `STT_NOTYPE`), which the Linux loader resolves to 0. - `WindowsRelocationBuilder`, which builds the imports of Windows and macOS executables, writes the value into the slot and adds no import. - TechnicalDebt records that what the console's loader does with such an entry is not measured. **Title.** OliSe Player (PPSA01153, catalog 02.001.000, GPL-3.0) has seven such relocations: six `GLOB_DAT` and one `JUMP_SLOT` against the all-zero entries 247 and 326 to 330 (#4437). Its code uses them as weak references. It reads 0x18c5bb8 at 16 places, each a compare with 0 that skips the call through the PLT stub of 0x18c60c8 when the slot is 0. Each of the other five slots has a wrapper that jumps through it when it is not 0 and otherwise returns 0 or -1. The title is built with the ps5-payload-dev SDK, so it relinks only with `--trap-sdk-syscall-stubs` (#3804). On `main` 3d8ffeb2: - Windows 11, RTX 4080: `FAIL: Empty import symbol name (offset 0x18c5bb8)` - Linux (Ubuntu 24.04 container): `./app.elf: symbol lookup error: ./app.elf: undefined symbol:` With this change merged onto that `main`, both get past these slots and stop at the next absent import, `XU4yLKvcDh0` (`__divti3`, open in #4037): - Windows: `FAIL: unresolved ELF import XU4yLKvcDh0 from libSceLibcInternal.prx` - Linux: `./app.elf: symbol lookup error: ./app.elf: undefined symbol: XU4yLKvcDh0` `tools/import_audit.py` then lists `statvfs` and `fdopendir` as its other two absent imports. Fixes #4437. ### Tested - **New test `null_symbol_relocations`.** A fixture has a `GLOB_DAT` and an `R_X86_64_64` (addend 0x1234) against an all-zero symbol entry. It relinks for Linux, Windows and macOS at `unused-filter=0` and `=1`, each with an empty registry. The Linux output imports both as unnamed weak symbols. On Windows the executable reads 0 and 0x1234 from the slots and returns 42. An unnamed entry that is not all zero fails the relink on all three targets. - **Revert-pin, one file at a time.** With `WindowsRelocationBuilder.cpp` reverted the Windows relink fails. With `SysVDynamicSectionBuilder.cpp` reverted the Linux symbols are `GLOBAL FUNC`. With `RelinkerPipeline.cpp` reverted the registry lists two empty NIDs. - **Relinker suite.** Relinker-only Release builds with `BUILD_TESTING=ON`: - Linux (Ubuntu 26.04, GCC 15.2.0): 130/130. - Windows 11 (WinLibs GCC 15.2.0 r7): 125/125, on `main` 3d8ffeb2 with this commit; the new test runs its Windows executable there. - **Whole homebrew catalog.** The 58 catalog titles that download and unpack today were relinked for Linux, Windows and macOS with `--trap-sdk-syscall-stubs`, by the relinker of `main` 029c1bc1 with and without this change. 171 of the 174 outputs are byte-identical, registries included. The 3 that differ are OliSe Player's: its Linux output, and its Windows and macOS relinks, which now succeed. - `tools/check_conventions.py --base origin/main` passes, and `tools/pr_overlap.py --branch` reports no overlap. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) - [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: PPSA01153 - [x] AI-assisted: yes (Claude Code Opus 5.5 xhigh) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LeandroLP23 commented 2026-10-12 13:16:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T13:16:23Z.


Verified on Windows 11 (26300), AMD Radeon 860M, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, with head 1205d03da merged onto current main f8dee0595.

OliSe Player (PPSA01153, catalog 02.001.000), relinked with --windows --trap-sdk-syscall-stubs:

  • main: FAIL: Empty import symbol name (offset 0x18c5bb8), as in #4437.
  • With this PR, the relink succeeds. main now has __divti3 (#4037), so the run gets one step further than in the description and stops at FAIL: unresolved ELF import j+XjoRSIvwU from libSceLibcInternal.prx (fdopendir), exit 0xc0000139. No open PR adds fdopendir or statvfs yet.

Tests

  • ctest under core/relinker: 109/109.
  • null_symbol_relocations: 3/3.
  • Revert check, one file at a time against main: with WindowsRelocationBuilder.cpp, SysVDynamicSectionBuilder.cpp or RelinkerPipeline.cpp reverted, null_symbol_relocations fails each time.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125045390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4452#issuecomment-6125045390). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-12T13:16:23Z. --- Verified on Windows 11 (26300), AMD Radeon 860M, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, with head `1205d03da` merged onto current `main` `f8dee0595`. **OliSe Player** (PPSA01153, catalog 02.001.000), relinked with `--windows --trap-sdk-syscall-stubs`: - `main`: `FAIL: Empty import symbol name (offset 0x18c5bb8)`, as in #4437. - With this PR, the relink succeeds. `main` now has `__divti3` (#4037), so the run gets one step further than in the description and stops at `FAIL: unresolved ELF import j+XjoRSIvwU from libSceLibcInternal.prx` (`fdopendir`), exit `0xc0000139`. No open PR adds `fdopendir` or `statvfs` yet. **Tests** - `ctest` under `core/relinker`: 109/109. - `null_symbol_relocations`: 3/3. - Revert check, one file at a time against `main`: with `WindowsRelocationBuilder.cpp`, `SysVDynamicSectionBuilder.cpp` or `RelinkerPipeline.cpp` reverted, `null_symbol_relocations` fails each time. AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-12 14:12:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T14:12:35Z.


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
#4510 core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp L135-136, L146-147
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L260-261
#4602 core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp L0-1, L41-42
core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp L134-136, L145-147
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L260-261
#4624 core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp L135-136, L146-147
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L260-261
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126023912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4452#issuecomment-6126023912). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T14:12:35Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #4510 | `core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp` [L135-136](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp#L135-L136), [L146-147](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp#L146-L147)<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` [L260-261](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L260-L261) | | | | #4602 | `core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp` [L0-1](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp#L0-L1), [L41-42](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp#L41-L42)<br>`core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp` [L134-136](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp#L134-L136), [L145-147](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp#L145-L147)<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` [L260-261](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L260-L261) | | | | #4624 | `core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp` [L135-136](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp#L135-L136), [L146-147](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp#L146-L147)<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` [L260-261](https://github.com/boykopovar/AnyPS5/blob/bde332a59ce98ce8aa776b26a4ed04e53417946d/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L260-L261) | | |
overlordxrz-source commented 2026-10-12 17:45:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-12T17:45:53Z.


Tested on Linux (Ubuntu 24.04, lavapipe) with main 2a5eca11 + this PR + #4470, OliSe Player PPSA01153 with --trap-sdk-syscall-stubs.

  • Without this PR: the relink passes, then ./app.elf: symbol lookup error: ./app.elf: undefined symbol: (empty name). The input has the seven null-symbol relocations you describe (six GLOB_DAT, one JUMP_SLOT, at .got 0x18C5BB8 to 0x18C60C8).
  • With this PR: the empty-symbol error is gone, and the title now stops at: ./app.elf: symbol lookup error: ./app.elf: undefined symbol: j+XjoRSIvwU.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129532137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4452#issuecomment-6129532137). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-12T17:45:53Z. --- Tested on Linux (Ubuntu 24.04, lavapipe) with main 2a5eca11 + this PR + #4470, OliSe Player PPSA01153 with `--trap-sdk-syscall-stubs`. - Without this PR: the relink passes, then `./app.elf: symbol lookup error: ./app.elf: undefined symbol: ` (empty name). The input has the seven null-symbol relocations you describe (six GLOB_DAT, one JUMP_SLOT, at .got 0x18C5BB8 to 0x18C60C8). - With this PR: the empty-symbol error is gone, and the title now stops at: `./app.elf: symbol lookup error: ./app.elf: undefined symbol: j+XjoRSIvwU`. AI-assisted: yes
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!4452
No description provided.