Skip to content

fix(system/os/windows): pin every ext import to its providing DLL#358

Merged
octalide merged 1 commit into
devfrom
fix/334
Jul 3, 2026
Merged

fix(system/os/windows): pin every ext import to its providing DLL#358
octalide merged 1 commit into
devfrom
fix/334

Conversation

@octalide

@octalide octalide commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #334.

What

Every ext fun under src/system/os/windows/ and the windows runtime entrypoint (src/runtime/windows/x86_64.mach) now carries an explicit #[library] decorator naming its providing DLL. Previously the ~61 kernel32 imports were unattributed: they reached the PE writer as DYNLIB_ANY and relied on the COFF fallback binding them to dependency 0, which is correct only while kernel32.dll happens to sort first. The first mixed-DLL consumer (e.g. one also linking glfw3.dll) breaks that implicit ordering contract, mis-binding a whole DLL set and producing STATUS_ENTRYPOINT_NOT_FOUND at load.

The change is purely additive — links that were already ordered correctly are unchanged — and removes the implicit ordering dependency entirely.

Sweep

Exhaustive grep across the windows + runtime trees: 78 ext fun total. 17 were already pinned (14 ws2_32, 2 synch-apiset, 1 advapi32). The remaining 61 kernel32 imports are now pinned. A grep for any ext fun not immediately preceded by a #[library decorator comes back empty.

Obsolete comments documenting the old first-dependency reliance (header, CreateSymbolicLinkA, runtime entrypoint) were updated to match.

Verification

  • mach build . + mach test .: 620 passed, 0 failed (native linux/x86_64).
  • Cross-build for windows-x86_64: succeeds; every windows os/runtime module compiles.
  • Import-directory proof (acceptance Convert all method declarations to C-style prefixed free functions #3). Built a consumer PE with kernel32.dll deliberately placed last in libs (dependency index 3, not 0) and dumped the import directory: all 53 referenced kernel32 imports resolve under kernel32.dll, 14 under ws2_32.dll, 1 under advapi32.dll, 2 under the synch apiset — each attributed to the correct DLL despite the adverse ordering.
  • Falsifiability. Removing a single pin (WriteFile) and rebuilding the same PE re-binds WriteFile to ws2_32.dll (dependency 0) — the exact mis-bind the issue describes. Restoring the pin returns it to kernel32.dll.

every kernel32 import under src/system/os/windows/ and the windows
runtime entrypoint was unattributed, reaching the PE writer as
DYNLIB_ANY and relying on the COFF fallback binding it to dependency 0
(kernel32.dll only when kernel32 sorts first). the first mixed-DLL
consumer breaks that implicit ordering contract, mis-binding a whole
DLL set and yielding STATUS_ENTRYPOINT_NOT_FOUND at load.

pin each ext import with an explicit #[library] decorator naming its
providing DLL, removing the ordering dependency. purely additive:
correctly-ordered links are unchanged.

Closes #334
@octalide octalide marked this pull request as ready for review July 3, 2026 13:15
@octalide octalide merged commit 533dc5d into dev Jul 3, 2026
3 checks passed
@octalide octalide deleted the fix/334 branch July 3, 2026 13:16
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.

system/os/windows: pin every unpinned import with #[library] — kernel32 binding rides dependency-0 ordering

1 participant