-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
-Zregparm doesn't put 64-bit arguments in registers #145694
Copy link
Copy link
Open
Labels
-ZregparmUnstable option: -ZregparmUnstable option: -ZregparmA-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-rust-for-linuxRelevant for the Rust-for-Linux projectRelevant for the Rust-for-Linux projectC-bugCategory: This is a bug.Category: This is a bug.O-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
-ZregparmUnstable option: -ZregparmUnstable option: -ZregparmA-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-rust-for-linuxRelevant for the Rust-for-Linux projectRelevant for the Rust-for-Linux projectC-bugCategory: This is a bug.Category: This is a bug.O-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The
-Zregparmoption on 32-bit x86 should pass arguments in registers where possible, but for 64-bit arguments, it will push them onto the stack, whereas C compilers (both gcc and clang) will put them in a pair of registers.For example, the following rust code:
compiles to (with
-Zregparm=3):Note the 64-bit value is put on the stack.
However, the equivalent C code:
compiles to (gcc 15.2 with
-mregparm=3, but clang produces something similar):Note that the 64-bit value is put in edx:eax.
This can cause crashes/incorrect results due to an ABI mismatch, particularly in Rust-for-Linux on 32-bit x86.
Note that 64-bit return values seem to be functioning correctly, and are placed in edx:eax.
Compiler explorer link with the above examples: https://godbolt.org/z/feb7addG7
Rust-for-Linux tracking issue for 32-bit x86: Rust-for-Linux/linux#78
Tracking issue for
-Zregparm: #131749