-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix varargs support on aarch64-apple-darwin
#1500
Conversation
src/abi/mod.rs
Outdated
&& fn_sig.c_variadic() | ||
// No need to pad the argument list unless vardiac arguments are actually being passed. | ||
&& args.len() > fixed_arg_count | ||
{ |
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.
This is a lot of code here. Would it be possible to move it to the if fn_sig.c_variadic() {
if statement after emitting the call inst? Basically the idea would be to modify the argument list of the call instruction and splice extra arguments in. You can probably use func.dfg.overwrite_inst_values
, taking care to account for the first arg of call_indirect
being the function pointer rather than a call arguments. This would keep all vararg hacks in a single place which can easily be removed once Cranelift lands real vararg support.
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.
Unfortunately overwrite_inst_values
doesn't allow changing the number of Value
s. As most of the block in the closure passed to codegen_with_call_return_arg
is handling varargs, I've left a comment at the top of it stating which bits aren't hacky workarounds for Cranelift's lack of C varargs support.
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.
I see. Maybe match func.stencil.dfg.inst[call_inst] { InstructionData::Call { args } => { ... }, InstructionData::CallIndirect { args, ... } => { ... }
with args.insert(index, zero, &mut func.stencil.dfg.value_lists)
to actually add the arguments would work? If not what you have right now is fine as is.
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.
I've refactored all the C varargs handling into a dedicated adjust_call_for_c_variadic
function that gets called just before the call instruction is generated.
Thanks a lot for this PR! While this is a big hack, so is the rest of the vararg support in cg_clif, so I don't see it as a reason to reject this PR. I would like to see all parts of the vararg support hack to be placed together though. Also if you don't mind, could you ask a CI job for aarch64-apple-darwin to test it? This should be a matter of duplicating the block at rustc_codegen_cranelift/.github/workflows/main.yml Lines 57 to 59 in 1cb7282
TARGET_TRIPLE . You can also do the same at rustc_codegen_cranelift/.github/workflows/main.yml Lines 214 to 216 in 1cb7282
|
2d1255e
to
a0341ee
Compare
I've added a dist CI job (I'd already added a PR CI job). While testing the implementation, I noticed a pre-existing bug: when fixing the signature of a C variadic function to match its arguments, the implementation used to blanket overwrite all the |
a0341ee
to
1321af5
Compare
I've fixed it so it now uses |
1321af5
to
ca9381f
Compare
ca9381f
to
b0fcf2e
Compare
@beetrees I want to post an announcement on Mastodon. Do you want me to credit you as @\beetrees? |
Yes, that would be great. Thanks. |
Uses the strategy outlined in #1451 (comment) to enable support for varargs functions with integer/pointer arguments on
aarch64-apple-darwin
. CI testing is also added foraarch64-apple-darwin
.