Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
orishamir:fix/relinker-null-symbol-imports
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
orishamir:fix/relinker-null-symbol-imports

Conversation

@orishamir

@orishamir orishamir commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 3d8ffeb:

  • 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 3d8ffeb 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 029c1bc 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

A relocation whose dynamic symbol entry is all zero, like the null symbol,
now takes the value 0 plus its addend, as the gABI defines for STN_UNDEF.
The Linux output imports such an entry as an unnamed weak symbol, which the
host loader resolves to 0. The Windows and macOS outputs write the value
into the slot instead of failing with "Empty import symbol name". Such
references are left out of the call registry. An unnamed symbol entry that
is not all zero still fails the relink.

OliSe Player (PPSA01153) has seven of these entries and calls through the
slots only when they are not 0 (boykopovar#4437).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeandroLP23

Copy link
Copy Markdown
Contributor

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:

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

github-actions Bot commented Oct 12, 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
#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

@overlordxrz-source

Copy link
Copy Markdown
Contributor

Tested on Linux (Ubuntu 24.04, lavapipe) with main 2a5eca1 + 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 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.

Relinker (Windows): OliSe Player (PPSA01153) stops at 'Empty import symbol name' on seven weak references with all-zero symbol entries

4 participants