fix(relinker): reject relocations against a non-null executable symbol entry 0 #11367

Merged
roboterspinne merged 4 commits from upstream-pr/11367 into main 2026-10-27 08:23:51 +00:00
roboterspinne commented 2026-10-26 08:58:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-26T08:58:07Z.


What

A symbolic relocation in the executable with symbol index 0 read the name, binding and type of dynamic symbol entry 0 like any import. On untouched 4017310678, an input whose R_X86_64_GLOB_DAT and R_X86_64_64 relocations name index 0 while entry 0 is (st_name "foo", st_info 0x12) converted with exit 0 for Linux, --windows and --macos: the Linux output imports foo as a global function for both slots, and the Windows program exits 0xC0000139 with FAIL: unresolved ELF import foo. The ELF gABI reserves index 0 as STN_UNDEF and requires its entry to be all zero; the guest reader already rejects an entry 0 with a name or any nonzero field in modules (Invalid null symbol, GuestImageReader.cpp:184).

  • Rule. symbolEntryPos in RelinkerPipeline.cpp throws Dynamic symbol table entry 0 is not a null symbol entry at the entry's file offset, after its bounds check, when symIdx is 0 and any of the entry's 24 bytes is nonzero; the CLI exits 2 and writes no output. Only extractRela asks for index 0: the RELATIVE, defined-TLS and TLS-pass paths skip index 0, and the export loop starts at entry 1, so the check fires only for a symbolic relocation against index 0, and a dynamic symbol table that aliases other data without such a relocation is unaffected. Relocations against an all-zero entry 0 keep the STN_UNDEF meaning from docs/dev/debt/relinker.md (value 0 plus addend); linkers emit an all-zero entry 0, and the relocations of OliSe Player (PPSA01153) point at all-zero entries. An unnamed nonzero entry 0 now reports this message instead of Unnamed import symbol is not a null symbol entry; that message still covers other indices. #11382 rejects a dynamic string table that does not begin with NUL.
  • Tests. test_null_symbol_relocations.py gets a case built from image_with(index=0) with string table \0foo\0libfoo.prx\0, DT_NEEDED libfoo.prx and entry 0 (1, 0x12, 0, 0, 0, 0); Linux, --windows and --macos must exit 2 with the message and no output. The existing all-zero index-0 and index-1 cases (exit 42 on Windows) and the unnamed index-1 case are unchanged.
  • Overlap. pr_overlap.py reports no shared lines with open pull requests that merge with main. It cannot compare this branch with #10792 and #10861, which also change RelinkerPipeline.cpp, because they do not merge with main. Checked by hand against main 7b415520b6: #10792 adds FindPathconfImport after line 25 and changes the syscall patch loop (lines 431 to 437); #10861 changes the unwind block that #8076 rewrote on main (the hasEhFrame block, lines 403 to 416), adds a tail scan after line 439 and SyscallContinuations after line 632. None of this is near symbolEntryPos (line 305), where this PR adds lines 311 to 313. Trial merges of this branch with each of them conflict in the same files and regions as main does (GuestModuleBuilder.cpp for #10792; GuestModuleBuilder.cpp, the hasEhFrame block of RelinkerPipeline.cpp and docs/dev/debt/relinker.md for #10861), and apart from the conflict marker labels the merged trees differ from those of main only by the lines of this PR. #10861 treats every relocation against index 0 as a null symbol relocation in CodeInstructionCollector.cpp; for the executable that code runs only after extractRela, so with this PR it never sees a non-null entry 0. The fixtures of both pull requests keep entry 0 all zero.

Tested

Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.

  • Counter-check: null_symbol_relocations with the new case on untouched 4017310678 fails with AssertionError: ('linux', 0, ''); run per target, the assertions are ('linux', 0, ''), ('windows', 0, '') and ('macos', 0, ''), after the existing cases passed. The untouched Windows output ran and exited 0xC0000139 with FAIL: unresolved ELF import foo. Rebased onto e05ba6feeb, which has no relinker changes since 4017310678; with the change it passed there in 1.6 s.
  • Probe: an unnamed entry 0 with st_info 0x12 and relocations against index 0 failed on all three targets with Unnamed import symbol is not a null symbol entry (offset 0x620) on untouched 4017310678 and with Dynamic symbol table entry 0 is not a null symbol entry (offset 0x620) with the change.
  • Merged current main (7b415520b6, which includes #11058) into the branch without conflicts (7c0b736c68; the earlier merges are 5b5d24cb22 in 028e58a18f and 204c6747d0 in b1e3b814fb); tools/check_main_sync.py --base upstream/main reported 0 behind and a clean merge at 7b415520b6, and the later merges on main up to 035ac96edd touch no relinker file. On 7c0b736c68, ctest -R 'null_symbol|symbol|import|weak_imports|executable_export|executable_tls_relocations' -j 6: 22 tests passed: null_symbol_relocations (1.1 s), executable_tls_relocations (extended by #11058), macos_trace_imports, import_audit, import_symbol_types, windows_import_modules, executable_export_bounds, guest_relative_section_symbols, guest_unused_import_dependencies, guest_absolute_symbols, guest_symbol_names, windows_trace_imports, linux_trace_imports, windows_named_imports, linux_named_imports, linux_guest_named_imports, symbolize_samples, macos_executable_exports, linux_executable_exports, weak_imports, windows_guest_weak_imports, macos_guest_weak_imports.
  • Full suite on 7c0b736c68: ctest --test-dir build-relinker -j 6: 309 tests, 306 passed, long_paths skipped; failures known on this machine on main as well: select_tests (Windows symlink fixture) and patch_advisor_unit (path with spaces, which open #10667 fixes); both failed again alone.
  • python tools/check_conventions.py --base upstream/main with this title and description passed on 7c0b736c68.
  • Not tested on Linux or macOS; CI runs the tests on all three hosts.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5014721165 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11367). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-26T08:58:07Z. --- ### What A symbolic relocation in the executable with symbol index 0 read the name, binding and type of dynamic symbol entry 0 like any import. On untouched 4017310678, an input whose `R_X86_64_GLOB_DAT` and `R_X86_64_64` relocations name index 0 while entry 0 is `(st_name "foo", st_info 0x12)` converted with exit 0 for Linux, `--windows` and `--macos`: the Linux output imports `foo` as a global function for both slots, and the Windows program exits 0xC0000139 with `FAIL: unresolved ELF import foo`. The ELF gABI reserves index 0 as `STN_UNDEF` and requires its entry to be all zero; the guest reader already rejects an entry 0 with a name or any nonzero field in modules (`Invalid null symbol`, `GuestImageReader.cpp:184`). - **Rule.** `symbolEntryPos` in `RelinkerPipeline.cpp` throws `Dynamic symbol table entry 0 is not a null symbol entry` at the entry's file offset, after its bounds check, when `symIdx` is 0 and any of the entry's 24 bytes is nonzero; the CLI exits 2 and writes no output. Only `extractRela` asks for index 0: the `RELATIVE`, defined-TLS and TLS-pass paths skip index 0, and the export loop starts at entry 1, so the check fires only for a symbolic relocation against index 0, and a dynamic symbol table that aliases other data without such a relocation is unaffected. Relocations against an all-zero entry 0 keep the `STN_UNDEF` meaning from `docs/dev/debt/relinker.md` (value 0 plus addend); linkers emit an all-zero entry 0, and the relocations of OliSe Player (PPSA01153) point at all-zero entries. An unnamed nonzero entry 0 now reports this message instead of `Unnamed import symbol is not a null symbol entry`; that message still covers other indices. #11382 rejects a dynamic string table that does not begin with NUL. - **Tests.** `test_null_symbol_relocations.py` gets a case built from `image_with(index=0)` with string table `\0foo\0libfoo.prx\0`, `DT_NEEDED` `libfoo.prx` and entry 0 `(1, 0x12, 0, 0, 0, 0)`; Linux, `--windows` and `--macos` must exit 2 with the message and no output. The existing all-zero index-0 and index-1 cases (exit 42 on Windows) and the unnamed index-1 case are unchanged. - **Overlap.** `pr_overlap.py` reports no shared lines with open pull requests that merge with `main`. It cannot compare this branch with #10792 and #10861, which also change `RelinkerPipeline.cpp`, because they do not merge with `main`. Checked by hand against `main` 7b415520b6: #10792 adds `FindPathconfImport` after line 25 and changes the syscall patch loop (lines 431 to 437); #10861 changes the unwind block that #8076 rewrote on `main` (the `hasEhFrame` block, lines 403 to 416), adds a tail scan after line 439 and `SyscallContinuations` after line 632. None of this is near `symbolEntryPos` (line 305), where this PR adds lines 311 to 313. Trial merges of this branch with each of them conflict in the same files and regions as `main` does (`GuestModuleBuilder.cpp` for #10792; `GuestModuleBuilder.cpp`, the `hasEhFrame` block of `RelinkerPipeline.cpp` and `docs/dev/debt/relinker.md` for #10861), and apart from the conflict marker labels the merged trees differ from those of `main` only by the lines of this PR. #10861 treats every relocation against index 0 as a null symbol relocation in `CodeInstructionCollector.cpp`; for the executable that code runs only after `extractRela`, so with this PR it never sees a non-null entry 0. The fixtures of both pull requests keep entry 0 all zero. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew. - Counter-check: `null_symbol_relocations` with the new case on untouched 4017310678 fails with `AssertionError: ('linux', 0, '')`; run per target, the assertions are `('linux', 0, '')`, `('windows', 0, '')` and `('macos', 0, '')`, after the existing cases passed. The untouched Windows output ran and exited 0xC0000139 with `FAIL: unresolved ELF import foo`. Rebased onto e05ba6feeb, which has no relinker changes since 4017310678; with the change it passed there in 1.6 s. - Probe: an unnamed entry 0 with `st_info` 0x12 and relocations against index 0 failed on all three targets with `Unnamed import symbol is not a null symbol entry (offset 0x620)` on untouched 4017310678 and with `Dynamic symbol table entry 0 is not a null symbol entry (offset 0x620)` with the change. - Merged current `main` (7b415520b6, which includes #11058) into the branch without conflicts (7c0b736c68; the earlier merges are 5b5d24cb22 in 028e58a18f and 204c6747d0 in b1e3b814fb); `tools/check_main_sync.py --base upstream/main` reported 0 behind and a clean merge at 7b415520b6, and the later merges on `main` up to 035ac96edd touch no relinker file. On 7c0b736c68, `ctest -R 'null_symbol|symbol|import|weak_imports|executable_export|executable_tls_relocations' -j 6`: 22 tests passed: `null_symbol_relocations` (1.1 s), `executable_tls_relocations` (extended by #11058), `macos_trace_imports`, `import_audit`, `import_symbol_types`, `windows_import_modules`, `executable_export_bounds`, `guest_relative_section_symbols`, `guest_unused_import_dependencies`, `guest_absolute_symbols`, `guest_symbol_names`, `windows_trace_imports`, `linux_trace_imports`, `windows_named_imports`, `linux_named_imports`, `linux_guest_named_imports`, `symbolize_samples`, `macos_executable_exports`, `linux_executable_exports`, `weak_imports`, `windows_guest_weak_imports`, `macos_guest_weak_imports`. - Full suite on 7c0b736c68: `ctest --test-dir build-relinker -j 6`: 309 tests, 306 passed, `long_paths` skipped; failures known on this machine on `main` as well: `select_tests` (Windows symlink fixture) and `patch_advisor_unit` (path with spaces, which open #10667 fixes); both failed again alone. - `python tools/check_conventions.py --base upstream/main` with this title and description passed on 7c0b736c68. - Not tested on Linux or macOS; CI runs the tests on all three hosts. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-26 09:01:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:01:07Z.

Review: APPROVED


Reviewed exact head b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d against current main. The current branch includes its merge base; neither touched path has changed on main since that base.

The guard is placed after the existing symbol-entry bounds validation and rejects symbol index 0 only when a symbolic relocation reads a nonzero entry. The RELATIVE path and the existing TLS index-zero handling remain unaffected. The regression fixture exercises a named, nonzero entry 0 across Linux, Windows, and macOS output modes, while retaining the existing all-zero null-entry coverage. I found no blocking issue in the code or test.

Independent Linux relinker-only Release build with GCC 12.2 succeeded. The focused null-symbol test passed, and the 20-test symbol/import/export selection passed 20/20 after building its required guest_module_args_host fixture target. Current-main conventions and git diff --check passed. Hosted relinker/ASan jobs are still running; Linux and Windows product jobs are skipped by path policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5649570155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11367#pullrequestreview-5649570155). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T09:01:07Z. **Review:** APPROVED --- Reviewed exact head `b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d` against current `main`. The current branch includes its merge base; neither touched path has changed on `main` since that base. The guard is placed after the existing symbol-entry bounds validation and rejects symbol index 0 only when a symbolic relocation reads a nonzero entry. The `RELATIVE` path and the existing TLS index-zero handling remain unaffected. The regression fixture exercises a named, nonzero entry 0 across Linux, Windows, and macOS output modes, while retaining the existing all-zero null-entry coverage. I found no blocking issue in the code or test. Independent Linux relinker-only Release build with GCC 12.2 succeeded. The focused null-symbol test passed, and the 20-test symbol/import/export selection passed 20/20 after building its required `guest_module_args_host` fixture target. Current-main conventions and `git diff --check` passed. Hosted relinker/ASan jobs are still running; Linux and Windows product jobs are skipped by path policy.
MarcZX10 commented 2026-10-26 10:03:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:03:28Z.

Review: CHANGES_REQUESTED


The reviewed relinker change remains unchanged at b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d, but its base is now 118 commits behind current main 5b5d24cb22. The merge preview is clean and main has not changed the two PR paths since the merge base; current conventions and diff checks pass. The contribution checklist requires branches based on current main. Please rebase and rerun the focused symbol-table tests on the resulting head before approval; the existing hosted relinker matrix passed on the older head, and the latest base should be represented in that validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5650266160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11367#pullrequestreview-5650266160). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T10:03:28Z. **Review:** CHANGES_REQUESTED --- The reviewed relinker change remains unchanged at `b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d`, but its base is now 118 commits behind current `main` `5b5d24cb22`. The merge preview is clean and main has not changed the two PR paths since the merge base; current conventions and diff checks pass. The contribution checklist requires branches based on current `main`. Please rebase and rerun the focused symbol-table tests on the resulting head before approval; the existing hosted relinker matrix passed on the older head, and the latest base should be represented in that validation.
MarcZX10 commented 2026-10-26 10:50:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:50:32Z.

Review: APPROVED


Re-reviewed exact head 028e58a18f. The branch includes main at 5b5d24cb; current main has advanced since then, but the intervening changes do not touch this PR's two changed paths, and the current-main merge preview is clean. The author reports 20/20 focused symbol/import/export tests passing on this exact head, with all hosted relinker, ASan, eligibility, conventions, intake, and labels checks green. The symbol-index guard remains after bounds validation and leaves RELATIVE and TLS index-zero handling intact. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5650859104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11367#pullrequestreview-5650859104). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T10:50:32Z. **Review:** APPROVED --- Re-reviewed exact head 028e58a18f0dd5462de3e9415a4ac7696fd0aec9. The branch includes main at 5b5d24cb; current main has advanced since then, but the intervening changes do not touch this PR's two changed paths, and the current-main merge preview is clean. The author reports 20/20 focused symbol/import/export tests passing on this exact head, with all hosted relinker, ASan, eligibility, conventions, intake, and labels checks green. The symbol-index guard remains after bounds validation and leaves RELATIVE and TLS index-zero handling intact. No blocking issue found.
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!11367
No description provided.