-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
added support for s390x target features soft-float and packed-stack
#150766
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: main
Are you sure you want to change the base?
Conversation
|
These commits modify compiler targets. |
|
r? @nnethercote rustbot has assigned @nnethercote. Use |
7fdc148 to
30628ca
Compare
| ## packed-stack | ||
|
|
||
| This flag enables packed StackFrames on s390x. | ||
| If backchain is also enabled, switch to the soft-float ABI. |
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 think this should say something about allowed values and what the default is. (if only for consistency).
Also i like your phrasing from above better: enabling both packed-stack and backchain is incompatible with hard-float, but is compatible with soft-float. The current text could be read to mean that soft-float would be switched to automatically.
| // On s390x only the hard-float ABI is valid. However for kernel compilation we need to | ||
| // allow soft-float if and only if the ABI is explicitly set to soft-float. |
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.
Does this refer to the linux kernel? Also I feel like this mixes up the SoftFloat ABI and the soft-float feature, maybe you can clarify which way the implication goes?
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.
Having flags that change ABI is a problem because everything quietly breaks if you don't rebuild the world (among other problems); I don't think we want to add this to any more targets, we're trying to rip it out. See context at #116344, cc @RalfJung.
The thing to do is to submit an MCP to create a new separate -softfloat target, like we have with aarch64-unknown-none-softfloat, loongarch64-unknown-none-softfloat, x86_64-unknown-none (softfloat is implied there), and others.
|
Reminder, once the PR becomes ready for a review, use |
| FeatureConstraints { required: &[], incompatible: &["soft-float"] } | ||
| // On s390x only the hard-float ABI is valid. However for kernel compilation we need to | ||
| // allow soft-float if and only if the ABI is explicitly set to soft-float. | ||
| if matches!(self.abi, Abi::SoftFloat) { |
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.
self.abi is just used for cfg(target_abi), it doesn't actually control the ABI.
It looks like s390x is just as bad as x86 when it comes to ABI handling so the logic should probably be similar?
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.
there is only one valid abi on s390x. This ABI uses hard-float.
The idea is that soft-floatremains incompatible unless the user explicitly requests to use the soft-float abi(e.g.1). This will not change the abi, as there is no other ABI specified. And to my knowledge there wont be a soft-float abi specified that really could be used by llvm.
It is used as a gate, so if you want to use soft-float you also have to explicitly change the ABI. And make it clear that this code is incompatible with the normal code.
Footnotes
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 will not change the abi, as there is no other ABI specified.
What exactly do you mean by this - floats still get passed in vregs even with soft-float? What does the flag do then?
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.
There might only be one official ABI, but the soft-float ABI is real and we're not going to pretend that it isn't. The soft-float ABI is whatever LLVM does to pass float args across function barriers when the soft-float target feature is on. So there might be no specification for such an ABI, but that doesn't stop LLVM from using it.
That's what happened on x86, anyway. I suspect it is similar on s390x.
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.
so if you want to use soft-float you also have to explicitly change the ABI.
Exactly. But self.abi does not change the ABI, it just tells cfg what the ABI is. llvm_abiname, llvm_floatabi, and rustc_abi change the ABI.
(Well, that's not entirely true. self.abi actually is used in some places in the ABI adjustment logic. It's all a bit messy unfortunately...)
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.
Note that further up this file it still says
("soft-float", Forbidden { reason: "currently unsupported ABI-configuration feature" }, &[]),So using the soft-float target feature still doesn't work even with this PR.
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.
On that note, it would be great to have codegen tests for these kind of flags.
| } | ||
|
|
||
| if sess.opts.cg.packed_stack { | ||
| Some(llvm::CreateAttrString(cx.llcx, "packed-stack")) |
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.
What are the ABI considerations for this flag? Is it possible to freely mix code built with and without this flag? If not, it needs to be made a "target modifier" to avoid unsoundness.
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.
yes packed-stack and non packed stack code can be mixed. It just affects the calling code and not the called code.
| overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED], | ||
| "use overflow checks for integer arithmetic"), | ||
| packed_stack: bool = (false, parse_bool, [TRACKED], | ||
| "use packed stack frames (s390x only) (default: no)"), |
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.
It's bad UI to just silently ignore the flag for targets where it does not make sense. Please ensure it raises an error instead.
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
I don't know anything about this stuff, so I will hand this over to a target maintainer: r? @cuviper |
|
cc @uweigand, in case you're available to look at this, otherwise I'll try to review it soon. |
as we want to enable
rust in kernelon s390x we need to do some things:-packed-stackrustcoption. this adds thepacked-stackfunction-attribute to every function call. I implemented it the same way as it is implemented in clang12. In clang this is a cli argument. It is not a part of the target feature. Therefore we cannot pass it via thefeaturesfield in thetarget.json.packed-stack && backchain** && !soft-floatas this combination should never occur. However I don't know if I put it in the right spot. 3Footnotes
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mpacked-stack ↩
https://github.com/llvm/llvm-project/blob/release/20/clang/lib/CodeGen/CodeGenFunction.cpp#L1202-L1208 ↩
compiler/rustc_target/src/spec/mod.rs ↩