Skip to content

fix(libc): define PF_R beside PF_X and PF_W for the macOS ELF types - #10659

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
imellag:fix/libc-elf-pf-r-macos
Oct 27, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
imellag:fix/libc-elf-pf-r-macos

Conversation

@imellag

@imellag imellag commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

#9972 made GuestFlexibleMemoryModule.cpp describe its segment on macOS with header.p_flags = PF_R | PF_W. On macOS that file takes its ELF types from prx/libc/include/specifics/linux/ElfTypes.hpp, which defines PF_X and PF_W but not PF_R, so on current main the fixture fails to compile on macOS:

core/libs/tests/GuestFlexibleMemoryModule.cpp:22:22: error: use of undeclared identifier 'PF_R'

This adds PF_R = 4 (the ELF value) beside the other two. None of the files that include ElfTypes.hpp also include <elf.h> or <link.h>, so the name cannot meet the system macro, as with PF_X and PF_W. #7201 adds the same constant to the same header as part of the whole macOS port, inside its own #ifdef __APPLE__ block. The two lines are in different places, so a text merge of the second one to land is clean but leaves two PF_R definitions, a redefinition error on macOS. #7201's head (6687cbac29, 2026-10-16) conflicts with main and needs a rebase anyway, so the order proposed here is this PR first and PF_R dropped from #7201's block at its rebase; if #7201 lands first, this PR is not needed and I will close it.

Tested

Apple M4 Pro, macOS 27.0.1, Apple clang, x86-64 Release (-DCMAKE_OSX_ARCHITECTURES=x86_64, Ninja), on main fee6a14709, whose ElfTypes.hpp, GuestFlexibleMemoryModule.cpp and libkernel/CMakeLists.txt match this branch's base c9b75825f3: cmake --build build --target guest_flexible_memory_module fails with the error above without this change and compiles and links guest_flexible_memory_module.guest.prx with it. The test that loads the fixture needs libkernel, which does not build on main on macOS yet, so it was not run. Not built on Linux or Windows; the header only gains a constant, and the macOS block that uses it is the only user.

check_conventions.py --base upstream/main passes. pr_overlap.py lists only #7201 as a pull request it could not compare on ElfTypes.hpp, because #7201 conflicts with main.

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

GuestFlexibleMemoryModule.cpp describes its segment with PF_R | PF_W on
macOS, where ElfTypes.hpp stands in for <elf.h>, but ElfTypes.hpp only
had PF_X and PF_W, so the fixture failed to compile on macOS with
"use of undeclared identifier 'PF_R'". PF_R is 4, as in the ELF
specification.

@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 one-line definition matches the ELF PF_R value (4), and the PR identifies the missing constant in the macOS ELF header as the compile failure. The focused macOS compile is author-reported; hosted policy checks pass, with relinker/register-context jobs still running. git diff --check passes.

Please coordinate the direct overlap with open #7201 before merging: it adds the same PF_R constant in the same header. The body acknowledges this, but the checklist says Depends on: none and does not record which branch lands first or how the second change will avoid a duplicate definition. Please agree and record the integration order (or clarify why the two patches will not conflict), then I can complete the review.

@imellag

imellag commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, you're right that it needs an order: a 3-way merge of ElfTypes.hpp between main, #7201's head (6687cbac29) and this branch is clean as text, but it keeps both lines, #7201's inside its #ifdef __APPLE__ block and this one beside PF_W, and the second definition fails to compile on macOS.

#7201's head is from 2026-10-16 and conflicts with main, so it needs a rebase anyway. I've recorded in the description the order I propose: this PR first, and PF_R dropped from #7201's Apple block at that rebase; if #7201 lands first, this PR isn't needed and I'll close it. @marion909, does that work for you?

AI-assisted: yes

@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 6dfd477eef25bc3a357c38208bfc0c4ad1eb2690. The missing ELF PF_R definition is the direct cause of the reported macOS fixture compile failure, and adding its value beside PF_X/PF_W is correct. The author has now documented the duplicate-definition hazard with #7201 and a workable ordering: this standalone fix first, then remove #7201’s duplicate at rebase; if #7201 lands first, close this PR. The focused macOS build is author-reported, not independently reproduced. Eligibility, conventions, intake, labels, report, all relinker platforms, ASan, register-context and write-watch checks pass; product build jobs are skipped. I found no remaining blocker on this PR.

@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 7201 core/libs/prx/libc/include/specifics/linux/ElfTypes.hpp

@github-actions github-actions Bot added the libc label Oct 24, 2026
@adriadam10 adriadam10 self-assigned this Oct 26, 2026
@adriadam10
adriadam10 merged commit 2e85f47 into boykopovar:main Oct 27, 2026
20 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked: PF_R = 4 is the ELF value and sits in the non-Linux branch of ElfTypes.hpp (Linux uses <link.h>), so no macro clash; it is what GuestFlexibleMemoryModule.cpp:22 needs. Conventions, relinker and macOS CI jobs are green; merged.

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