Skip to content

Resolve a delay loaded library's dependencies from its own directory - #22

Merged
bavulapati merged 1 commit into
mainfrom
windows-dependency-search-path
Aug 20, 2026
Merged

Resolve a delay loaded library's dependencies from its own directory#22
bavulapati merged 1 commit into
mainfrom
windows-dependency-search-path

Conversation

@bavulapati

@bavulapati bavulapati commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

bare__module_load builds an absolute path to a library installed next to the addon and calls LoadLibraryA. That finds the named library, but its dependencies resolve through the ambient search order, which excludes the directory it came from. A bundled library depending on a sibling is found only if the current directory or PATH covers it. When neither does - always, for a packaged MSIX app - the delay load helper raises 0xC06D007E and the process exits with nothing to catch.

macOS and Linux are unaffected: the addon carries an @loader_path / $ORIGIN runpath, and PE has no equivalent.

The fix is LoadLibraryExA with LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR, which the loader also applies to that library's dependencies, plus LOAD_LIBRARY_SEARCH_DEFAULT_DIRS. That drops the current directory and PATH from the search; LOAD_WITH_ALTERED_SEARCH_PATH is the additive alternative.

test/fixtures/transitive-dependency covers what runtime-dependency misses: it installs a library but never references it. On win32-arm64 the process exits 0xC06D007E before the change and the suite is 6/6 after; also 6/6 on darwin-arm64.

Found from holepunchto/bare-collabora#28.

LoadLibraryA locates the named library by absolute path but resolves that
library's own dependencies through the ambient search order, which never
includes the directory it was loaded from. A bundled library that depends on a
sibling then dies with a 0xC06D007E delay load exception once the process has
no current directory or PATH entry that happens to cover it.
@bavulapati
bavulapati requested a review from a team August 20, 2026 15:32

@kasperisager kasperisager 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.

Nice! 👌

@kasperisager kasperisager 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.

Wrong radio button 🤦

@bavulapati
bavulapati merged commit 0e947e0 into main Aug 20, 2026
11 of 20 checks passed
@bavulapati
bavulapati deleted the windows-dependency-search-path branch August 20, 2026 16:11
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.

2 participants