-
Notifications
You must be signed in to change notification settings - Fork 13.8k
x86: Correctly pass larger structs/types in registers with -Zregparm #147628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Fixes rust-lang#145694. The -Zregparm option for 32-bit x86 modifies the calling convention to pass a number of arguments in registers instead of on the stack. (This is primarily used by the Linux kernel.) Currently, rustc will only pass primitive integer types in registers, which seems to match the gcc documentation[1], which says that arguments "of integral type" are passed as registers. This also matches the fastcall and vectorcall conventions on windows. However, it seems that _any_ type — most particularly structs — should be passed as a register if possible. This matches what clang and gcc do, and so avoids an ABI mismatch when linking with C code (which, after all, is the whole point of supporting -Zregparm).
rustbot has assigned @jdonszelmann. Use |
|
The |
If this fixes that issue, I'd love to see a test for that issue which now passes. At least some amount of testing seems wise. I'm aware this is an unstable option I know little about otherwise, but since there is a specific test failing, I think adding it as a test is the least we can do before merging this fix so we won't forget about this failure in the future. |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
Fixes #145694. I think this should be the last compiler fix needed to unblock 32-bit x86 support for Rust-for-linux (Rust-for-Linux/linux#78)
Tracking issue for -Zregparm: #131749
The -Zregparm option for 32-bit x86 modifies the calling convention to pass a number of arguments in registers instead of on the stack. (This is primarily used by the Linux kernel.)
Currently, rustc will only pass primitive integer types in registers, which seems to match the gcc documentation[1], which says that arguments "of integral type" are passed as registers. This also matches the fastcall and vectorcall conventions on windows.
However, it seems that any type — most particularly structs — should be passed as a register if possible. This matches what clang and gcc do, and so avoids an ABI mismatch when linking with C code (which, after all, is the whole point of supporting -Zregparm).
Note that I haven't tested this particularly thoroughly outside the Linux kernel usecase, and in particular haven't tried to implement any 'assembly-llvm' tests, nor test for regressions against fastcall/vectorcall.