-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rust_for_linux: -Zreg-struct-return commandline flag for X86 (#116973) #130777
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
ad600b5
to
d5888d4
Compare
This comment has been minimized.
This comment has been minimized.
d5888d4
to
0bb5469
Compare
This comment has been minimized.
This comment has been minimized.
cc @ojeda |
0bb5469
to
c8970c5
Compare
Some changes occurred in compiler/rustc_codegen_gcc These commits modify compiler targets. |
tests/codegen/reg-struct-return.rs
Outdated
// reg-struct-return doesn't work for "Rust" calling conv | ||
// CHECK: { i32, i32 } @f2() | ||
#[no_mangle] | ||
pub extern "Rust" fn f2() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't it work for the Rust calling convention? Is that what we want? I assume that there's a reason we use this flag, but I don't know whether it's just a question of performance or if it's an important mitigation.
@andyhhp Do you know if this matters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At technical level, "external" abi's are processed a little in different way (another place in code). It is not a big problem to support the same behavior for "Rust" calling conv, I just need to know if it is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't it work for the Rust calling convention? Is that what we want? I assume that there's a reason we use this flag, but I don't know whether it's just a question of performance or if it's an important mitigation.
@andyhhp Do you know if this matters?
Rust and C need to agree on how to return >GPR sized values, if this happens to be used in either direction.
Whether that is via some bindings using the Rust calling conventions is something I can't answer.
The use of >GPR sized return values is rare in C because it's irritating to set up. You need a struct/typedef with a fairly precise layout, but the code generation improvements are substantial, hence why they do get used occasionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Rust ABI is not stable. C should not call an extern "Rust" fn
. This matters for extern "C" fn
and a few others. And reusing this code, tuned for extern "C"
and other foreign ABIs, for Rust ABI code? Proved incapable of compiling libcore in #130432.
We're not going to be scope-creeping this PR into extern "Rust"
. That can be addressed alongside the extensive cleanups of our ABI code that it will require.
c8970c5
to
44fec08
Compare
This comment has been minimized.
This comment has been minimized.
44fec08
to
7e72e24
Compare
Cc @vincenzopalazzo who was interested in this. |
7e72e24
to
8413bba
Compare
☔ The latest upstream changes (presumably #131458) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm not in capacity to review this. |
d74321c
to
491526e
Compare
I have mutated #116973 into a tracking issue for this, so we do not need to open another one. |
☔ The latest upstream changes (presumably #132020) made this pull request unmergeable. Please resolve the merge conflicts. |
491526e
to
8fedf94
Compare
☔ The latest upstream changes (presumably #132079) made this pull request unmergeable. Please resolve the merge conflicts. |
compiler/rustc_ty_utils/src/abi.rs
Outdated
let is_indirect_not_on_stack = !matches!(arg.layout.abi, Abi::Aggregate { .. }) | ||
|| matches!(arg.mode, PassMode::Indirect { on_stack: false, .. }); | ||
assert!(is_indirect_not_on_stack, "is_indirect_not_on_stack: {:?}", arg); | ||
|
||
let size = arg.layout.size; | ||
if !arg.layout.is_unsized() && size <= Pointer(AddressSpace::DATA).size(cx) { | ||
let ptr_size = Pointer(AddressSpace::DATA).size(cx); | ||
|
||
// In x86 we may return 2x pointer sized struct as i64 | ||
let reg_struct_return_case = tcx.sess.target.arch == "x86" | ||
&& arg_idx.is_none() | ||
&& tcx.sess.opts.unstable_opts.reg_struct_return | ||
&& abi != SpecAbi::RustIntrinsic; | ||
|
||
if !arg.layout.is_unsized() | ||
&& (size <= ptr_size || (reg_struct_return_case && (size <= 2 * ptr_size))) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of this code has moved into rustc_target
.
8fedf94
to
f3eef25
Compare
Reverted changes for "Rust" calling conv (flag works only for extern "C"-like calling conventions). Added unstable-book record, error about wrong arch and related test. |
Command line flag
-Zreg-struct-return
for X86 (32-bit) for rust-for-linux.This flag enables the same behavior as the
abi_return_struct_as_int
target spec key.-Zreg-struct-return
support inrustc
#116973