Skip to content

Commit 7fdc148

Browse files
committed
added support for s390x target features soft-float and packed-stack
1 parent d9617c8 commit 7fdc148

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ fn backchain_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll Attrib
311311
if found_positive { Some(llvm::CreateAttrString(cx.llcx, "backchain")) } else { None }
312312
}
313313

314+
fn packed_stack_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll Attribute> {
315+
if sess.target.arch != Arch::S390x {
316+
return None;
317+
}
318+
319+
if sess.opts.cg.packed_stack {
320+
Some(llvm::CreateAttrString(cx.llcx, "packed-stack"))
321+
} else {
322+
None
323+
}
324+
}
325+
314326
pub(crate) fn target_cpu_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> &'ll Attribute {
315327
let target_cpu = llvm_util::target_cpu(sess);
316328
llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu)
@@ -525,6 +537,10 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
525537
if let Some(backchain) = backchain_attr(cx, sess) {
526538
to_add.push(backchain);
527539
}
540+
if let Some(packed_stack) = packed_stack_attr(cx, sess) {
541+
to_add.push(packed_stack);
542+
}
543+
528544
to_add.extend(patchable_function_entry_attrs(
529545
cx,
530546
sess,

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,8 @@ options! {
21822182
#[rustc_lint_opt_deny_field_access("use `Session::overflow_checks` instead of this field")]
21832183
overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
21842184
"use overflow checks for integer arithmetic"),
2185+
packed_stack: bool = (false, parse_bool, [TRACKED],
2186+
"use packed stack frames (s390x only) (default: no)"),
21852187
#[rustc_lint_opt_deny_field_access("use `Session::panic_strategy` instead of this field")]
21862188
panic: Option<PanicStrategy> = (None, parse_opt_panic_strategy, [TRACKED],
21872189
"panic strategy to compile crate with"),

compiler/rustc_target/src/spec/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,17 @@ impl Target {
32423242
));
32433243
}
32443244
}
3245+
3246+
// If both `packed-stack` and `backchain` are set we need to use soft-float ABI.
3247+
if self.arch == Arch::S390x
3248+
&& features_enabled.contains("packed-stack")
3249+
&& features_enabled.contains("backchain")
3250+
&& matches!(self.llvm_floatabi, Some(FloatAbi::Hard))
3251+
{
3252+
return Err(format!(
3253+
"Enabling both, `packed-stack` and `backchain` attributes is incompatible with the hard-float ABI. Enable soft-float ABI to use these attributes."
3254+
));
3255+
}
32453256
}
32463257

32473258
Ok(())

compiler/rustc_target/src/target_features.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,11 +1211,13 @@ impl Target {
12111211
}
12121212
}
12131213
Arch::S390x => {
1214-
// We don't currently support a softfloat target on this architecture.
1215-
// As usual, we have to reject swapping the `soft-float` target feature.
1216-
// The "vector" target feature does not affect the ABI for floats
1217-
// because the vector and float registers overlap.
1218-
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
1214+
// On s390x only the hard-float ABI is valid. However for kernel compilation we need to
1215+
// allow soft-float if and only if the ABI is explicitly set to soft-float.
1216+
if matches!(self.abi, Abi::SoftFloat) {
1217+
FeatureConstraints { required: &["soft-float"], incompatible: &[] }
1218+
} else {
1219+
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
1220+
}
12191221
}
12201222
_ => NOTHING,
12211223
}

src/doc/rustc/src/codegen-options/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ one of the following values:
487487
If not specified, overflow checks are enabled if
488488
[debug-assertions](#debug-assertions) are enabled, disabled otherwise.
489489

490+
## packed-stack
491+
492+
This flag enables packed StackFrames on s390x.
493+
If backchain is also enabled, switch to the soft-float ABI.
494+
490495
## panic
491496

492497
This option lets you control what happens when the code panics.

0 commit comments

Comments
 (0)