fix(relinker): preserve imported ELF symbol types #8899

Closed
SteelCrab wants to merge 1 commit from upstream-pr/8899 into main
SteelCrab commented 2026-10-21 05:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SteelCrab on 2026-10-21T05:05:43Z.


What

Superseded by #10017, which carries the reviewed symbol-type correction on current main. This closed PR retains the earlier review snapshot; use #10017 for the active diff, current test results and CI.

Carry the original ELF symbol-type nibble through parsing in NidReference::SymbolType, then use it when writing named imports to the SysV dynamic symbol table. STT_NOTYPE, STT_OBJECT and STT_FUNC remain distinct; non-function imports are no longer all converted to objects. Existing TLS relocation handling and weak/global binding remain in place.

Addresses the STT_NOTYPE review. The regression covers all 16 type values with both weak/global binding and GLOB_DAT/JUMP_SLOT relocations.

The relinker prerequisite of #6879 is now tracked in #10017.

Historical tested source: earlier branch diff. GitHub rejected reopening this PR after the branch history changed, so #10017 replaces it.

Tested

Ubuntu 26.04.1 x86-64, GCC 15.2, Release. Rebased onto main a6646f8464140180351e4c08694dccdd55b2814d; tested head 15366612f433497db718d701a313136448b1f8fd.

  • Negative control: the preceding PR implementation fails the new STT_NOTYPE assertion, emitting type 1 (STT_OBJECT) for input type 0.
  • Relinker-only configure (ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON), build and full CTest: 240/240 passed.
  • Focused ctest -R '^import_symbol_types$' -V: 1/1 passed, exercising 64 conversion fixtures (16 types × 2 bindings × 2 relocation kinds).
  • python3 tools/check_conventions.py --base origin/main and the complete PR-template check passed locally. Merge check against the tested main is clean.
  • Overlap scan completed. #6879 carries the intended temporary copy; other shared files are reported for PRs that conflict with main. #8076 changes unwind/data-table scanning rather than import-symbol parsing.

CI coverage: Build / relinker runs this regression and the complete relinker suite on Linux, Windows and macOS. A maintainer-triggered Build run is required for this contributor. No remote native matrix result is claimed for this head; Windows and macOS were not run locally.

This PR remains closed and is superseded by #10017. The results above are historical local results for the explicitly listed commit.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946686858 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8899). Originally posted by [SteelCrab](https://github.com/SteelCrab) on 2026-10-21T05:05:43Z. --- ### What Superseded by #10017, which carries the reviewed symbol-type correction on current main. This closed PR retains the earlier review snapshot; use #10017 for the active diff, current test results and CI. Carry the original ELF symbol-type nibble through parsing in `NidReference::SymbolType`, then use it when writing named imports to the SysV dynamic symbol table. `STT_NOTYPE`, `STT_OBJECT` and `STT_FUNC` remain distinct; non-function imports are no longer all converted to objects. Existing TLS relocation handling and weak/global binding remain in place. Addresses the [STT_NOTYPE review](https://github.com/boykopovar/AnyPS5/pull/8899#discussion_r4333229721). The regression covers all 16 type values with both weak/global binding and GLOB_DAT/JUMP_SLOT relocations. The relinker prerequisite of #6879 is now tracked in #10017. Historical tested source: [earlier branch diff](https://github.com/SteelCrab/AnyPS5/compare/a6646f8464140180351e4c08694dccdd55b2814d...15366612f433497db718d701a313136448b1f8fd). GitHub rejected reopening this PR after the branch history changed, so #10017 replaces it. ### Tested Ubuntu 26.04.1 x86-64, GCC 15.2, Release. Rebased onto main `a6646f8464140180351e4c08694dccdd55b2814d`; tested head `15366612f433497db718d701a313136448b1f8fd`. - Negative control: the preceding PR implementation fails the new `STT_NOTYPE` assertion, emitting type 1 (`STT_OBJECT`) for input type 0. - Relinker-only configure (`ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`), build and full CTest: **240/240 passed**. - Focused `ctest -R '^import_symbol_types$' -V`: **1/1 passed**, exercising **64 conversion fixtures** (16 types × 2 bindings × 2 relocation kinds). - `python3 tools/check_conventions.py --base origin/main` and the complete PR-template check passed locally. Merge check against the tested main is clean. - Overlap scan completed. #6879 carries the intended temporary copy; other shared files are reported for PRs that conflict with main. #8076 changes unwind/data-table scanning rather than import-symbol parsing. CI coverage: **Build / `relinker`** runs this regression and the complete relinker suite on Linux, Windows and macOS. A maintainer-triggered Build run is required for this contributor. No remote native matrix result is claimed for this head; Windows and macOS were not run locally. This PR remains closed and is superseded by #10017. The results above are historical local results for the explicitly listed commit. <!-- 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. --> ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-21 05:06:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:06:25Z.

