Skip to content

fix(apple): limit already-loaded reuse to rpath dependencies - #2292

Merged
morluto merged 2 commits into
morluto:mainfrom
viniciusdsandrade:fix/apple-dylib-already-loaded-rpath
Oct 13, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
viniciusdsandrade:fix/apple-dylib-already-loaded-rpath

Conversation

@viniciusdsandrade

Copy link
Copy Markdown
Contributor

Summary

When multiple images in different directories depend on @loader_path/ libraries sharing an install name (for example, plugins or isolated helpers bundling @loader_path/libhelper.dylib), dyld dependency resolution checked context.byInstallName before candidate path expansion. Because byInstallName was populated for any install name, the second loader erroneously bound to the first loader's resolved copy or appeared resolved even when its own copy was absent.

Apple dyld (Loader.cpp:802-816) reuses already-loaded images by install name only for @rpath/ dependencies; caller-relative and literal dependencies are evaluated against their expanded candidate paths for each loader. Limit byInstallName registration and lookup to install names starting with @rpath/.

No existing issue covers this.

Problem and expected behavior

In src/domain/apple/dylibResolution.ts, resolveDependency consults context.byInstallName.get(dependency.install_name) before expanding candidate paths. When traceProcess loads an image whose slice has an install name, it registers context.byInstallName.set(slice.install_name, image).

Consider an application bundling two plugins in separate directories:

  • Contents/PlugIns/A/pluginA.dylib depending on @loader_path/libhelper.dylib
  • Contents/PlugIns/B/pluginB.dylib depending on @loader_path/libhelper.dylib

When pluginA.dylib loads, REA resolves @loader_path/libhelper.dylib to Contents/PlugIns/A/libhelper.dylib and registers @loader_path/libhelper.dylib -> Contents/PlugIns/A/libhelper.dylib in byInstallName. When pluginB.dylib is later evaluated, resolveDependency finds @loader_path/libhelper.dylib in byInstallName and immediately binds pluginB's dependency to Contents/PlugIns/A/libhelper.dylib without expanding candidate paths relative to pluginB's directory. If Contents/PlugIns/B/libhelper.dylib is absent, REA reports the dependency as resolved rather than emitting a required-load-unresolved finding.

Expected behavior: dyld reuses already-loaded images by install name only for @rpath/ dependencies. @loader_path/, @executable_path/, and literal dependencies expand candidate paths for each loader; identical images reached through identical paths are deduplicated once resolved.

Change and scope

  • In src/domain/apple/dylibResolution.ts: limit context.byInstallName lookup in resolveDependency to dependencies whose install_name starts with @rpath/. Limit context.byInstallName.set registration in traceProcess to slices whose install_name starts with @rpath/.
  • In docs/apple-application-analysis.md and src/domain/apple/dylibResolutionFindings.ts: update the documentation and limitation text to state that already-loaded reuse by install name applies to @rpath requests.
  • In src/domain/apple/dylibResolution.test.ts: add regression tests asserting that @loader_path dependencies across isolated directories do not reuse already-loaded images by install name, reporting required-load-unresolved when the second helper is absent and resolving to each loader's own directory when both exist.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Mach-O dependency resolution in src/domain/apple/dylibResolution.ts.
  • CLI and MCP/tool-catalog contract: unchanged schemas.
  • Provider, bridge, target-format, or platform compatibility: Apple dyld resolution semantics across macOS bundles.
  • Evidence, artifact, provenance, or reconstruction contract: trace_dylib_resolution candidate paths and resolution status reflect each loader's own directory for @loader_path/ dependencies.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: src/domain/apple/dylibResolution.test.ts adds tests under describe("loader-relative dylib resolution") verifying that @loader_path/ dependencies in isolated directories do not reuse already-loaded images by install name, both when the second loader's helper is absent and when each loader has its own helper.
  • Base reproduction or other evidence: on the base revision, pluginB's dependency resolves to Contents/PlugIns/A/libhelper.dylib even when Contents/PlugIns/B/libhelper.dylib is absent, and no required-load-unresolved finding is produced.
  • User-visible CLI/MCP output (if applicable): before, false-positive resolution of loader-relative dependencies across directories; after, correct candidate evaluation and required-load-unresolved finding when the target directory lacks the dependency.
  • Remaining proof gaps: tests were verified by source inspection; CI executes the test suite.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • No local commands were run: verification is source-derived; CI runs the deterministic suite.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no added process authority or external dependencies.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

dyld reuses an already-loaded image by install name only for @rpath/
dependencies (Loader.cpp:802-816) and evaluates other dependency forms
against their expanded path for each loader. When multiple images in
different directories depend on @loader_path/ libraries sharing an
install name, checking loaded images before candidate expansion caused
subsequent loaders to bind to the first loaded image's copy or appear
resolved when their own copy was absent.

Limit byInstallName registration and lookup to install names that start
with @rpath/, leaving caller-relative and literal dependencies to expand
and evaluate their own candidate paths.

Signed-off-by: Vinícius DS Andrade <95101505+viniciusdsandrade@users.noreply.github.com>
Assert that multiple images depending on @loader_path/ libraries with
the same install name do not reuse already-loaded images across loaders.
When the second loader's helper is absent, its candidate path is absent
and dyld reports required-load-unresolved; when both helpers exist, each
loader resolves to its own directory.

Signed-off-by: Vinícius DS Andrade <95101505+viniciusdsandrade@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

Limits reuse by install name to @rpath/ requests. Other requests resolve their candidate paths separately, while resolved images still load once per process.

  • Loader-relative dylibs resolve from each loader's own folder.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Dependency request] --> B{Starts with @rpath/?}
  B -->|Yes| C{Install name already loaded?}
  C -->|Yes| D[Reuse loaded image]
  C -->|No| E[Expand and check candidate paths]
  B -->|No| E
  E --> F{Candidate resolves?}
  F -->|No| G[Report unresolved or uncertain result]
  F -->|Yes| H{Resolved image already loaded?}
  H -->|Yes| I[Keep edge without loading again]
  H -->|No| J[Record image and visit dependencies]
Loading

Reviews (1) · Last reviewed commit: "test(apple): verify loader_path dependen..." · Reviewed by Greptile

@morluto
morluto merged commit 60f771a into morluto:main Oct 13, 2026
31 checks passed
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants