Skip to content

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

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
roboterspinne:fix/relinker-null-symbol-entry
Oct 27, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
roboterspinne:fix/relinker-null-symbol-entry

Conversation

@roboterspinne

@roboterspinne roboterspinne commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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 4017310, 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).

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 4017310 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 e05ba6f, which has no relinker changes since 4017310; 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 4017310 and with Dynamic symbol table entry 0 is not a null symbol entry (offset 0x620) with the change.
  • Merged current main (7b41552, which includes fix(relinker): reject out-of-range executable TLS symbols #11058) into the branch without conflicts (7c0b736; the earlier merges are 5b5d24c in 028e58a and 204c674 in b1e3b81); tools/check_main_sync.py --base upstream/main reported 0 behind and a clean merge at 7b41552, and the later merges on main up to 035ac96 touch no relinker file. On 7c0b736, 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 fix(relinker): reject out-of-range executable TLS symbols #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 7c0b736: 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 test(tools): compare quoted and resolved paths in the patch advisor test #10667 fixes); both failed again alone.
  • python tools/check_conventions.py --base upstream/main with this title and description passed on 7c0b736.
  • 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)

…l entry 0

A symbolic relocation with symbol index 0 read the name, binding and
type of dynamic symbol entry 0, so a named entry 0 turned STN_UNDEF
relocations into named imports on Linux, Windows and macOS. The ELF
gABI reserves index 0 as STN_UNDEF and requires its entry to be all
zero, and the guest reader already rejects such a table as "Invalid
null symbol". The relinker now fails with "Dynamic symbol table entry
0 is not a null symbol entry" when a symbolic relocation names index 0
and that entry has a nonzero byte; relocations against an all-zero
entry 0 are unchanged.

@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.

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

Copy link
Copy Markdown
Contributor

CI follow-up to my exact-head review of b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d: the pending Windows and macOS relinker jobs have now completed successfully. Ubuntu, Windows, macOS arm64, macOS x86_64, relinker ASan, eligibility, conventions, intake and labels are all green. Register-context, write-watch and product builds remain skipped by path policy. This closes the CI-pending note in my approval; it does not change the stated local-test scope.

@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 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.

@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Synced with current main by merging it into the branch rather than rebasing, so the reviewed commit 96470f0 and the approved head b1e3b81 stay in the history: 028e58a merges main 5b5d24c, and tools/check_main_sync.py --base upstream/main reports 3 ahead, 0 behind and a clean merge. The change itself is unchanged, and none of the three relinker files main changed since 204c674 (Amd64OnlyConverterTests.cpp, SectionHeaderTableBuilder.cpp, SectionRangeTests.cpp) is touched by this PR. On 028e58a I rebuilt relinker-only and reran the focused selection ctest -R 'null_symbol|symbol|import|weak_imports|executable_export': 20/20 passed; the full suite passed 304 of 307 tests, with long_paths skipped and the same two known local failures as on main. The Tested section now names 028e58a.

@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.

Re-reviewed exact head 028e58a. The branch includes main at 5b5d24c; 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.

@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Since your approval, main merged #11058, which changes definedTlsSymbolValue in RelinkerPipeline.cpp. To keep the branch current I merged main 7b41552 into it (7c0b736, no conflicts); the change itself is unchanged. The two checks do not interact: definedTlsSymbolValue is reached only behind symIdx != 0 in extractRela and in the TLS pass, so symbolEntryPos(0) is never called from the TLS path, and the #11058 check and the entry-0 check cannot fire for the same relocation. On 7c0b736 the focused selection plus executable_tls_relocations passed 22/22 and the full suite 306 of 309, with the same skip and known local failures as on main; the Tested section now names 7c0b736, and the hosted relinker matrix runs on it. A re-review on this head is welcome if you want the approval to name it.

@oneandonlydean oneandonlydean self-assigned this Oct 26, 2026
@github-actions

Copy link
Copy Markdown

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 10861 core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp

@oneandonlydean
oneandonlydean merged commit 06e4e46 into boykopovar:main Oct 27, 2026
14 checks passed
@roboterspinne
roboterspinne deleted the fix/relinker-null-symbol-entry branch October 27, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants