Skip to content

build: a darwin sysroot stub names only what macOS exports (#2530) - #2775

Merged
ehartford merged 1 commit into
mainfrom
fix-2530-stubs
Oct 28, 2026
Merged

ehartford merged 1 commit into
mainfrom
fix-2530-stubs

Conversation

@ehartford

@ehartford ehartford commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

build: a darwin sysroot stub names only what macOS exports (#2530)

The declared libraries' .tbd stubs named every API a header declares,
but Apple builds some of it out: libsqlite3's stub named 9 symbols
/usr/lib/libsqlite3.dylib does not export (sqlite3_load_extension and
sqlite3_enable_load_extension under SQLITE_OMIT_LOAD_EXTENSION,
sqlite3_unlock_notify, the win32 entry points), libz 14, libxml2 40,
libiconv 1. A call of one linked against the stub and crashed at run
time: the probe calling sqlite3_enable_load_extension built and exited
139 at the call (lazy bind of a missing symbol). Against Apple's SDK
the same program fails at link.

Root cause: sdk_darwin_declared_libraries built each stub from the
header's API macros alone (sdk_header_api_symbols); nothing compared
it with what the OS exports.

Evidence: --check before: 64 stub symbols not exported; after: every
stub symbol exported (sqlite3 284 -> 275, libz 93 -> 79, libxml2
1718 -> 1678, libiconv 12 -> 11). The probe now fails at link
("ld64.lld: error: undefined symbol: _sqlite3_enable_load_extension");
examples/c-interop runs green without SDKROOT on stage1.
test/compile_errors/err_2530_stub_names_only_exported.w failed on the
installed compiler (the build succeeded) and passes on stage1.

The declared libraries' .tbd stubs named every API a header declares,
but Apple builds some of it out: libsqlite3's stub named 9 symbols
/usr/lib/libsqlite3.dylib does not export (sqlite3_load_extension and
sqlite3_enable_load_extension under SQLITE_OMIT_LOAD_EXTENSION,
sqlite3_unlock_notify, the win32 entry points), libz 14, libxml2 40,
libiconv 1. A call of one linked against the stub and crashed at run
time: the probe calling sqlite3_enable_load_extension built and exited
139 at the call (lazy bind of a missing symbol). Against Apple's SDK
the same program fails at link.

Root cause: sdk_darwin_declared_libraries built each stub from the
header's API macros alone (sdk_header_api_symbols); nothing compared
it with what the OS exports.

- build/darwin_exports/<lib>.txt records each library's exports, read
  from /usr/lib with dyld_info by tools/darwin_exports.w (macOS 26.6.2
  named in each file). The sysroot build reads only these committed
  lists, never the host.
- Each stub is the header's declarations that the list exports
  (sdk_declared_and_exported). The lists are darwin-sysroot inputs.
- tools/darwin_exports.w --check compares a built sysroot's stubs with
  the host's dylibs. It needs dyld_info, an xcrun shim (Command Line
  Tools), so it is a maintainer check beside the rewrite, not a gate
  target (#1915: the build reads nothing of the host).

Evidence: --check before: 64 stub symbols not exported; after: every
stub symbol exported (sqlite3 284 -> 275, libz 93 -> 79, libxml2
1718 -> 1678, libiconv 12 -> 11). The probe now fails at link
("ld64.lld: error: undefined symbol: _sqlite3_enable_load_extension");
examples/c-interop runs green without SDKROOT on stage1.
test/compile_errors/err_2530_stub_names_only_exported.w failed on the
installed compiler (the build succeeded) and passes on stage1.
@ehartford
ehartford added this pull request to stack #2777 October 28, 2026 17:14
@ehartford ehartford changed the title fix 2530 stubs build: a darwin sysroot stub names only what macOS exports (#2530) Oct 28, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery GREEN on the stack top 6cba97b (with run tools/battery.w, 562 s; gate, uat and battery-checks). The first battery (16cc3e0) was red on err_2530_stub_names_only_exported: a c_import cache entry made under the Xcode SDK was served to the embedded-sysroot run. #2778 fixes the cache key.

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.

1 participant