fix(relinker): synthesise a non-executable PT_GNU_STACK for Linux executables #7363

Merged
plokmklo merged 4 commits from upstream-pr/7363 into main 2026-10-19 14:52:18 +00:00
plokmklo commented 2026-10-18 02:22:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plokmklo on 2026-10-18T02:22:59Z.


What

The Linux executable output carries no PT_GNU_STACK: SegmentFilter treats every type in [PT_LOOS, PT_HIOS] as SCE-specific and only PT_GNU_EH_FRAME is rescued, and nothing synthesised one. On x86-64 Linux a main executable without PT_GNU_STACK is loaded with an executable stack (EXSTACK_DEFAULT), which is weaker than what the guest asked for.

After the discussion below, this PR now carries only the PT_GNU_STACK half of #6394:

  • A PT_GNU_STACK the input has is kept (its addresses are 0 and RebaseProgramHeaders already skips it in the fixed-base path).
  • An input without one gets a synthesised non-executable stack header (PF_R | PF_W, zero addresses, the same shape LinuxGuestModuleWriter already adds to guest-module output). The synthesis is skipped when no program header slot is available, so tight-slot inputs keep converting and the existing slot-exhaustion messages are unchanged.
  • WriteLayout and RequiredProgramHeaderCount now share one predicate — the count required for the layout — so they cannot disagree about the extra slot: the header is written exactly when the count fits the table, and the output table grows one slot earlier when the input has no stack header.
  • The PT_GNU_RELRO half is left to #6406, which guards the lazy-binding GOT and the mprotect page-range cases. This branch no longer touches the RELRO handling.

Guest-module output is unchanged (its writer already keeps PT_GNU_STACK). PT_GNU_PROPERTY and the SCE segment types are still dropped.

Three existing tests assumed the old shape and are updated:

  • test_linux_eh_frame_header.py: exact output-header counts grow by the synthesised stack (6→7, 7→8); also asserts the synthesised header in no-frame-exact-slots.
  • test_linux_input_program_headers.py: the exact-slot and both cases now grow the table one slot earlier, phnum 8→9.
  • Amd64OnlyConverterTests.cpp executableFileOffset: read e_phoff from the ELF header instead of assuming the table stayed at offset 64 (the table now relocates one slot earlier).

New test test_linux_gnu_stack.py (registered as linux_gnu_stack): an input PT_GNU_STACK survives plain and --linux-fixed-base conversion unchanged, an input without one gets the synthesised non-executable header, and an input without any GNU header gets it while the SCE-specific segments are still dropped.

Tested

  • Fedora sandbox, GCC 14.2, Release relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), full relinker ctest suite green (152 tests, including the updated and new ones) on the restructured branch.
  • python3 tools/check_conventions.py --base origin/main clean.
  • Reproduced the issue's rows before the change: a fixture's PT_GNU_STACK was dropped from the output; after the change it survives and an input without one gets the synthesised header.

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: #6406
  • Fixes: (the PT_GNU_STACK half of #6394; PT_GNU_RELRO is #6406)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4905733716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363). Originally posted by [plokmklo](https://github.com/plokmklo) on 2026-10-18T02:22:59Z. --- ### What The Linux executable output carries no `PT_GNU_STACK`: `SegmentFilter` treats every type in `[PT_LOOS, PT_HIOS]` as SCE-specific and only `PT_GNU_EH_FRAME` is rescued, and nothing synthesised one. On x86-64 Linux a main executable without `PT_GNU_STACK` is loaded with an executable stack (`EXSTACK_DEFAULT`), which is weaker than what the guest asked for. After the discussion below, this PR now carries only the `PT_GNU_STACK` half of #6394: - A `PT_GNU_STACK` the input has is kept (its addresses are 0 and `RebaseProgramHeaders` already skips it in the fixed-base path). - An input without one gets a synthesised non-executable stack header (`PF_R | PF_W`, zero addresses, the same shape `LinuxGuestModuleWriter` already adds to guest-module output). The synthesis is skipped when no program header slot is available, so tight-slot inputs keep converting and the existing slot-exhaustion messages are unchanged. - `WriteLayout` and `RequiredProgramHeaderCount` now share one predicate — the count required for the layout — so they cannot disagree about the extra slot: the header is written exactly when the count fits the table, and the output table grows one slot earlier when the input has no stack header. - The `PT_GNU_RELRO` half is left to #6406, which guards the lazy-binding GOT and the `mprotect` page-range cases. This branch no longer touches the RELRO handling. Guest-module output is unchanged (its writer already keeps `PT_GNU_STACK`). `PT_GNU_PROPERTY` and the SCE segment types are still dropped. Three existing tests assumed the old shape and are updated: - `test_linux_eh_frame_header.py`: exact output-header counts grow by the synthesised stack (6→7, 7→8); also asserts the synthesised header in `no-frame-exact-slots`. - `test_linux_input_program_headers.py`: the exact-slot and both cases now grow the table one slot earlier, phnum 8→9. - `Amd64OnlyConverterTests.cpp` `executableFileOffset`: read `e_phoff` from the ELF header instead of assuming the table stayed at offset 64 (the table now relocates one slot earlier). New test `test_linux_gnu_stack.py` (registered as `linux_gnu_stack`): an input `PT_GNU_STACK` survives plain and `--linux-fixed-base` conversion unchanged, an input without one gets the synthesised non-executable header, and an input without any GNU header gets it while the SCE-specific segments are still dropped. ### Tested - Fedora sandbox, GCC 14.2, Release relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`), full relinker `ctest` suite green (152 tests, including the updated and new ones) on the restructured branch. - `python3 tools/check_conventions.py --base origin/main` clean. - Reproduced the issue's rows before the change: a fixture's `PT_GNU_STACK` was dropped from the output; after the change it survives and an input without one gets the synthesised header. ### 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: #6406 - [x] Fixes: (the `PT_GNU_STACK` half of #6394; `PT_GNU_RELRO` is #6406) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-18 02:36:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T02:36:05Z.


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 2780 core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp
PR 6879 core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp
PR 7332 core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6244788148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6244788148). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T02:36:05Z. --- <!-- 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 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp` |
oneandonlydean commented 2026-10-18 02:53:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T02:53:25Z.


Thanks @plokmklo. We compared this with #6406, which fixes the same SegmentFilter::ShouldSkip defect and is in final testing now. The two conflict in SegmentFilter.cpp, and we'd like to take the RELRO part from #6406:

  • Keeping PT_GNU_RELRO unconditionally breaks two cases that #6406 had to guard. With --lazy-binding, the lazy GOT slots sit inside RELRO, so the first lazy call faults when ld.so writes the slot. And when the kept RELRO extends past the RW LOAD's pages, glibc's mprotect(PROT_READ) fails with ENOMEM and the process exits with 127. That second case is the failure #6406 hit and fixed in c56cafae2.
  • The PT_GNU_STACK synthesis here is new and useful. None of the eboots we checked has a PT_GNU_STACK, so keeping an existing one changes nothing for them, while synthesizing {PF_R|PF_W, align 16} gives them a non-executable stack marking. The e_phoff fix in Amd64OnlyConverterTests.cpp is good too.

Proposal: once #6406 merges, could you rebase this onto it and keep only the PT_GNU_STACK synthesis plus the e_phoff test fix? It adds a program header to every title, so we'll run a full review and the game gates on it. One thing to look at while you're there: RequiredProgramHeaderCount always reserves one extra header when the input has no PT_GNU_STACK, but WriteLayout only synthesizes it when kept + synthetic < PhNum, so it would be good to make sure the two can't disagree, including with #6406's frame budget.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6244920648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6244920648). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T02:53:25Z. --- Thanks @plokmklo. We compared this with #6406, which fixes the same `SegmentFilter::ShouldSkip` defect and is in final testing now. The two conflict in `SegmentFilter.cpp`, and we'd like to take the RELRO part from #6406: - Keeping `PT_GNU_RELRO` unconditionally breaks two cases that #6406 had to guard. With `--lazy-binding`, the lazy GOT slots sit inside RELRO, so the first lazy call faults when ld.so writes the slot. And when the kept RELRO extends past the RW LOAD's pages, glibc's `mprotect(PROT_READ)` fails with ENOMEM and the process exits with 127. That second case is the failure #6406 hit and fixed in c56cafae2. - The `PT_GNU_STACK` synthesis here is new and useful. None of the eboots we checked has a `PT_GNU_STACK`, so keeping an existing one changes nothing for them, while synthesizing `{PF_R|PF_W, align 16}` gives them a non-executable stack marking. The `e_phoff` fix in `Amd64OnlyConverterTests.cpp` is good too. Proposal: once #6406 merges, could you rebase this onto it and keep only the `PT_GNU_STACK` synthesis plus the `e_phoff` test fix? It adds a program header to every title, so we'll run a full review and the game gates on it. One thing to look at while you're there: `RequiredProgramHeaderCount` always reserves one extra header when the input has no `PT_GNU_STACK`, but `WriteLayout` only synthesizes it when `kept + synthetic < PhNum`, so it would be good to make sure the two can't disagree, including with #6406's frame budget.
MarcZX10 commented 2026-10-18 03:05:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T03:05:24Z.


One compatibility case to check before treating the RELRO handling as complete: a PS5 eboot I inspected has 697 R_X86_64_JUMP_SLOT targets inside its PT_GNU_RELRO range and no DT_BIND_NOW. This PR preserves that range unconditionally. Could you verify that the resulting Linux executable can resolve an initially-unresolved PLT entry on first call, or otherwise explain how lazy binding avoids writing into the RELRO pages? The header-shape tests here do not exercise that runtime path. I have a related open change in #6406 that omits RELRO for lazy-binding inputs based on this layout evidence; I’m mentioning it so the overlapping approaches can be compared, not to ask you to abandon your PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245011604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6245011604). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T03:05:24Z. --- One compatibility case to check before treating the RELRO handling as complete: a PS5 eboot I inspected has 697 `R_X86_64_JUMP_SLOT` targets inside its `PT_GNU_RELRO` range and no `DT_BIND_NOW`. This PR preserves that range unconditionally. Could you verify that the resulting Linux executable can resolve an initially-unresolved PLT entry on first call, or otherwise explain how lazy binding avoids writing into the RELRO pages? The header-shape tests here do not exercise that runtime path. I have a related open change in #6406 that omits RELRO for lazy-binding inputs based on this layout evidence; I’m mentioning it so the overlapping approaches can be compared, not to ask you to abandon your PR.
MarcZX10 commented 2026-10-18 03:05:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T03:05:59Z.


Thanks for the detailed coordination note. I saw it after posting my follow-up, so I repeated the lazy-binding point you had already covered. I agree the two failure cases belong in #6406; the remaining work here is the separate PT_GNU_STACK synthesis and e_phoff test correction once the rebase is ready. I will not add another review request on that same point.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245016489 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6245016489). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T03:05:59Z. --- Thanks for the detailed coordination note. I saw it after posting my follow-up, so I repeated the lazy-binding point you had already covered. I agree the two failure cases belong in #6406; the remaining work here is the separate PT_GNU_STACK synthesis and e_phoff test correction once the rebase is ready. I will not add another review request on that same point.
plokmklo commented 2026-10-18 03:19:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plokmklo on 2026-10-18T03:19:10Z.


Restructured per your proposal: the branch now carries only the PT_GNU_STACK keep/synthesis and the e_phoff test correction, with Depends on: #6406 for the RELRO half, so the SegmentFilter RELRO handling and its lazy-binding and mprotect guards stay with #6406.

For the RequiredProgramHeaderCount/WriteLayout disagreement you flagged: both now derive from one predicate — RequiredProgramHeaderCount(originalHeaders) <= PhNum — so the header is written exactly when the count says it fits, and the slot-exhaustion messages for tight inputs (including the 65536-slot overflow case) are unchanged. The new test_linux_gnu_stack.py covers keep-under-fixed-base, synthesis, and SCE-segment dropping; the full relinker suite (152 tests) is green on the restructured branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245120661 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6245120661). Originally posted by [plokmklo](https://github.com/plokmklo) on 2026-10-18T03:19:10Z. --- Restructured per your proposal: the branch now carries only the `PT_GNU_STACK` keep/synthesis and the `e_phoff` test correction, with `Depends on: #6406` for the RELRO half, so the `SegmentFilter` RELRO handling and its lazy-binding and mprotect guards stay with #6406. For the `RequiredProgramHeaderCount`/`WriteLayout` disagreement you flagged: both now derive from one predicate — `RequiredProgramHeaderCount(originalHeaders) <= PhNum` — so the header is written exactly when the count says it fits, and the slot-exhaustion messages for tight inputs (including the 65536-slot overflow case) are unchanged. The new `test_linux_gnu_stack.py` covers keep-under-fixed-base, synthesis, and SCE-segment dropping; the full relinker suite (152 tests) is green on the restructured branch.
MarcZX10 commented 2026-10-18 03:21:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T03:21:38Z.


Thanks for the update. I checked the current PR state, and it still reports head 791985268f997555b4f2be9324c972738813deed; its three changed files are GuestPthreadGuardSize.cpp, GuestSocketPortZero.cpp, and test_linux_gnu_stack.py. The body also still describes the RELRO implementation and says Depends on: none. I cannot see the narrowed PT_GNU_STACK/e_phoff change or the #6406 dependency in the published branch yet. Could you push the restructured branch and update the PR body when ready? I will review that exact diff then.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245139295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6245139295). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T03:21:38Z. --- Thanks for the update. I checked the current PR state, and it still reports head `791985268f997555b4f2be9324c972738813deed`; its three changed files are `GuestPthreadGuardSize.cpp`, `GuestSocketPortZero.cpp`, and `test_linux_gnu_stack.py`. The body also still describes the RELRO implementation and says `Depends on: none`. I cannot see the narrowed PT_GNU_STACK/e_phoff change or the #6406 dependency in the published branch yet. Could you push the restructured branch and update the PR body when ready? I will review that exact diff then.
MarcZX10 commented 2026-10-18 05:11:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T05:11:30Z.


Thanks for pushing the restructured head. I checked the current diff and confirmed it now contains only the PT_GNU_STACK keep/synthesis work plus the e_phoff/test updates, with the RELRO handling left to #6406 as described. The shared RequiredProgramHeaderCount predicate also addresses the slot-count/write disagreement I raised. My earlier note was based on the prior published head; that mismatch is resolved. I have not rerun the 152-test suite locally, so I am relying on your reported result for that validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245976430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6245976430). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T05:11:30Z. --- Thanks for pushing the restructured head. I checked the current diff and confirmed it now contains only the PT_GNU_STACK keep/synthesis work plus the e_phoff/test updates, with the RELRO handling left to #6406 as described. The shared RequiredProgramHeaderCount predicate also addresses the slot-count/write disagreement I raised. My earlier note was based on the prior published head; that mismatch is resolved. I have not rerun the 152-test suite locally, so I am relying on your reported result for that validation.
plokmklo commented 2026-10-18 05:45:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plokmklo on 2026-10-18T05:45:55Z.


