Skip to content

Conversation

@Arshia001
Copy link
Member

This PR fixes the initialization order for main modules in the linker.

Previously, the main function's relocations would run before pending globals were resolved, which would result in the main module reading incorrect values while applying its relocations.

@Arshia001 Arshia001 requested review from Copilot and zebreus October 31, 2025 11:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the main module linking process by extracting initialization logic into a separate method. The change improves code structure by allowing the main module and side modules to share the same initialization code path.

Key changes:

  • Extracts module initialization logic into a new initialize_new_modules method
  • Refactors finalize_link_operation to call the new initialize_new_modules method
  • Updates main module linking to directly call finalize_pending_globals and initialize_new_modules instead of the combined finalize_link_operation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@zebreus zebreus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You split up finalize_link_operation into finalize_link_operation and initialize_new_modules, because the relocation functions need to be called after finalizing the globals. Seems like the correct fix for the issue

@Arshia001 Arshia001 merged commit 3d21acf into main Oct 31, 2025
182 of 183 checks passed
@Arshia001 Arshia001 deleted the fix/linker-main-initialization-order branch October 31, 2025 13:35
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.

3 participants