Skip to content

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

Open

Description

@Xilonz

What happened?

When compiling FrankenPHP (or embedding PHP) on macOS using static-php-cli v3 (spc craft), spc fails at the buildFrankenphpForUnix stage:

Building frankenphp: building with xcaddy
[EXEC] go clean -cache
[EXEC] xcaddy build --output frankenphp --with github.com/dunglas/frankenphp=...
✘ Command execution failed: Command exited with non-zero code: 1

-------------------- Module error info --------------------
Failed module: Target Package 'frankenphp'
Failed stage: build -> buildFrankenphpForUnix
Failed command: xcaddy build --output frankenphp ...
  - Exit code: 1

Inside dist/log/spc.shell.log, the underlying Apple clang / ld error is:

Undefined symbols for architecture x86_64:
  "10", referenced from:
      <initial-undefines>
  "Init", referenced from:
      <initial-undefines>
  "lue", referenced from:
      <initial-undefines>
  "st_sort", referenced from:
      <initial-undefines>
  "y_rinit", referenced from:
      <initial-undefines>
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1

<initial-undefines> indicates that Apple's ld was asked to export symbols via -Wl,-exported_symbols_list,/path/to/libphp.a.dynsym that do not exist in any linked object file.

Related issue in FrankenPHP: php/frankenphp#2002

Root Cause

In src/StaticPHP/Util/System/UnixUtil.php:
UnixUtil::exportDynamicSymbols() runs nm -g --defined-only -P libphp.a.

  1. BSD ar Header Limits on macOS: In BSD ar, the ar_hdr.ar_name field has a fixed 16-character limit. Long member names (e.g., php_basic_early_rinit.o, zend_llist_sort.o) use BSD extended name headers (#1/<len>). When nm processes the archive, member headers or line continuations that do not end strictly with .o: or .o]: are parsed by strtok($line, " \t"), leaking line fragments like 10, Init, lue, st_sort, y_rinit into $defined.
  2. Darwin Mach-O Symbol Convention: In Mach-O C ABI, all valid C symbols generated by compilers start with a leading underscore (_). Strings without a leading _ cannot be valid exported C symbols on Darwin.
  3. Apple's ld treats -Wl,-exported_symbols_list strictly: any entry without a matching symbol in the linked objects causes linking to abort immediately. (GNU ld on Linux is lenient with --dynamic-list, which is why this does not break on Linux).

Note on Testing & Debugging

Note

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions