Repository navigation
fix(relinker): stop running a guest module's preinit array from the startup stubs - #579
Conversation
…tartup stubs A converted guest module's initializer is the console CRT entry, which walks DT_PREINIT_ARRAY itself. The macOS, Linux and Windows startup stubs also ran the array before that initializer, so every preinit entry ran twice. A module that registers a thread destructor callback from a preinit entry aborted on the second registration. This reverts the startup-stub execution added for the preinit array and drops the reader's copy of the array, matching the upstream revert. The unused-NID filter still collects the preinit targets as roots. guest_preinit_once covers the contract: it fails while a macOS startup stub still calls the preinit slots, and asserts a single run of each entry where native execution is available.
|
@codex review |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa263edf49
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| }; | ||
| readLifecycleArray(32, 33, image.PreInitArray); | ||
| readLifecycleArray(25, 27, image.InitArray); |
There was a problem hiding this comment.
Keep validating the preinit array before discarding it
When a guest has a non-empty DT_PREINIT_ARRAY with a malformed size/address or a relocation targeting mapped but non-executable data, the generic relocation checks can accept it; this removed call was the only path through readLifecycleArray that enforced the array layout, mapping, and executable function targets. Because initialization now relies on the guest's DT_INIT routine to invoke these entries, conversion succeeds but can fault during initialization instead of rejecting the invalid module. Keep this validation even if the collected slot RVAs are no longer stored.
Useful? React with 👍 / 👎.
What
A converted guest module's initializer is the console CRT entry, which walks
DT_PREINIT_ARRAYitself. The macOS, Linux and Windows startup stubs also ran the array before that initializer, so every preinit entry ran twice. A module that registers a thread destructor callback from a preinit entry aborted on the second registration (ThreadLifecycle::SetThreadDtorsthrowsThread destructor callback is already registered), inside dyld initializers at 0.5 s of guest time.This reverts the startup-stub execution of the preinit array and drops the reader's copy of the array, matching the upstream revert of boykopovar#6112. The unused-NID filter still collects the preinit targets as roots, so the entries stay in the image.
guest_preinit_oncecovers the contract. It builds a module whoseDT_INITwalks the preinit array (the CRT pattern), relinks it, and asserts no macOS startup stub calls the preinit slots. It also asserts a single run of each entry where native execution is available. It fails against the published engine's relinker (both preinit slots present in the macOS stub) and passes after the change.Tested
macOS 26.x, Apple Silicon, relinker-only build with
BUILD_TESTING=ON:guest_preinit_once: fails against the pre-fix relinker (macOS stub calls both preinit slots), passes after the change.check_conventions.py --base origin/main: all checks pass.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository