about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-10-24 12:16:33 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-02-20 17:45:28 +0000
commitb03b41420b2dc900a9db019f4b5a5c22c05d2bb8 (patch)
treecc718040f89d2abe8e50f547c6ac1b7845f75548
parentc7a50c26367f3d1d614d5ae647f9c86919c8f422 (diff)
downloadrust-b03b41420b2dc900a9db019f4b5a5c22c05d2bb8.tar.gz
rust-b03b41420b2dc900a9db019f4b5a5c22c05d2bb8.zip
Fix stack alignment problem on s390x
-rw-r--r--patches/0023-coretests-Ignore-failing-tests.patch26
-rw-r--r--src/common.rs17
2 files changed, 12 insertions, 31 deletions
diff --git a/patches/0023-coretests-Ignore-failing-tests.patch b/patches/0023-coretests-Ignore-failing-tests.patch
deleted file mode 100644
index 385f5a8a2e0..00000000000
--- a/patches/0023-coretests-Ignore-failing-tests.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From dd82e95c9de212524e14fc60155de1ae40156dfc Mon Sep 17 00:00:00 2001
-From: bjorn3 <bjorn3@users.noreply.github.com>
-Date: Sun, 24 Nov 2019 15:34:06 +0100
-Subject: [PATCH] [core] Ignore failing tests
-
----
- library/core/tests/iter.rs       |  4 ++++
- library/core/tests/num/bignum.rs | 10 ++++++++++
- library/core/tests/num/mod.rs    |  5 +++--
- library/core/tests/time.rs       |  1 +
- 4 files changed, 18 insertions(+), 2 deletions(-)
-
-diff --git a/atomic.rs b/atomic.rs
-index 13b12db..96fe4b9 100644
---- a/atomic.rs
-+++ b/atomic.rs
-@@ -185,6 +185,7 @@ fn ptr_bitops() {
- }
- 
- #[test]
-+#[cfg_attr(target_arch = "s390x", ignore)] // s390x backend doesn't support stack alignment >8 bytes
- #[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
- fn ptr_bitops_tagging() {
-     #[repr(align(16))]
--- 
-2.21.0 (Apple Git-122)
diff --git a/src/common.rs b/src/common.rs
index 1e37825b548..323f2bca5a8 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -388,18 +388,25 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
     }
 
     pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
-        if align <= 16 {
+        let abi_align = if self.tcx.sess.target.arch == "s390x" { 8 } else { 16 };
+        if align <= abi_align {
             let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
                 kind: StackSlotKind::ExplicitSlot,
-                // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to
-                // specify stack slot alignment.
-                size: (size + 15) / 16 * 16,
+                // FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
+                // a way to specify stack slot alignment.
+                size: (size + abi_align - 1) / abi_align * abi_align,
             });
             Pointer::stack_slot(stack_slot)
         } else {
             // Alignment is too big to handle using the above hack. Dynamically realign a stack slot
             // instead. This wastes some space for the realignment.
-            let base_ptr = self.create_stack_slot(size + align, 16).get_addr(self);
+            let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
+                kind: StackSlotKind::ExplicitSlot,
+                // FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
+                // a way to specify stack slot alignment.
+                size: (size + align) / abi_align * abi_align,
+            });
+            let base_ptr = self.bcx.ins().stack_addr(self.pointer_type, stack_slot, 0);
             let misalign_offset = self.bcx.ins().urem_imm(base_ptr, i64::from(align));
             let realign_offset = self.bcx.ins().irsub_imm(misalign_offset, i64::from(align));
             Pointer::new(self.bcx.ins().iadd(base_ptr, realign_offset))