Thanks for the detailed comparison — agreed on all points. The branch is rebased onto #6406 (c56cafae2) and slimmed to exactly the two pieces approved; Depends on: #6406. Head: https://github.com/plokmklo/AnyPS5/tree/fix/relinker-gnu-stack-relro.

What remains here: (1) PT_GNU_STACK synthesis — when the kept headers contain no PT_GNU_STACK, the layout appends {PF_R|PF_W, align 16, no mapping}; an existing stack is preserved verbatim. (2) the e_phoff fix in executableFileOffset (Amd64OnlyConverterTests), which is now load-bearing: the synthesis adds a header to every title, so full input tables move and the stub lookup must follow the output e_phoff. Everything that duplicated #6406 (unconditional RELRO, the SegmentFilter edits) is dropped, and #6406's lazy-binding and RELRO-coverage guards are untouched.

On the RequiredProgramHeaderCount/WriteLayout question: yes, they could disagree. The old layout only synthesized when kept + 5 < PhNum, so any PhNum at or below the reserved count silently skipped the header the count had reserved — concretely, once required > 65535 the uint16 cap skips the table move and the stack vanished without an error. Both entry points now derive from one shared header list, so the reserved count and the written count are the same value by construction: exact-fit tables move and get the stack, tables with a free slot reuse it without moving, and inputs that already have a stack neither reserve nor grow (e_phoff unchanged at 64). With #6406's frame budget, synthesis happens before the EH_FRAME slot check, so RELRO drops and the synthetic stack flow through one count, and space exhaustion still fails loudly.

Tests: new converter cases for each boundary (exact fit, one spare, with-stack exact, with-stack one short), layout-builder assertions that written == required, and end-to-end relinks including executing an output whose stack was synthesized, with RELRO kept. Full relinker ctest suite passes (188/188) on top of #6406. Needs the full review plus a real-title sanity run per the game gates.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6246231075 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6246231075). Originally posted by [plokmklo](https://github.com/plokmklo) on 2026-10-18T05:45:55Z. --- Thanks for the detailed comparison — agreed on all points. The branch is rebased onto #6406 (`c56cafae2`) and slimmed to exactly the two pieces approved; **Depends on: #6406**. Head: `https://github.com/plokmklo/AnyPS5/tree/fix/relinker-gnu-stack-relro`. What remains here: (1) PT_GNU_STACK synthesis — when the kept headers contain no PT_GNU_STACK, the layout appends `{PF_R|PF_W, align 16, no mapping}`; an existing stack is preserved verbatim. (2) the `e_phoff` fix in `executableFileOffset` (Amd64OnlyConverterTests), which is now load-bearing: the synthesis adds a header to every title, so full input tables move and the stub lookup must follow the output `e_phoff`. Everything that duplicated #6406 (unconditional RELRO, the SegmentFilter edits) is dropped, and #6406's lazy-binding and RELRO-coverage guards are untouched. On the RequiredProgramHeaderCount/WriteLayout question: yes, they could disagree. The old layout only synthesized when `kept + 5 < PhNum`, so any PhNum at or below the reserved count silently skipped the header the count had reserved — concretely, once `required > 65535` the uint16 cap skips the table move and the stack vanished without an error. Both entry points now derive from one shared header list, so the reserved count and the written count are the same value by construction: exact-fit tables move and get the stack, tables with a free slot reuse it without moving, and inputs that already have a stack neither reserve nor grow (`e_phoff` unchanged at 64). With #6406's frame budget, synthesis happens before the EH_FRAME slot check, so RELRO drops and the synthetic stack flow through one count, and space exhaustion still fails loudly. Tests: new converter cases for each boundary (exact fit, one spare, with-stack exact, with-stack one short), layout-builder assertions that `written == required`, and end-to-end relinks including executing an output whose stack was synthesized, with RELRO kept. Full relinker ctest suite passes (188/188) on top of #6406. Needs the full review plus a real-title sanity run per the game gates.
oneandonlydean commented 2026-10-18 06:04:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T06:04:34Z.


@plokmklo Thanks, the Linux relinker tests all pass on the full CI run for f104d9be0 (amd64_only_converter, program_layout_ranges, linux_gnu_segments, linux_eh_frame_header, linux_input_program_headers and linux_program_header_order), and so does Windows.

The two macOS relinker jobs fail to compile ProgramLayoutRangeTests.cpp, though (run 39102016538):

core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp:8:23: error: no type named 'size_t' in namespace 'std'

