From 6eec89a42b2e69642c912aa5fd6d432d7b15a499 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 31 Aug 2017 13:38:34 -0700 Subject: [PATCH 1/2] Update to 1.20.0. Add a rust-src subpackage. --- .gitignore | 8 ++ rust-1.19.0-43072-stack-guard.patch | 80 ------------------- ....20.0-44203-exclude-compiler-rt-test.patch | 28 +++++++ rust.spec | 55 ++++++++----- sources | 2 +- sources-bootstrap | 16 ++-- 6 files changed, 79 insertions(+), 110 deletions(-) delete mode 100644 rust-1.19.0-43072-stack-guard.patch create mode 100644 rust-1.20.0-44203-exclude-compiler-rt-test.patch diff --git a/.gitignore b/.gitignore index 412c8d9..4b73176 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,11 @@ /rust-1.18.0-powerpc64-unknown-linux-gnu.tar.gz /rust-1.18.0-s390x-unknown-linux-gnu.tar.gz /rust-1.18.0-x86_64-unknown-linux-gnu.tar.gz +/rustc-1.20.0-src.tar.xz +/rust-1.19.0-aarch64-unknown-linux-gnu.tar.xz +/rust-1.19.0-armv7-unknown-linux-gnueabihf.tar.xz +/rust-1.19.0-i686-unknown-linux-gnu.tar.xz +/rust-1.19.0-powerpc64le-unknown-linux-gnu.tar.xz +/rust-1.19.0-powerpc64-unknown-linux-gnu.tar.xz +/rust-1.19.0-s390x-unknown-linux-gnu.tar.xz +/rust-1.19.0-x86_64-unknown-linux-gnu.tar.xz diff --git a/rust-1.19.0-43072-stack-guard.patch b/rust-1.19.0-43072-stack-guard.patch deleted file mode 100644 index 137eaf3..0000000 --- a/rust-1.19.0-43072-stack-guard.patch +++ /dev/null @@ -1,80 +0,0 @@ -From 1d5e3cd80b66a3abd274107e75854476c603617d Mon Sep 17 00:00:00 2001 -From: Josh Stone -Date: Wed, 5 Jul 2017 12:03:17 -0700 -Subject: [PATCH] Skip the main thread's manual stack guard on Linux - -Linux doesn't allocate the whole stack right away, and the kernel has -its own stack-guard mechanism to fault when growing too close to an -existing mapping. If we map our own guard, then the kernel starts -enforcing a rather large gap above that, rendering much of the possible -stack space useless. - -Instead, we'll just note where we expect rlimit to start faulting, so -our handler can report "stack overflow", and trust that the kernel's own -stack guard will work. - -Fixes #43052. ---- - src/libstd/sys/unix/thread.rs | 44 ++++++++++++++++++++++++++++--------------- - 1 file changed, 29 insertions(+), 15 deletions(-) - -diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs -index 1642baa34d63..15747746611c 100644 ---- a/src/libstd/sys/unix/thread.rs -+++ b/src/libstd/sys/unix/thread.rs -@@ -264,23 +264,37 @@ pub mod guard { - as *mut libc::c_void; - } - -- // Rellocate the last page of the stack. -- // This ensures SIGBUS will be raised on -- // stack overflow. -- let result = mmap(stackaddr, psize, PROT_NONE, -- MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0); -- -- if result != stackaddr || result == MAP_FAILED { -- panic!("failed to allocate a guard page"); -- } -- -- let offset = if cfg!(any(target_os = "linux", target_os = "freebsd")) { -- 2 -+ if cfg!(target_os = "linux") { -+ // Linux doesn't allocate the whole stack right away, and -+ // the kernel has its own stack-guard mechanism to fault -+ // when growing too close to an existing mapping. If we map -+ // our own guard, then the kernel starts enforcing a rather -+ // large gap above that, rendering much of the possible -+ // stack space useless. See #43052. -+ // -+ // Instead, we'll just note where we expect rlimit to start -+ // faulting, so our handler can report "stack overflow", and -+ // trust that the kernel's own stack guard will work. -+ Some(stackaddr as usize) - } else { -- 1 -- }; -+ // Reallocate the last page of the stack. -+ // This ensures SIGBUS will be raised on -+ // stack overflow. -+ let result = mmap(stackaddr, psize, PROT_NONE, -+ MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0); -+ -+ if result != stackaddr || result == MAP_FAILED { -+ panic!("failed to allocate a guard page"); -+ } - -- Some(stackaddr as usize + offset * psize) -+ let offset = if cfg!(target_os = "freebsd") { -+ 2 -+ } else { -+ 1 -+ }; -+ -+ Some(stackaddr as usize + offset * psize) -+ } - } - - #[cfg(target_os = "solaris")] --- -2.13.3 - diff --git a/rust-1.20.0-44203-exclude-compiler-rt-test.patch b/rust-1.20.0-44203-exclude-compiler-rt-test.patch new file mode 100644 index 0000000..eac112a --- /dev/null +++ b/rust-1.20.0-44203-exclude-compiler-rt-test.patch @@ -0,0 +1,28 @@ +From 35f8a2065b7d17d39481a75cefa739df7a061084 Mon Sep 17 00:00:00 2001 +From: Josh Stone +Date: Wed, 30 Aug 2017 18:20:59 -0700 +Subject: [PATCH] rustbuild: update the rust-src filter for compiler-rt + +We wanted `src/compiler-rt/test` filtered from the `rust-src` package, +but that path is now `src/libcompiler_builtins/compiler-rt/test`. This +saves over half of the installed rust-src size. (50MB -> 22MB) +--- + src/bootstrap/dist.rs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs +index 746f85a9d59d..05d59e7d5956 100644 +--- a/src/bootstrap/dist.rs ++++ b/src/bootstrap/dist.rs +@@ -562,7 +562,7 @@ impl Step for Src { + "src/libprofiler_builtins", + ]; + let std_src_dirs_exclude = [ +- "src/compiler-rt/test", ++ "src/libcompiler_builtins/compiler-rt/test", + "src/jemalloc/test/unit", + ]; + +-- +2.13.5 + diff --git a/rust.spec b/rust.spec index e50bc4f..f4b2522 100644 --- a/rust.spec +++ b/rust.spec @@ -8,10 +8,10 @@ # To bootstrap from scratch, set the channel and date from src/stage0.txt # e.g. 1.10.0 wants rustc: 1.9.0-2016-05-24 # or nightly wants some beta-YYYY-MM-DD -%global bootstrap_rust 1.18.0 -%global bootstrap_cargo 0.19.0 +%global bootstrap_rust 1.19.0 +%global bootstrap_cargo 0.20.0 %global bootstrap_channel %{bootstrap_rust} -%global bootstrap_date 2017-06-08 +%global bootstrap_date 2017-07-20 # Only the specified arches will use bootstrap binaries. #global bootstrap_arches %%{rust_arches} @@ -47,8 +47,8 @@ Name: rust -Version: 1.19.0 -Release: 4%{?dist} +Version: 1.20.0 +Release: 1%{?dist} Summary: The Rust Programming Language License: (ASL 2.0 or MIT) and (BSD and ISC and MIT) # ^ written as: (rust itself) and (bundled libraries) @@ -62,8 +62,8 @@ ExclusiveArch: %{rust_arches} %endif Source0: https://static.rust-lang.org/dist/%{rustc_package}.tar.xz -Patch1: rust-1.19.0-43072-stack-guard.patch -Patch2: rust-1.19.0-43297-configure-debuginfo.patch +Patch1: rust-1.19.0-43297-configure-debuginfo.patch +Patch2: rust-1.20.0-44203-exclude-compiler-rt-test.patch # Get the Rust triple for any arch. %{lua: function rust_triple(arch) @@ -93,7 +93,7 @@ end} .."/rust-%{bootstrap_channel}") local target_arch = rpm.expand("%{_target_cpu}") for i, arch in ipairs(bootstrap_arches) do - print(string.format("Source%d: %s-%s.tar.gz\n", + print(string.format("Source%d: %s-%s.tar.xz\n", i, base, rust_triple(arch))) if arch == target_arch then rpm.define("bootstrap_source "..i) @@ -123,7 +123,7 @@ BuildRequires: curl %if %with bundled_llvm BuildRequires: cmake3 -Provides: bundled(llvm) = 3.9 +Provides: bundled(llvm) = 4.0 %else %if 0%{?epel} %global llvm llvm3.9 @@ -164,7 +164,7 @@ Requires: %{name}-std-static%{?_isa} = %{version}-%{release} # The C compiler is needed at runtime just for linking. Someday rustc might # invoke the linker directly, and then we'll only need binutils. # https://github.com/rust-lang/rust/issues/11937 -Requires: gcc +Requires: /usr/bin/cc # ALL Rust libraries are private, because they don't keep an ABI. %global _privatelibs lib.*-[[:xdigit:]]*[.]so.* @@ -258,6 +258,15 @@ This package includes HTML documentation for the Rust programming language and its standard library. +%package src +Summary: Sources for the Rust standard library +BuildArch: noarch + +%description src +This package includes source files for the Rust standard library. It may be +useful as a reference for code completion tools in various editors. + + %prep %ifarch %{bootstrap_arches} @@ -270,8 +279,9 @@ test -f '%{local_rust_root}/bin/rustc' %setup -q -n %{rustc_package} -# unbundle -rm -rf src/jemalloc/ +# We're disabling jemalloc, but rust-src still wants it. +# rm -rf src/jemalloc/ + %if %without bundled_llvm rm -rf src/llvm/ %endif @@ -281,13 +291,6 @@ cp src/rt/hoedown/LICENSE src/rt/hoedown/LICENSE-hoedown sed -e '/*\//q' src/libbacktrace/backtrace.h \ >src/libbacktrace/LICENSE-libbacktrace -# These tests assume that alloc_jemalloc is present -# https://github.com/rust-lang/rust/issues/35017 -sed -i.jemalloc -e '1i // ignore-test jemalloc is disabled' \ - src/test/compile-fail/allocator-dylib-is-system.rs \ - src/test/compile-fail/allocator-rust-dylib-is-jemalloc.rs \ - src/test/run-pass/allocator-default.rs - # This tests a problem of exponential growth, which seems to be less-reliably # fixed when running on older LLVM and/or some arches. Just skip it for now. sed -i.ignore -e '1i // ignore-test may still be exponential...' \ @@ -306,8 +309,8 @@ sed -i.ffi -e '$a #[link(name = "ffi")] extern {}' \ src/librustc_llvm/lib.rs %endif -%patch1 -p1 -b .stack-guard -%patch2 -p1 -b .debuginfo +%patch1 -p1 -b .debuginfo +%patch2 -p1 -b .compiler-rt # The configure macro will modify some autoconf-related files, which upsets # cargo when it tries to verify checksums in those files. If we just truncate @@ -351,6 +354,7 @@ find src/vendor -name .cargo-checksum.json \ %{?rustflags:export RUSTFLAGS="%{rustflags}"} DESTDIR=%{buildroot} ./x.py install +DESTDIR=%{buildroot} ./x.py install src # Make sure the shared libraries are in the proper libdir @@ -459,7 +463,16 @@ rm -f %{buildroot}%{rustlibdir}/etc/lldb_*.py* %license %{_docdir}/%{name}/html/*.txt +%files src +%dir %{rustlibdir} +%{rustlibdir}/src + + %changelog +* Thu Aug 31 2017 Josh Stone - 1.20.0-1 +- Update to 1.20.0. +- Add a rust-src subpackage. + * Thu Aug 03 2017 Fedora Release Engineering - 1.19.0-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild diff --git a/sources b/sources index 61fa672..4ff38d8 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (rustc-1.19.0-src.tar.xz) = 4dc0d0848d54ba7355aac7e13b3d0d3f42f05d6cd97ced9dc9e6493ba4686e1398803b567cecf24be0632b11ce1565e8d61b7603ce838b9c32dd0e663d03ba82 +SHA512 (rustc-1.20.0-src.tar.xz) = 1fcf5f279094e9f8b89b2a46f3fbc11c15609a8bda1e51b82899bd475381c8bb6aaa7ce6fe196fc07e0a36e9d9b9dbaa1c4a6281946cd9f13f3e72fb8cbd3bb2 diff --git a/sources-bootstrap b/sources-bootstrap index 93cd855..361e7b7 100644 --- a/sources-bootstrap +++ b/sources-bootstrap @@ -1,8 +1,8 @@ -SHA512 (rustc-1.19.0-src.tar.xz) = 4dc0d0848d54ba7355aac7e13b3d0d3f42f05d6cd97ced9dc9e6493ba4686e1398803b567cecf24be0632b11ce1565e8d61b7603ce838b9c32dd0e663d03ba82 -SHA512 (rust-1.18.0-aarch64-unknown-linux-gnu.tar.gz) = a1445b84e6215d3b72ed3c33ecfb0467e9abc0eb000eb2059aacf24bed1d8f1de0d2355654d3558b405289db45512c164b45e8b5c19b1420b3eb6f6f17d83872 -SHA512 (rust-1.18.0-armv7-unknown-linux-gnueabihf.tar.gz) = 7f9783bf396d110da7dce69f5d27501357a6c398296aada1029cc251ac0d97b648a934e8a71c2c4cb2e9fe660e98130624d3bd45543a3fcf4e821f5ee6fda172 -SHA512 (rust-1.18.0-i686-unknown-linux-gnu.tar.gz) = 8deb0dc9aae392ff50e1e93a0039340db60dbd8838fbeb5bca87961506c21b85961bed37f89d73993e44f8e50c493ef90f7e5b815e459b3650826b97357cad59 -SHA512 (rust-1.18.0-powerpc64le-unknown-linux-gnu.tar.gz) = 814f07ba103a6358cff0f0a5d55d7b73ce8c1cfda2dbb426f9ace0e043a66eb76797917ebedcd50d60a7ede5e941bb3c77dbf99f5ba92e59238a09c41582edc5 -SHA512 (rust-1.18.0-powerpc64-unknown-linux-gnu.tar.gz) = 5f6107c70f71e8afec90e5a94d40e27927239e70811a373ef3e0d39191295625e15881ff738bd62ace1b04489c9a33d51f1b4eec2cc923f8d1959dae38de98d8 -SHA512 (rust-1.18.0-s390x-unknown-linux-gnu.tar.gz) = 291c2aa3107b727176b90f0ff927e72b69c0830261c13805734b6e41cf4979a0000adbfddd69ccfef960b1eb9382694c6084e31adb8c2979df9973f112f3ee12 -SHA512 (rust-1.18.0-x86_64-unknown-linux-gnu.tar.gz) = 3d5cb71c03f95145539d9f209733ef555520eb826411737c4f168bbcb8ff631a9035e7dc81c42ecf107c5115d1d69ea6620ed95331cefad6de1b9d49f87ce305 +SHA512 (rustc-1.20.0-src.tar.xz) = 1fcf5f279094e9f8b89b2a46f3fbc11c15609a8bda1e51b82899bd475381c8bb6aaa7ce6fe196fc07e0a36e9d9b9dbaa1c4a6281946cd9f13f3e72fb8cbd3bb2 +SHA512 (rust-1.19.0-aarch64-unknown-linux-gnu.tar.xz) = 403ff1e6795c623e022813a9cb6f3c246aeeb5f657f233ff96674b1c2fb8146838003de9322817e15cd3099e8a3a2044e92e64a8dde5b3e8f7255f1616699467 +SHA512 (rust-1.19.0-armv7-unknown-linux-gnueabihf.tar.xz) = dd358f03f9ff23de2b9932504d35518f6340a9dd32984a7597bcf77435435f6101066efd088f2637e75bfd1939cb363ef71796ea6f5f6583899a51190c2a5b64 +SHA512 (rust-1.19.0-i686-unknown-linux-gnu.tar.xz) = e04b453fd3d5f72cc24211f1dc8a04813b3d07fe088281926bddc5273ddda7702af71010eba5611b911b7049e5f852087c94516792c0e534b15122c55760f7a3 +SHA512 (rust-1.19.0-powerpc64le-unknown-linux-gnu.tar.xz) = 9bbdd62d2067d1c81b0cfb205f4c51250afe8699752f212a12ad359d9f7b6a85489a459093ab5d1c516d758f676df6eacef1f8d07a5d43b6c794daf1cde33f1c +SHA512 (rust-1.19.0-powerpc64-unknown-linux-gnu.tar.xz) = 6697ec98588d092a65b23565d4d29390182089bcc2fe5c9de75ca9020ac5cdfae6e255f6355a828884c4986197917c45b131b29aafd06a67d4d9a5686f3bf975 +SHA512 (rust-1.19.0-s390x-unknown-linux-gnu.tar.xz) = 61724b6e647d8c6539cc50b47bbef772a65b4d1b041f8fe2411e947bf08535b3227ffda729c3cdb73613723dfc66d73db08b99c173f4fdb6fe510066e9a47fa0 +SHA512 (rust-1.19.0-x86_64-unknown-linux-gnu.tar.xz) = 807d1b9845f47d515aac54d06274502fb57a4d8ac9caeeaf53bdfd8ae23cc67a151932a9abaa2c0b3ade7124943df91b42442450cbc2a58d2b545db798b45e5d From 99c271af8c8c050c3e49fcf56844695fb985fa0d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 11 Sep 2017 11:54:06 -0700 Subject: [PATCH 2/2] ABI fixes for ppc64 and s390x. --- rust-1.20.0-44066-ppc64-struct-abi.patch | 405 +++++++++++++++++++++ rust-1.20.0-44440-s390x-global-align.patch | 209 +++++++++++ rust.spec | 9 +- 3 files changed, 622 insertions(+), 1 deletion(-) create mode 100644 rust-1.20.0-44066-ppc64-struct-abi.patch create mode 100644 rust-1.20.0-44440-s390x-global-align.patch diff --git a/rust-1.20.0-44066-ppc64-struct-abi.patch b/rust-1.20.0-44066-ppc64-struct-abi.patch new file mode 100644 index 0000000..3f7d3b8 --- /dev/null +++ b/rust-1.20.0-44066-ppc64-struct-abi.patch @@ -0,0 +1,405 @@ +From 6f680d06544edae491d2281d89b0b93efcdd6143 Mon Sep 17 00:00:00 2001 +From: bors +Date: Sat, 2 Sep 2017 19:46:51 +0000 +Subject: [PATCH] Auto merge of #44066 - cuviper:powerpc64-extern-abi, + r=alexcrichton + +powerpc64: improve extern struct ABI + +These fixes all have to do with the 64-bit PowerPC ELF ABI for big-endian +targets. The ELF v2 ABI for powerpc64le already worked well. + +- Return after marking return aggregates indirect. Fixes #42757. +- Pass one-member float aggregates as direct argument values. +- Aggregate arguments less than 64-bit must be written in the least- + significant bits of the parameter space. +- Larger aggregates are instead padded at the tail. + (i.e. filling MSBs, padding the remaining LSBs.) + +New tests were also added for the single-float aggregate, and a 3-byte +aggregate to check that it's filled into LSBs. Overall, at least these +formerly-failing tests now pass on powerpc64: + +- run-make/extern-fn-struct-passing-abi +- run-make/extern-fn-with-packed-struct +- run-pass/extern-pass-TwoU16s.rs +- run-pass/extern-pass-TwoU8s.rs +- run-pass/struct-return.rs +--- + src/librustc_trans/cabi_powerpc64.rs | 64 +++++++++++++++++----- + src/librustc_trans/cabi_x86.rs | 41 ++++++++++++-- + .../run-make/extern-fn-struct-passing-abi/test.c | 32 ++++++++++- + .../run-make/extern-fn-struct-passing-abi/test.rs | 27 +++++++++ + .../run-make/extern-fn-with-packed-struct/test.c | 5 ++ + .../run-make/extern-fn-with-packed-struct/test.rs | 26 +-------- + 6 files changed, 151 insertions(+), 44 deletions(-) + +diff --git a/src/librustc_trans/cabi_powerpc64.rs b/src/librustc_trans/cabi_powerpc64.rs +index c4f8d0b4b963..a3780c8cfa92 100644 +--- a/src/librustc_trans/cabi_powerpc64.rs ++++ b/src/librustc_trans/cabi_powerpc64.rs +@@ -14,14 +14,26 @@ + + use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform}; + use context::CrateContext; ++use rustc::ty::layout; + +-fn is_homogenous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) ++#[derive(Debug, Clone, Copy, PartialEq)] ++enum ABI { ++ ELFv1, // original ABI used for powerpc64 (big-endian) ++ ELFv2, // newer ABI used for powerpc64le ++} ++use self::ABI::*; ++ ++fn is_homogenous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ++ arg: &mut ArgType<'tcx>, ++ abi: ABI) + -> Option { + arg.layout.homogenous_aggregate(ccx).and_then(|unit| { + let size = arg.layout.size(ccx); + +- // Ensure we have at most eight uniquely addressable members. +- if size > unit.size.checked_mul(8, ccx).unwrap() { ++ // ELFv1 only passes one-member aggregates transparently. ++ // ELFv2 passes up to eight uniquely addressable members. ++ if (abi == ELFv1 && size > unit.size) ++ || size > unit.size.checked_mul(8, ccx).unwrap() { + return None; + } + +@@ -42,21 +54,23 @@ fn is_homogenous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut Arg + }) + } + +-fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) { ++fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>, abi: ABI) { + if !ret.layout.is_aggregate() { + ret.extend_integer_width_to(64); + return; + } + +- // The PowerPC64 big endian ABI doesn't return aggregates in registers +- if ccx.sess().target.target.target_endian == "big" { ++ // The ELFv1 ABI doesn't return aggregates in registers ++ if abi == ELFv1 { + ret.make_indirect(ccx); ++ return; + } + +- if let Some(uniform) = is_homogenous_aggregate(ccx, ret) { ++ if let Some(uniform) = is_homogenous_aggregate(ccx, ret, abi) { + ret.cast_to(ccx, uniform); + return; + } ++ + let size = ret.layout.size(ccx); + let bits = size.bits(); + if bits <= 128 { +@@ -80,31 +94,55 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tc + ret.make_indirect(ccx); + } + +-fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) { ++fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>, abi: ABI) { + if !arg.layout.is_aggregate() { + arg.extend_integer_width_to(64); + return; + } + +- if let Some(uniform) = is_homogenous_aggregate(ccx, arg) { ++ if let Some(uniform) = is_homogenous_aggregate(ccx, arg, abi) { + arg.cast_to(ccx, uniform); + return; + } + +- let total = arg.layout.size(ccx); ++ let size = arg.layout.size(ccx); ++ let (unit, total) = match abi { ++ ELFv1 => { ++ // In ELFv1, aggregates smaller than a doubleword should appear in ++ // the least-significant bits of the parameter doubleword. The rest ++ // should be padded at their tail to fill out multiple doublewords. ++ if size.bits() <= 64 { ++ (Reg { kind: RegKind::Integer, size }, size) ++ } else { ++ let align = layout::Align::from_bits(64, 64).unwrap(); ++ (Reg::i64(), size.abi_align(align)) ++ } ++ }, ++ ELFv2 => { ++ // In ELFv2, we can just cast directly. ++ (Reg::i64(), size) ++ }, ++ }; ++ + arg.cast_to(ccx, Uniform { +- unit: Reg::i64(), ++ unit, + total + }); + } + + pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) { ++ let abi = match ccx.sess().target.target.target_endian.as_str() { ++ "big" => ELFv1, ++ "little" => ELFv2, ++ _ => unimplemented!(), ++ }; ++ + if !fty.ret.is_ignore() { +- classify_ret_ty(ccx, &mut fty.ret); ++ classify_ret_ty(ccx, &mut fty.ret, abi); + } + + for arg in &mut fty.args { + if arg.is_ignore() { continue; } +- classify_arg_ty(ccx, arg); ++ classify_arg_ty(ccx, arg, abi); + } + } +diff --git a/src/librustc_trans/cabi_x86.rs b/src/librustc_trans/cabi_x86.rs +index 9f5520dabe33..05932ef2de80 100644 +--- a/src/librustc_trans/cabi_x86.rs ++++ b/src/librustc_trans/cabi_x86.rs +@@ -11,12 +11,30 @@ + use abi::{ArgAttribute, FnType, LayoutExt, Reg, RegKind}; + use common::CrateContext; + ++use rustc::ty::layout::{self, Layout, TyLayout}; ++ + #[derive(PartialEq)] + pub enum Flavor { + General, + Fastcall + } + ++fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ++ layout: TyLayout<'tcx>) -> bool { ++ match *layout { ++ Layout::Scalar { value: layout::F32, .. } | ++ Layout::Scalar { value: layout::F64, .. } => true, ++ Layout::Univariant { .. } => { ++ if layout.field_count() == 1 { ++ is_single_fp_element(ccx, layout.field(ccx, 0)) ++ } else { ++ false ++ } ++ } ++ _ => false ++ } ++} ++ + pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + fty: &mut FnType<'tcx>, + flavor: Flavor) { +@@ -33,12 +51,23 @@ pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + if t.options.is_like_osx || t.options.is_like_windows + || t.options.is_like_openbsd { + let size = fty.ret.layout.size(ccx); +- match size.bytes() { +- 1 => fty.ret.cast_to(ccx, Reg::i8()), +- 2 => fty.ret.cast_to(ccx, Reg::i16()), +- 4 => fty.ret.cast_to(ccx, Reg::i32()), +- 8 => fty.ret.cast_to(ccx, Reg::i64()), +- _ => fty.ret.make_indirect(ccx) ++ ++ // According to Clang, everyone but MSVC returns single-element ++ // float aggregates directly in a floating-point register. ++ if !t.options.is_like_msvc && is_single_fp_element(ccx, fty.ret.layout) { ++ match size.bytes() { ++ 4 => fty.ret.cast_to(ccx, Reg::f32()), ++ 8 => fty.ret.cast_to(ccx, Reg::f64()), ++ _ => fty.ret.make_indirect(ccx) ++ } ++ } else { ++ match size.bytes() { ++ 1 => fty.ret.cast_to(ccx, Reg::i8()), ++ 2 => fty.ret.cast_to(ccx, Reg::i16()), ++ 4 => fty.ret.cast_to(ccx, Reg::i32()), ++ 8 => fty.ret.cast_to(ccx, Reg::i64()), ++ _ => fty.ret.make_indirect(ccx) ++ } + } + } else { + fty.ret.make_indirect(ccx); +diff --git a/src/test/run-make/extern-fn-struct-passing-abi/test.c b/src/test/run-make/extern-fn-struct-passing-abi/test.c +index 44a940a17a98..25cd6da10b8f 100644 +--- a/src/test/run-make/extern-fn-struct-passing-abi/test.c ++++ b/src/test/run-make/extern-fn-struct-passing-abi/test.c +@@ -43,6 +43,16 @@ struct FloatPoint { + double y; + }; + ++struct FloatOne { ++ double x; ++}; ++ ++struct IntOdd { ++ int8_t a; ++ int8_t b; ++ int8_t c; ++}; ++ + // System V x86_64 ABI: + // a, b, c, d, e should be in registers + // s should be byval pointer +@@ -283,7 +293,7 @@ struct Huge huge_struct(struct Huge s) { + // p should be in registers + // return should be in registers + // +-// Win64 ABI: ++// Win64 ABI and 64-bit PowerPC ELFv1 ABI: + // p should be a byval pointer + // return should be in a hidden sret pointer + struct FloatPoint float_point(struct FloatPoint p) { +@@ -292,3 +302,23 @@ struct FloatPoint float_point(struct FloatPoint p) { + + return p; + } ++ ++// 64-bit PowerPC ELFv1 ABI: ++// f1 should be in a register ++// return should be in a hidden sret pointer ++struct FloatOne float_one(struct FloatOne f1) { ++ assert(f1.x == 7.); ++ ++ return f1; ++} ++ ++// 64-bit PowerPC ELFv1 ABI: ++// i should be in the least-significant bits of a register ++// return should be in a hidden sret pointer ++struct IntOdd int_odd(struct IntOdd i) { ++ assert(i.a == 1); ++ assert(i.b == 2); ++ assert(i.c == 3); ++ ++ return i; ++} +diff --git a/src/test/run-make/extern-fn-struct-passing-abi/test.rs b/src/test/run-make/extern-fn-struct-passing-abi/test.rs +index aaae7ae4fb49..54a4f868eb4e 100644 +--- a/src/test/run-make/extern-fn-struct-passing-abi/test.rs ++++ b/src/test/run-make/extern-fn-struct-passing-abi/test.rs +@@ -53,6 +53,20 @@ struct FloatPoint { + y: f64 + } + ++#[derive(Clone, Copy, Debug, PartialEq)] ++#[repr(C)] ++struct FloatOne { ++ x: f64, ++} ++ ++#[derive(Clone, Copy, Debug, PartialEq)] ++#[repr(C)] ++struct IntOdd { ++ a: i8, ++ b: i8, ++ c: i8, ++} ++ + #[link(name = "test", kind = "static")] + extern { + fn byval_rect(a: i32, b: i32, c: i32, d: i32, e: i32, s: Rect); +@@ -83,6 +97,10 @@ extern { + fn huge_struct(s: Huge) -> Huge; + + fn float_point(p: FloatPoint) -> FloatPoint; ++ ++ fn float_one(f: FloatOne) -> FloatOne; ++ ++ fn int_odd(i: IntOdd) -> IntOdd; + } + + fn main() { +@@ -91,6 +109,8 @@ fn main() { + let u = FloatRect { a: 3489, b: 3490, c: 8. }; + let v = Huge { a: 5647, b: 5648, c: 5649, d: 5650, e: 5651 }; + let p = FloatPoint { x: 5., y: -3. }; ++ let f1 = FloatOne { x: 7. }; ++ let i = IntOdd { a: 1, b: 2, c: 3 }; + + unsafe { + byval_rect(1, 2, 3, 4, 5, s); +@@ -113,5 +133,12 @@ fn main() { + assert_eq!(sret_byval_struct(1, 2, 3, 4, s), t); + assert_eq!(sret_split_struct(1, 2, s), t); + assert_eq!(float_point(p), p); ++ assert_eq!(int_odd(i), i); ++ ++ // MSVC/GCC/Clang are not consistent in the ABI of single-float aggregates. ++ // x86_64: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82028 ++ // i686: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82041 ++ #[cfg(not(all(windows, target_env = "gnu")))] ++ assert_eq!(float_one(f1), f1); + } + } +diff --git a/src/test/run-make/extern-fn-with-packed-struct/test.c b/src/test/run-make/extern-fn-with-packed-struct/test.c +index 506954fca461..4124e202c1dd 100644 +--- a/src/test/run-make/extern-fn-with-packed-struct/test.c ++++ b/src/test/run-make/extern-fn-with-packed-struct/test.c +@@ -1,6 +1,8 @@ + // ignore-license + // Pragma needed cause of gcc bug on windows: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 + ++#include ++ + #ifdef _MSC_VER + #pragma pack(push,1) + struct Foo { +@@ -18,5 +20,8 @@ struct __attribute__((packed)) Foo { + #endif + + struct Foo foo(struct Foo foo) { ++ assert(foo.a == 1); ++ assert(foo.b == 2); ++ assert(foo.c == 3); + return foo; + } +diff --git a/src/test/run-make/extern-fn-with-packed-struct/test.rs b/src/test/run-make/extern-fn-with-packed-struct/test.rs +index 9e81636e3670..d2540ad61542 100644 +--- a/src/test/run-make/extern-fn-with-packed-struct/test.rs ++++ b/src/test/run-make/extern-fn-with-packed-struct/test.rs +@@ -8,36 +8,14 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use std::fmt; +- +-#[repr(packed)] +-#[derive(Copy, Clone)] ++#[repr(C, packed)] ++#[derive(Copy, Clone, Debug, PartialEq)] + struct Foo { + a: i8, + b: i16, + c: i8 + } + +-impl PartialEq for Foo { +- fn eq(&self, other: &Foo) -> bool { +- self.a == other.a && self.b == other.b && self.c == other.c +- } +-} +- +-impl fmt::Debug for Foo { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- let a = self.a; +- let b = self.b; +- let c = self.c; +- +- f.debug_struct("Foo") +- .field("a", &a) +- .field("b", &b) +- .field("c", &c) +- .finish() +- } +-} +- + #[link(name = "test", kind = "static")] + extern { + fn foo(f: Foo) -> Foo; +-- +2.13.5 + diff --git a/rust-1.20.0-44440-s390x-global-align.patch b/rust-1.20.0-44440-s390x-global-align.patch new file mode 100644 index 0000000..ddc2180 --- /dev/null +++ b/rust-1.20.0-44440-s390x-global-align.patch @@ -0,0 +1,209 @@ +From 3ca86983df58daf0242b0618d3beb9ea917193e2 Mon Sep 17 00:00:00 2001 +From: bors +Date: Mon, 11 Sep 2017 12:53:21 +0000 +Subject: [PATCH] Auto merge of #44440 - cuviper:min_global_align, r=japaric + +Add `TargetOptions::min_global_align`, with s390x at 16-bit + +The SystemZ `LALR` instruction provides PC-relative addressing for globals, +but only to *even* addresses, so other compilers make sure that such +globals are always 2-byte aligned. In Clang, this is modeled with +`TargetInfo::MinGlobalAlign`, and `TargetOptions::min_global_align` now +serves the same purpose for rustc. + +In Clang, the only targets that set this are SystemZ, Lanai, and NVPTX, and +the latter two don't have targets in rust master. + +Fixes #44411. +r? @eddyb +--- + src/librustc_back/target/mod.rs | 6 ++++ + .../target/s390x_unknown_linux_gnu.rs | 1 + + src/librustc_trans/consts.rs | 24 ++++++++++++-- + src/test/run-make/min-global-align/Makefile | 22 +++++++++++++ + .../run-make/min-global-align/min_global_align.rs | 38 ++++++++++++++++++++++ + 5 files changed, 89 insertions(+), 2 deletions(-) + create mode 100644 src/test/run-make/min-global-align/Makefile + create mode 100644 src/test/run-make/min-global-align/min_global_align.rs + +diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs +index edbbcf6f0b64..f88a3879d6c0 100644 +--- a/src/librustc_back/target/mod.rs ++++ b/src/librustc_back/target/mod.rs +@@ -414,6 +414,9 @@ pub struct TargetOptions { + + /// Whether or not stack probes (__rust_probestack) are enabled + pub stack_probes: bool, ++ ++ /// The minimum alignment for global symbols. ++ pub min_global_align: Option, + } + + impl Default for TargetOptions { +@@ -472,6 +475,7 @@ impl Default for TargetOptions { + abi_blacklist: vec![], + crt_static_default: false, + stack_probes: false, ++ min_global_align: None, + } + } + } +@@ -695,6 +699,7 @@ impl Target { + try!(key!(panic_strategy, PanicStrategy)); + key!(crt_static_default, bool); + key!(stack_probes, bool); ++ key!(min_global_align, Option); + + if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) { + for name in array.iter().filter_map(|abi| abi.as_string()) { +@@ -882,6 +887,7 @@ impl ToJson for Target { + target_option_val!(panic_strategy); + target_option_val!(crt_static_default); + target_option_val!(stack_probes); ++ target_option_val!(min_global_align); + + if default.abi_blacklist != self.options.abi_blacklist { + d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter() +diff --git a/src/librustc_back/target/s390x_unknown_linux_gnu.rs b/src/librustc_back/target/s390x_unknown_linux_gnu.rs +index 78a6bb7933d9..aad9effacd44 100644 +--- a/src/librustc_back/target/s390x_unknown_linux_gnu.rs ++++ b/src/librustc_back/target/s390x_unknown_linux_gnu.rs +@@ -22,6 +22,7 @@ pub fn target() -> TargetResult { + base.max_atomic_width = Some(64); + // see #36994 + base.exe_allocation_crate = None; ++ base.min_global_align = Some(16); + + Ok(Target { + llvm_target: "s390x-unknown-linux-gnu".to_string(), +diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs +index eac0a0625671..cfb29d848d0f 100644 +--- a/src/librustc_trans/consts.rs ++++ b/src/librustc_trans/consts.rs +@@ -26,6 +26,7 @@ use rustc::ty; + + use rustc::hir; + ++use std::cmp; + use std::ffi::{CStr, CString}; + use syntax::ast; + use syntax::attr; +@@ -36,6 +37,25 @@ pub fn ptrcast(val: ValueRef, ty: Type) -> ValueRef { + } + } + ++fn set_global_alignment(ccx: &CrateContext, ++ gv: ValueRef, ++ mut align: machine::llalign) { ++ // The target may require greater alignment for globals than the type does. ++ // Note: GCC and Clang also allow `__attribute__((aligned))` on variables, ++ // which can force it to be smaller. Rust doesn't support this yet. ++ if let Some(min) = ccx.sess().target.target.options.min_global_align { ++ match ty::layout::Align::from_bits(min, min) { ++ Ok(min) => align = cmp::max(align, min.abi() as machine::llalign), ++ Err(err) => { ++ ccx.sess().err(&format!("invalid minimum global alignment: {}", err)); ++ } ++ } ++ } ++ unsafe { ++ llvm::LLVMSetAlignment(gv, align); ++ } ++} ++ + pub fn addr_of_mut(ccx: &CrateContext, + cv: ValueRef, + align: machine::llalign, +@@ -47,7 +67,7 @@ pub fn addr_of_mut(ccx: &CrateContext, + bug!("symbol `{}` is already defined", name); + }); + llvm::LLVMSetInitializer(gv, cv); +- llvm::LLVMSetAlignment(gv, align); ++ set_global_alignment(ccx, gv, align); + llvm::LLVMRustSetLinkage(gv, llvm::Linkage::InternalLinkage); + SetUnnamedAddr(gv, true); + gv +@@ -251,7 +271,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, + ccx.statics_to_rauw().borrow_mut().push((g, new_g)); + new_g + }; +- llvm::LLVMSetAlignment(g, ccx.align_of(ty)); ++ set_global_alignment(ccx, g, ccx.align_of(ty)); + llvm::LLVMSetInitializer(g, v); + + // As an optimization, all shared statics which do not have interior +diff --git a/src/test/run-make/min-global-align/Makefile b/src/test/run-make/min-global-align/Makefile +new file mode 100644 +index 000000000000..2eacc36f380d +--- /dev/null ++++ b/src/test/run-make/min-global-align/Makefile +@@ -0,0 +1,22 @@ ++-include ../tools.mk ++ ++# This tests ensure that global variables respect the target minimum alignment. ++# The three bools `STATIC_BOOL`, `STATIC_MUT_BOOL`, and `CONST_BOOL` all have ++# type-alignment of 1, but some targets require greater global alignment. ++ ++SRC = min_global_align.rs ++LL = $(TMPDIR)/min_global_align.ll ++ ++all: ++ifeq ($(UNAME),Linux) ++# Most targets are happy with default alignment -- take i686 for example. ++ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86) ++ $(RUSTC) --target=i686-unknown-linux-gnu --emit=llvm-ir $(SRC) ++ [ "$$(grep -c 'align 1' "$(LL)")" -eq "3" ] ++endif ++# SystemZ requires even alignment for PC-relative addressing. ++ifeq ($(filter systemz,$(LLVM_COMPONENTS)),systemz) ++ $(RUSTC) --target=s390x-unknown-linux-gnu --emit=llvm-ir $(SRC) ++ [ "$$(grep -c 'align 2' "$(LL)")" -eq "3" ] ++endif ++endif +diff --git a/src/test/run-make/min-global-align/min_global_align.rs b/src/test/run-make/min-global-align/min_global_align.rs +new file mode 100644 +index 000000000000..3d4f9001a747 +--- /dev/null ++++ b/src/test/run-make/min-global-align/min_global_align.rs +@@ -0,0 +1,38 @@ ++// Copyright 2017 The Rust Project Developers. See the COPYRIGHT ++// file at the top-level directory of this distribution and at ++// http://rust-lang.org/COPYRIGHT. ++// ++// Licensed under the Apache License, Version 2.0 or the MIT license ++// , at your ++// option. This file may not be copied, modified, or distributed ++// except according to those terms. ++ ++#![feature(no_core, lang_items)] ++#![crate_type="rlib"] ++#![no_core] ++ ++pub static STATIC_BOOL: bool = true; ++ ++pub static mut STATIC_MUT_BOOL: bool = true; ++ ++const CONST_BOOL: bool = true; ++pub static CONST_BOOL_REF: &'static bool = &CONST_BOOL; ++ ++ ++#[lang = "sized"] ++trait Sized {} ++ ++#[lang = "copy"] ++trait Copy {} ++ ++#[lang = "freeze"] ++trait Freeze {} ++ ++#[lang = "sync"] ++trait Sync {} ++impl Sync for bool {} ++impl Sync for &'static bool {} ++ ++#[lang="drop_in_place"] ++pub unsafe fn drop_in_place(_: *mut T) { } +-- +2.13.5 + diff --git a/rust.spec b/rust.spec index f4b2522..035cfe4 100644 --- a/rust.spec +++ b/rust.spec @@ -48,7 +48,7 @@ Name: rust Version: 1.20.0 -Release: 1%{?dist} +Release: 2%{?dist} Summary: The Rust Programming Language License: (ASL 2.0 or MIT) and (BSD and ISC and MIT) # ^ written as: (rust itself) and (bundled libraries) @@ -64,6 +64,8 @@ Source0: https://static.rust-lang.org/dist/%{rustc_package}.tar.xz Patch1: rust-1.19.0-43297-configure-debuginfo.patch Patch2: rust-1.20.0-44203-exclude-compiler-rt-test.patch +Patch3: rust-1.20.0-44066-ppc64-struct-abi.patch +Patch4: rust-1.20.0-44440-s390x-global-align.patch # Get the Rust triple for any arch. %{lua: function rust_triple(arch) @@ -311,6 +313,8 @@ sed -i.ffi -e '$a #[link(name = "ffi")] extern {}' \ %patch1 -p1 -b .debuginfo %patch2 -p1 -b .compiler-rt +%patch3 -p1 -b .ppc64-struct-abi +%patch4 -p1 -b .s390x-global-align # The configure macro will modify some autoconf-related files, which upsets # cargo when it tries to verify checksums in those files. If we just truncate @@ -469,6 +473,9 @@ rm -f %{buildroot}%{rustlibdir}/etc/lldb_*.py* %changelog +* Mon Sep 11 2017 Josh Stone - 1.20.0-2 +- ABI fixes for ppc64 and s390x. + * Thu Aug 31 2017 Josh Stone - 1.20.0-1 - Update to 1.20.0. - Add a rust-src subpackage.