fix(relinker): preserve imports with an empty GNU hash #25672
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25672"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mcarkade on 2026-11-22T14:14:27Z.
What
GNU ld 2.42 with
-shared --hash-style=gnu -swrites an empty GNU hash for a plugin with no exports, even when.dynsymcontains an import. Relinking a bundled plugin built this way stops at its first import relocation withUnsupported relocation or symbol index.When every GNU hash bucket is empty, the guest module reader, code scanner, and strict NID filter use the same helper to count symbols from the matching
.dynsymsection. Without section headers, the count still falls back tosymoffset. A malformed section table is rejected.Tested
Windows 11, MinGW 15.2, Python 3.13.5, CMake/CTest 4.3.1.
guest_gnu_hash_import_onlyfails on main and passes with the fix. It checks the converted Linux relocation and provider dependency, and runs the Windows output. The extendedstrict_nid_filtercase fails on the previous PR head because the filter drops a reachable import. It passes with the fix and also checks that a truncated section table is rejected. The conventions check passed. Of 20 focused relinker CTests, 19 passed.reloc_table_boundsfailed with the same writable-segment error on the previous PR head.A stripped plugin built with GNU ld 2.42 reproduced the failure on main. With the fix, it converted for Linux and Windows, and the Linux loader resolved the import under WSL. The Linux startup probe under WSL and the Windows output each returned 42. macOS runtime was unchecked.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by throny on 2026-11-22T14:33:31Z.
Review: COMMENTED
Review: ⚠️ fixes the reported case; a third copy of the same logic is left
Basis: code read; the new
import-onlytest run againstmain'srelinker.exe(fails withconsumer.prx: Unsupported relocation or symbol index); this PR not built hereChecked
main,GuestImageReader.cppandCodeInstructionCollector.cppfall back tosymoffsetas the symbol count when every GNU hash bucket is 0, so an import at index >=symoffsetis dropped. Using theSHT_DYNSYMsection size in that case is the only source left; the non-empty-hash, SysV and SCE paths are unchanged.Findings
StrictNidFilter.cpp:158-179has a third copy of the same counting (count = firstSymbolwhenlastBucket == 0) that isn't updated, so with the strict filter a main executable with an empty GNU hash would still undercount imports while the other two readers now see them. A shared helper would keep the three in step.symoffsetand drops imports, silently; worth a line indocs/dev/debt.ReadDynamicSymbolCountnow parses the section header table, so a module with an empty GNU hash and a junk or truncated section table throws where it used to convert. Probably right, but it's new behaviour.Suggested action: apply the same count to
StrictNidFilter(or share it) and record the no-section-header gap; then merge.AI-assisted review (Claude Code) · head
e4dd269b58· basemain337a948bf1Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T14:39:27Z.
Review: APPROVED
Reviewed — looks good
The change adds a section-header fallback for counting dynamic symbols when GNU hash buckets are empty; the inspected implementation and regression fixture support the stated import-only case.
What I ran
No build or tests were run. I read the prepared diff and changed files at head
e4dd269b586084032a4540f2276f04c1d45f4a04usingrepo_read.py.Results
Findings
Blocking
None in the code reviewed.
Non-blocking
None.
Not verified
The build, CTests, conventions check, and reported Windows, WSL/Linux, and macOS behavior were not independently verified.
core/relinker/CMakeLists.txt,core/relinker/relinker/include/relinker/parsing/ElfReader.hpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp,core/relinker/relinker/src/guest/GuestImageReader.cpp,core/relinker/relinker/src/parsing/ElfReader.cpp, andcore/relinker/relinker/tests/test_guest_gnu_hash.pywere read. No changed files were excluded in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T14:50:27Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
dbccaacaa1:tools/check_conventions.pypassed.strict_nid_filter_testsbuilt cleanly.strict_nid_filter):core/relinker/relinker/include/relinker/parsing/ElfReader.hpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp,core/relinker/relinker/src/analysis/UnusedNidFilter/StrictNidFilter.cpp,core/relinker/relinker/src/guest/GuestImageReader.cpp,core/relinker/relinker/src/parsing/ElfReader.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by throny on 2026-11-22T15:05:28Z.
Review: APPROVED
Review: ✅ all three readers now count imports the same way; I'd merge it
Basis: code read of
dbccaacaa1(not built here)Checked
ElfReader::ReadDynamicSymbolCount(ElfReader.cpp:290) takes the size of theSHT_DYNSYMsection at theDT_SYMTABfile offset. It throws if the size isn't a multiple of 24 or is belowsymoffset, and falls back tosymoffsetwhen there is no such section.GuestImageReader,CodeInstructionCollectorandStrictNidFilter(line 192) all call it on the empty-bucket path, so my finding 1 is fixed. The non-empty-hash, SysV andDT_SCEpaths are unchanged.fix-relinker-gnu-hash-import-only.md(finding 2). Keeping the error for a malformed table (finding 3) is the author's call, and it's reasonable.Findings
none. The author reports that
reloc_table_boundsalso fails on the previous head; therelinker (windows-latest)CI job is still running and will show whether it fails onmaintoo.Suggested action: merge
AI-assisted review (Claude Code) · head
dbccaacaa1· basemain337a948bf1Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T16:41:12Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review found no verified blocking defect, and the author-reported tests are not treated as tests run here.
What I ran
Reviewed head
dbccaacaa1ccd34c0657e1d6008abf10660045d5. No test or build commands were run; repository reading was limited to the supplied diff and targeted file ranges usingrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The PR description reports 19 of 20 focused relinker CTests passed, with
reloc_table_boundsfailing on both this head and the previous PR head. Those runs were not independently verified. No build, test, Windows runtime, WSL runtime, or macOS runtime checks were run during this review. Read all files listed as reviewed inmanifest.json; no files were excluded in the supplied manifest.To get this to a good state
Nothing is required.