ElfConstants.hpp uses std::size_t but only includes <cstdint>. That's been latent on main because every other file includes something that pulls in <cstddef> first; this test includes ElfConstants.hpp on its first line, and libc++ doesn't provide size_t through <cstdint>. Adding #include <cstddef> to ElfConstants.hpp should fix it. Could you add that here?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6246374449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6246374449). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T06:04:34Z. --- @plokmklo Thanks, the Linux relinker tests all pass on the full CI run for f104d9be0 (amd64_only_converter, program_layout_ranges, linux_gnu_segments, linux_eh_frame_header, linux_input_program_headers and linux_program_header_order), and so does Windows. The two macOS relinker jobs fail to compile `ProgramLayoutRangeTests.cpp`, though (run 39102016538): ``` core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp:8:23: error: no type named 'size_t' in namespace 'std' ``` `ElfConstants.hpp` uses `std::size_t` but only includes `<cstdint>`. That's been latent on main because every other file includes something that pulls in `<cstddef>` first; this test includes `ElfConstants.hpp` on its first line, and libc++ doesn't provide `size_t` through `<cstdint>`. Adding `#include <cstddef>` to `ElfConstants.hpp` should fix it. Could you add that here?
simonbbby commented 2026-10-18 06:23:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-18T06:23:39Z.


Independent check of exact head f104d9be0865230d6b3811e4123e2c0a250ada7a, including the macOS CI blocker and live Linux stack mappings.

macOS 27.2 arm64, AppleClang 21.0.0, CMake 4.4.4, Release relinker-only:

  • cmake --build … --target program_layout_ranges_tests reproduces the reported ElfConstants.hpp:8:23: no type named 'size_t' in namespace 'std' (exit 1).
  • Adding only #include <cstddef> before <cstdint> in that header makes the same target build. ctest -R '^program_layout_ranges$' --output-on-failure passes 1/1. No include-order change to the test, forced include or compiler-flag change is needed. I restored the source after the experiment; this is verification of the proposed fix, not an upstream commit or full macOS-suite claim.

Ubuntu 24.04 x86-64, kernel 7.0.0-38-generic, GCC 13.3:

  • Focused CTest: program_layout_ranges, linux_gnu_segments, linux_eh_frame_header, linux_program_header_order, linux_input_program_headers: 5/5 pass.
  • Six generated inputs/outputs (no game files), covering no input stack header, input flags 6, and input flags 7, each in default and --linux-fixed-base 0x400000 mode. All outputs have exactly one GNU_STACK, zero addresses/sizes and alignment 16. Missing input headers synthesize flags 6; supplied flags are preserved.
  • I ran each generated output with a two-byte loop at its guest entry and read its live /proc/<pid>/maps. The synthesized and preserved flags-6 cases have an rw-p stack; both preserved flags-7 controls have rwxp. All generated inputs remain byte-identical.

One qualification to the opening description: on this kernel, changing only the synthesized output header type to PT_NULL still gives rw-p, in both default/fixed modes. So this host verifies explicit header synthesis/preservation and that executable-stack requests are honored; it does not demonstrate a no-header → executable-stack default. I would qualify that claim by kernel/ABI rather than present the NX improvement as universal for current x86-64 Linux.

No title sanity run, Windows execution or macOS guest execution was performed. The generated looping processes were terminated after their mappings were captured.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6246526389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6246526389). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-18T06:23:39Z. --- Independent check of exact head `f104d9be0865230d6b3811e4123e2c0a250ada7a`, including the macOS CI blocker and live Linux stack mappings. **macOS 27.2 arm64, AppleClang 21.0.0, CMake 4.4.4, Release relinker-only:** - `cmake --build … --target program_layout_ranges_tests` reproduces the reported `ElfConstants.hpp:8:23: no type named 'size_t' in namespace 'std'` (exit 1). - Adding only `#include <cstddef>` before `<cstdint>` in that header makes the same target build. `ctest -R '^program_layout_ranges$' --output-on-failure` passes 1/1. No include-order change to the test, forced include or compiler-flag change is needed. I restored the source after the experiment; this is verification of the proposed fix, not an upstream commit or full macOS-suite claim. **Ubuntu 24.04 x86-64, kernel 7.0.0-38-generic, GCC 13.3:** - Focused CTest: `program_layout_ranges`, `linux_gnu_segments`, `linux_eh_frame_header`, `linux_program_header_order`, `linux_input_program_headers`: **5/5 pass**. - Six generated inputs/outputs (no game files), covering no input stack header, input flags 6, and input flags 7, each in default and `--linux-fixed-base 0x400000` mode. All outputs have exactly one GNU_STACK, zero addresses/sizes and alignment 16. Missing input headers synthesize flags 6; supplied flags are preserved. - I ran each generated output with a two-byte loop at its guest entry and read its live `/proc/<pid>/maps`. The synthesized and preserved flags-6 cases have an **`rw-p`** stack; both preserved flags-7 controls have **`rwxp`**. All generated inputs remain byte-identical. One qualification to the opening description: on **this kernel**, changing only the synthesized output header type to PT_NULL still gives `rw-p`, in both default/fixed modes. So this host verifies explicit header synthesis/preservation and that executable-stack requests are honored; it does not demonstrate a no-header → executable-stack default. I would qualify that claim by kernel/ABI rather than present the NX improvement as universal for current x86-64 Linux. No title sanity run, Windows execution or macOS guest execution was performed. The generated looping processes were terminated after their mappings were captured.
plokmklo commented 2026-10-19 08:46:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plokmklo on 2026-10-19T08:46:38Z.