Code review location: core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp; line 90

@@ -87,7 +87,8 @@ SysVDynamicSection SysVDynamicSectionBuilder::BuildDynamicSection(
         if (ref.Nid.empty()) return static_cast<std::uint8_t>((STB_WEAK << 4) | STT_NOTYPE);
         const bool tls = ref.RelocationTypeValue == R_X86_64_DTPMOD64 || ref.RelocationTypeValue == R_X86_64_DTPOFF64
             || ref.RelocationTypeValue == R_X86_64_TPOFF64;
-        return static_cast<std::uint8_t>(((ref.Weak ? STB_WEAK : STB_GLOBAL) << 4) | (tls ? STT_TLS : STT_FUNC));
+        const auto type = tls ? STT_TLS : ref.Function ? STT_FUNC : STT_OBJECT;

Could we preserve the input symbol type here instead of deriving every non-function import as STT_OBJECT? The parser currently reduces st_info & 0xf to Function = (type == STT_FUNC), so an undefined STT_NOTYPE import is indistinguishable from STT_OBJECT by this point and will now be emitted as an object. If normalizing STT_NOTYPE to object is intentional, please narrow the PR description; otherwise retaining the original type in NidReference (or explicitly mapping only STT_OBJECT to object) would make the preservation claim accurate.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4333229721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8899#discussion_r4333229721). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T05:06:25Z. **Code review location:** `core/relinker/relinker/src/output/SysVDynamicSectionBuilder.cpp`; line 90 ~~~~diff @@ -87,7 +87,8 @@ SysVDynamicSection SysVDynamicSectionBuilder::BuildDynamicSection( if (ref.Nid.empty()) return static_cast<std::uint8_t>((STB_WEAK << 4) | STT_NOTYPE); const bool tls = ref.RelocationTypeValue == R_X86_64_DTPMOD64 || ref.RelocationTypeValue == R_X86_64_DTPOFF64 || ref.RelocationTypeValue == R_X86_64_TPOFF64; - return static_cast<std::uint8_t>(((ref.Weak ? STB_WEAK : STB_GLOBAL) << 4) | (tls ? STT_TLS : STT_FUNC)); + const auto type = tls ? STT_TLS : ref.Function ? STT_FUNC : STT_OBJECT; ~~~~ --- Could we preserve the input symbol type here instead of deriving every non-function import as `STT_OBJECT`? The parser currently reduces `st_info & 0xf` to `Function = (type == STT_FUNC)`, so an undefined `STT_NOTYPE` import is indistinguishable from `STT_OBJECT` by this point and will now be emitted as an object. If normalizing `STT_NOTYPE` to object is intentional, please narrow the PR description; otherwise retaining the original type in `NidReference` (or explicitly mapping only `STT_OBJECT` to object) would make the preservation claim accurate.
github-actions[bot] commented 2026-10-21 05:13:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T05:13:59Z.


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 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7532 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308613985 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8899#issuecomment-6308613985). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T05:13:59Z. --- <!-- pr-overlap --> 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt` | | [PR 7532](https://www.github.com/boykopovar/AnyPS5/pull/7532) | `core/relinker/CMakeLists.txt`<br>`core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp` |
github-actions[bot] commented 2026-10-21 12:04:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T12:04:34Z.


Thank you for your contribution! Authors with no pull requests merged into main can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315450445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8899#issuecomment-6315450445). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T12:04:34Z. --- Thank you for your contribution! Authors with no pull requests merged into `main` can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

Pull request closed

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!8899
No description provided.