Skip to content

fix(UnixUtil): filter non-Mach-O symbols from Darwin dynsym exports (#1294) - #1296

Open
Xilonz wants to merge 2 commits into
crazywhalecc:v3from
Xilonz:fix/darwin-dynsym-filter
Open

Xilonz wants to merge 2 commits into
crazywhalecc:v3from
Xilonz:fix/darwin-dynsym-filter

Conversation

@Xilonz

@Xilonz Xilonz commented Nov 19, 2026

Copy link
Copy Markdown

What does this PR do?

Builds upon the test added in #1295 and fixes #1294 by ensuring that on Darwin (SystemTarget::getTargetOS() === 'Darwin'), UnixUtil filters out any symbol not starting with an underscore (_).

Background

In Darwin Mach-O ABI, all C identifiers are prefixed with _. Non-_ entries resulting from line wrapping or extended BSD archive (#1/<len>) headers cause Apple's ld to fail with <initial-undefines> when passed via -Wl,-exported_symbols_list.

Filtering $defined on Darwin ensures only valid Mach-O symbols are exported, resolving FrankenPHP / embed static build failures on macOS.

Closes #1294
Companion test PR: #1295

Note on Testing & Debugging

Note

All testing, reproduction, and debugging for this PR were conducted with the assistance of AI (Google Antigravity).

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the Darwin symbol-filtering change.

No open issues 🎉

What changed in this PR

Fixes Darwin dynamic-symbol exports for static PHP builds, addressing the macOS linker failure reported in #1294 and incorporating the regression test from #1295.

Changes:

  • Extracts symbol parsing into a testable parseDynamicSymbols() method.
  • Filters Darwin exports to underscore-prefixed symbols while preserving behavior on other platforms.
  • Adds a regression test verifying that malformed archive-header fragments are excluded.
File Description
tests/​StaticPHP/​Util/​UnixUtilTest.php Tests Darwin symbol filtering with archive-header fragments.
src/​StaticPHP/​Util/​System/​UnixUtil.php Extracts parsing and adds Darwin-only underscore filtering.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3][macOS] xcaddy link fails with <initial-undefines> due to non-Mach-O symbol fragments in libphp.a.dynsym

2 participants