Rebased onto current main (fb0dc118f) since #6406 merged, and pushed two commits:

1. dd1e4b40d — the <cstddef> include both of you asked for. ProgramLayoutRangeTests.cpp includes ElfConstants.hpp first and AppleClang/libc++ does not provide std::size_t through <cstdint>, so both macOS relinker jobs should compile again.

2. df0baf9e3 — a real regression your runs surfaced, thank you. With synthesis adding a header to every title, inputs whose original table has no free slot now relocate the table into the extra block. game_patches then failed: the verify guard rejected every patch below e_phoff + e_phnum * e_phentsize, which for a relocated table swallows the whole first PT_LOAD (fixture: table at 0x8108, patch at 0x4fff). The guard now rejects overlap with the ELF header ([0, 64)) and the table range itself, instead of everything below the table end. headerRange()'s expectations (reject 0x0/0x40/0xaf, accept 0xb0) are unchanged, and patches below a start-of-file table behave exactly as before.

Tested: Ubuntu 24.04 x86-64, GCC 14.2, relinker-only Release build: ctest 210/210 pass (game_patches, program_layout_ranges, linux_gnu_segments, linux_eh_frame_header, linux_input_program_headers, linux_program_header_order included), tools/check_conventions.py --base origin/main clean.

Head: df0baf9e3.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263322924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7363#issuecomment-6263322924). Originally posted by [plokmklo](https://github.com/plokmklo) on 2026-10-19T08:46:38Z. --- Rebased onto current `main` (fb0dc118f) since #6406 merged, and pushed two commits: **1. `dd1e4b40d` — the `<cstddef>` include both of you asked for.** `ProgramLayoutRangeTests.cpp` includes `ElfConstants.hpp` first and AppleClang/libc++ does not provide `std::size_t` through `<cstdint>`, so both macOS relinker jobs should compile again. **2. `df0baf9e3` — a real regression your runs surfaced, thank you.** With synthesis adding a header to every title, inputs whose original table has no free slot now relocate the table into the extra block. `game_patches` then failed: the verify guard rejected every patch below `e_phoff + e_phnum * e_phentsize`, which for a relocated table swallows the whole first `PT_LOAD` (fixture: table at `0x8108`, patch at `0x4fff`). The guard now rejects overlap with the ELF header (`[0, 64)`) and the table range itself, instead of everything below the table end. `headerRange()`'s expectations (reject `0x0`/`0x40`/`0xaf`, accept `0xb0`) are unchanged, and patches below a start-of-file table behave exactly as before. **Tested:** Ubuntu 24.04 x86-64, GCC 14.2, relinker-only Release build: `ctest` 210/210 pass (`game_patches`, `program_layout_ranges`, `linux_gnu_segments`, `linux_eh_frame_header`, `linux_input_program_headers`, `linux_program_header_order` included), `tools/check_conventions.py --base origin/main` clean. Head: df0baf9e3.
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!7363
No description provided.