Skip to content

Conversation

@leonardocxavier
Copy link

@leonardocxavier leonardocxavier commented Dec 22, 2025

Summary

This PR fixes a critical bug introduced in PR #150116 that causes linker errors on PE/COFF targets (e.g., x86_64-unknown-uefi):

error: offset is not a multiple of 16

Problem

PR #150116 optimized memory layout by inverting the storage representation from memory_index (source→memory) to in_memory_order (memory→source).

However, in compiler/rustc_abi/src/layout/coroutine.rs (lines 244-276), the code was building combined_in_memory_order directly instead of:

  1. Building combined_memory_index (source→memory) first
  2. Inverting it to get in_memory_order (memory→source)

This caused fields to be placed at incorrect offsets, violating PE/COFF alignment requirements (16-byte multiples).

Solution

Changed the coroutine layout code to:

  • Build combined_memory_index as an intermediate representation
  • Use correct indexing: combined_memory_index[i] = memory_index
  • Invert at the end: combined_in_memory_order = combined_memory_index.invert_bijective_mapping()

Testing

Verified that rustc_abi compiles successfully with this fix.

Impact

  • Fixes UEFI target compilation (x86_64-unknown-uefi)
  • May affect other PE/COFF targets
  • No performance impact (logical fix only)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@leonardocxavier
Copy link
Author

solving issues

PR rust-lang#150116 introduced a bug in coroutine variant layout by incorrectly
keeping the direct construction of `in_memory_order` without adapting
it to the new representation.

Before PR rust-lang#150116, the code correctly built an inverse mapping indexed
by memory position, then inverted it to get the memory_index.

After PR rust-lang#150116, the code still built the mapping indexed by memory
position (as if it were an inverse mapping), but treated it directly as
`in_memory_order` without inversion. This caused incorrect field ordering.

The bug manifested as linker errors on PE/COFF targets (e.g., x86_64-unknown-uefi):
  error: offset is not a multiple of 16

And as ICEs with non-bijective mapping assertions in other cases.

Fix by correctly keeping the inverse memory index construction (indexed
by memory position), then using it directly as `in_memory_order` since
that's what the new representation expects.
@leonardocxavier leonardocxavier force-pushed the fix-coroutine-memory-index-bug branch from 936dc7d to 557616b Compare December 22, 2025 16:40
@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2025

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@lqd
Copy link
Member

lqd commented Dec 22, 2025

This looks like #150266 which was closed for not matching our contribution policy 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants