Skip to content

Fix iOS runtime symbol-loader exports - #9736

Open
derek-gerstmann wants to merge 2 commits into
mainfrom
dg/fix_ios_symbol_loader
Open

derek-gerstmann wants to merge 2 commits into
mainfrom
dg/fix_ios_symbol_loader

Conversation

@derek-gerstmann

@derek-gerstmann derek-gerstmann commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Halide's runtime API (HalideRuntime.h) declares nine symbol-loading entry points (halide_default_get_symbol, halide_default_load_library, halide_default_get_library_symbol, halide_get_symbol, halide_load_library, halide_get_library_symbol, and the three halide_set_custom_* setters). While get_initial_module_for_target in src/LLVM_Runtime_Linker.cpp includes osx_get_symbol for Target::MacOS, the Target::IOS branch omitted a symbol-lookup module altogether. Consequently, standalone iOS Host and Metal runtime archives (across ARM64 device, ARM64 Simulator, and x86-64 Simulator targets, including symbol-prefixed multi-backend distributions) omitted definitions for this entire function family, causing downstream executables that populate runtime dispatch tables or take addresses of these functions to fail at link time even when no kernel performs dynamic symbol lookup.

Summary of changes

  • iOS runtime module selection (src/LLVM_Runtime_Linker.cpp): Add get_initmod_osx_get_symbol to the Target::IOS branch so iOS Host and Metal runtimes reuse the existing Darwin dlopen/dlsym symbol-loader implementation.
  • Runtime documentation and cleanup (src/runtime/HalideRuntime.h, src/runtime/metal.cpp): Document the macOS and iOS default loader behavior (RTLD_DEFAULT global lookup, dlopen(name, RTLD_LAZY | RTLD_LOCAL), RTLD_DEFAULT fallback for null library handles, null return on missing libraries/symbols, and adherence to iOS code-signing/dynamic-loading restrictions without implying JIT support), and remove the obsolete comment in metal.cpp noting halide_get_symbol was absent on iOS.
  • Cross-target IR export test (test/correctness/ios_runtime_symbols.cpp, test/correctness/CMakeLists.txt): Compile standalone runtimes to LLVM IR for arm-64-ios, arm-64-ios-simulator, and x86-64-ios-simulator (with and without -metal) and verify externally visible weak definitions for all nine symbol-loader functions.
  • Apple archive, link, and Simulator integration test (test/integration/ios_runtime_symbols/, .github/workflows/testing-macos.yml): Build standalone Host and Metal .a archives via add_halide_runtime across all six iOS target/backend combinations, verify all nine defined exports per slice with xcrun nm -gU, link standalone consumer executables against the iphoneos and iphonesimulator SDKs (Foundation and Metal supplied explicitly), and run the native ARM64 Simulator Host and Metal consumers via simctl in testing-macos.yml to exercise default lookup, load_library(nullptr), null-handle lookup, missing symbol/library failure returns, custom handler dispatch, and handler restoration.

Validation

  • ctest --test-dir build\ios-loader-validation --output-on-failure -R '^correctness_(ios_runtime_symbols|cross_compilation)$' -j 2 — passed (and verified correctness_ios_runtime_symbols fails without osx_get_symbol).
  • Inspected Mach-O LC_SYMTAB symbol tables across all six generated standalone .a archives (arm-64-ios, arm-64-ios-simulator, x86-64-ios-simulator × Host/Metal) — passed (all nine public loader exports defined in each archive).
  • ruff check test/integration/ios_runtime_symbols/run.py and clang-format --dry-run --Werror test/correctness/ios_runtime_symbols.cpp test/integration/ios_runtime_symbols/consumer.cpp — passed.
  • python3 test/integration/ios_runtime_symbols/run.py --halide-root "$PWD/install" --build-dir "$PWD/build-ios-runtime-symbols" — wired into testing-macos.yml (arm-64); not run locally on Windows because macOS/Xcode SDKs and Simulator runtimes are required.

Fixes: N/A

Breaking changes

None.

Checklist

  • Tests added or updated (not required for docs, CI config, or typo fixes)
  • Documentation updated (if public API changed)
  • Python bindings updated (if public API changed)
  • Benchmarks are included here if the change is intended to affect performance.
  • Commits include AI attribution where applicable (see Code of Conduct)

Generated with GitHub Copilot

Include the Darwin symbol loader in iOS runtimes and cover Host and Metal archives across device and Simulator targets.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

1 participant