From 1e9595e1169a31b518d72c9c64e990a20faec869 Mon Sep 17 00:00:00 2001 From: pierzchalski Date: Mon, 4 Apr 2016 19:44:38 +1000 Subject: [PATCH 1/8] Change build_helper to modify suffix of cc This should help avoid issues when using tools like ccache. --- src/build_helper/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index 092a1cabc746f..87e93afcf09b4 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -43,10 +43,16 @@ pub fn cc2ar(cc: &Path, target: &str) -> PathBuf { if target.contains("musl") || target.contains("msvc") { PathBuf::from("ar") } else { + let parent = cc.parent().unwrap(); let file = cc.file_name().unwrap().to_str().unwrap(); - cc.parent().unwrap().join(file.replace("gcc", "ar") - .replace("cc", "ar") - .replace("clang", "ar")) + for suffix in &["gcc", "cc", "clang"] { + if let Some(idx) = file.rfind(suffix) { + let mut file = file[..idx].to_owned(); + file.push_str(suffix); + return parent.join(&file); + } + } + parent.join(file) } } From 0fe1359885288537833d4b8cd6db724b46ea07b7 Mon Sep 17 00:00:00 2001 From: pierzchalski Date: Mon, 4 Apr 2016 21:14:15 +1000 Subject: [PATCH 2/8] whoops --- src/build_helper/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index 87e93afcf09b4..8e1da69cf02e7 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -48,7 +48,7 @@ pub fn cc2ar(cc: &Path, target: &str) -> PathBuf { for suffix in &["gcc", "cc", "clang"] { if let Some(idx) = file.rfind(suffix) { let mut file = file[..idx].to_owned(); - file.push_str(suffix); + file.push_str("ar"); return parent.join(&file); } } From c822546c9ebd79a245ca171a56f452b373ab623f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 4 Apr 2016 11:24:44 -0700 Subject: [PATCH 3/8] mk: Hardcode the bootstrap key for each release Starting with the 1.10.0 release we would like to bootstrap all compilers from the previous stable release. For example the 1.10.0 compiler should bootstrap from the literal 1.9.0 release artifacts. To do this, however, we need a way to enable unstable features temporarily in a stable compiler (as the released compiler is stable), but it turns out we already have a way to do that! At compile time the configure script selects a `CFG_BOOTSTRAP_KEY` variable value and then exports it into the makefiles. If the `RUSTC_BOOTSTRAP_KEY` environment variable is set to this value, then the compiler is allowed to "cheat" and use unstable features. This method of choosing the bootstrap key, however, is problematic for the intention of bootstrapping from the previous release. Each time a 1.9.0 compiler is created, a new bootstrap key will be selected. That means that the 1.10.0 compiler will only compile from *our* literal release artifacts. Instead distributions would like to bootstrap from their own compilers, so instead we simply hardcode the bootstrap key for each release. This patch uses the same `CFG_FILENAME_EXTRA` value (a hash of the release string) as the bootstrap key. Consequently all 1.9.0 compilers, no matter where they are compiled, will have the same bootstrap key. Additionally we won't need to keep updating this as it'll be based on the release number anyway. Once the 1.9.0 beta has been created, we can update the 1.10.0 nightly sources (the `master` branch at that time) to bootstrap from that release using this hard-coded bootstrap key. We will likely just hardcode into the makefiles what the previous bootstrap key was and we'll change that whenever the stage0 compiler is updated. --- configure | 12 ------------ mk/main.mk | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/configure b/configure index 2a18beeb8c954..84ed6fa895422 100755 --- a/configure +++ b/configure @@ -716,18 +716,6 @@ if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; f if [ -n "$CFG_ENABLE_ORBIT" ]; then putvar CFG_ENABLE_ORBIT; fi -# A magic value that allows the compiler to use unstable features -# during the bootstrap even when doing so would normally be an error -# because of feature staging or because the build turns on -# warnings-as-errors and unstable features default to warnings. The -# build has to match this key in an env var. Meant to be a mild -# deterrent from users just turning on unstable features on the stable -# channel. -# Basing CFG_BOOTSTRAP_KEY on CFG_BOOTSTRAP_KEY lets it get picked up -# during a Makefile reconfig. -CFG_BOOTSTRAP_KEY="${CFG_BOOTSTRAP_KEY-`date +%H:%M:%S`}" -putvar CFG_BOOTSTRAP_KEY - step_msg "looking for build programs" probe_need CFG_CURLORWGET curl wget diff --git a/mk/main.mk b/mk/main.mk index a32658ddcefdc..9b8080f96610f 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -24,6 +24,17 @@ CFG_PRERELEASE_VERSION=.1 # versions in the same place CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(CFG_HASH_COMMAND)) +# A magic value that allows the compiler to use unstable features during the +# bootstrap even when doing so would normally be an error because of feature +# staging or because the build turns on warnings-as-errors and unstable features +# default to warnings. The build has to match this key in an env var. +# +# This value is keyed off the release to ensure that all compilers for one +# particular release have the same bootstrap key. Note that this is +# intentionally not "secure" by any definition, this is largely just a deterrent +# from users enabling unstable features on the stable compiler. +CFG_BOOTSTRAP_KEY=$(CFG_FILENAME_EXTRA) + ifeq ($(CFG_RELEASE_CHANNEL),stable) # This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly" CFG_RELEASE=$(CFG_RELEASE_NUM) From 4815f7e668640ae968418307909f41a7eaabf050 Mon Sep 17 00:00:00 2001 From: James Miller Date: Wed, 17 Feb 2016 19:33:27 +1300 Subject: [PATCH 4/8] Handle integer-extending for C ABI We need to supply sext/zext attributes to LLVM to ensure that arguments are extended to the appropriate width in the correct way. Most platforms extend integers less than 32 bits, though not all. --- src/librustc_trans/abi.rs | 19 ++++++++++++ src/librustc_trans/cabi_aarch64.rs | 2 ++ src/librustc_trans/cabi_arm.rs | 2 ++ src/librustc_trans/cabi_mips.rs | 14 +++++++-- src/librustc_trans/cabi_powerpc.rs | 14 +++++++-- src/librustc_trans/cabi_powerpc64.rs | 2 ++ src/librustc_trans/cabi_x86.rs | 40 +++++++++++++++----------- src/librustc_trans/cabi_x86_64.rs | 2 ++ src/librustc_trans/cabi_x86_win64.rs | 2 ++ src/rt/rust_test_helpers.c | 4 +++ src/test/run-pass/cabi-int-widening.rs | 22 ++++++++++++++ 11 files changed, 102 insertions(+), 21 deletions(-) create mode 100644 src/test/run-pass/cabi-int-widening.rs diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 6edc26c70097a..73bed8dc56a85 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -80,6 +80,8 @@ pub struct ArgType { /// Only later will `original_ty` aka `%Foo` be used in the LLVM function /// pointer type, without ever having introspected it. pub ty: Type, + /// Signedness for integer types, None for other types + pub signedness: Option, /// Coerced LLVM Type pub cast: Option, /// Dummy argument, which is emitted before the real argument @@ -94,6 +96,7 @@ impl ArgType { kind: ArgKind::Direct, original_ty: original_ty, ty: ty, + signedness: None, cast: None, pad: None, attrs: llvm::Attributes::default() @@ -123,6 +126,19 @@ impl ArgType { self.kind = ArgKind::Ignore; } + pub fn extend_integer_width_to(&mut self, bits: u64) { + // Only integers have signedness + if let Some(signed) = self.signedness { + if self.ty.int_width() < bits { + self.attrs.set(if signed { + llvm::Attribute::SExt + } else { + llvm::Attribute::ZExt + }); + } + } + } + pub fn is_indirect(&self) -> bool { self.kind == ArgKind::Indirect } @@ -268,6 +284,9 @@ impl FnType { } else { let mut arg = ArgType::new(type_of::type_of(ccx, ty), type_of::sizing_type_of(ccx, ty)); + if ty.is_integral() { + arg.signedness = Some(ty.is_signed()); + } if llsize_of_real(ccx, arg.ty) == 0 { // For some forsaken reason, x86_64-pc-windows-gnu // doesn't ignore zero-sized struct arguments. diff --git a/src/librustc_trans/cabi_aarch64.rs b/src/librustc_trans/cabi_aarch64.rs index 4903af2a6ff7d..fc11e3888d3c2 100644 --- a/src/librustc_trans/cabi_aarch64.rs +++ b/src/librustc_trans/cabi_aarch64.rs @@ -163,6 +163,7 @@ fn is_homogenous_aggregate_ty(ty: Type) -> Option<(Type, u64)> { fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { if is_reg_ty(ret.ty) { + ret.extend_integer_width_to(32); return; } if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ret.ty) { @@ -190,6 +191,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) { if is_reg_ty(arg.ty) { + arg.extend_integer_width_to(32); return; } if let Some((base_ty, members)) = is_homogenous_aggregate_ty(arg.ty) { diff --git a/src/librustc_trans/cabi_arm.rs b/src/librustc_trans/cabi_arm.rs index 35099399e317c..68a2e8aa8ce95 100644 --- a/src/librustc_trans/cabi_arm.rs +++ b/src/librustc_trans/cabi_arm.rs @@ -131,6 +131,7 @@ fn ty_size(ty: Type, align_fn: TyAlignFn) -> usize { fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType, align_fn: TyAlignFn) { if is_reg_ty(ret.ty) { + ret.extend_integer_width_to(32); return; } let size = ty_size(ret.ty, align_fn); @@ -150,6 +151,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType, align_fn: TyAlignFn) { fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, align_fn: TyAlignFn) { if is_reg_ty(arg.ty) { + arg.extend_integer_width_to(32); return; } let align = align_fn(arg.ty); diff --git a/src/librustc_trans/cabi_mips.rs b/src/librustc_trans/cabi_mips.rs index be9d4cad1db68..680310e195a41 100644 --- a/src/librustc_trans/cabi_mips.rs +++ b/src/librustc_trans/cabi_mips.rs @@ -86,6 +86,14 @@ fn ty_size(ty: Type) -> usize { } } +fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { + if is_reg_ty(ret.ty) { + ret.extend_integer_width_to(32); + } else { + ret.make_indirect(ccx); + } +} + fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut usize) { let orig_offset = *offset; let size = ty_size(arg.ty) * 8; @@ -98,6 +106,8 @@ fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut usize) { if !is_reg_ty(arg.ty) { arg.cast = Some(struct_ty(ccx, arg.ty)); arg.pad = padding_ty(ccx, align, orig_offset); + } else { + arg.extend_integer_width_to(32); } } @@ -146,8 +156,8 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type { } pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { - if !fty.ret.is_ignore() && !is_reg_ty(fty.ret.ty) { - fty.ret.make_indirect(ccx); + if !fty.ret.is_ignore() { + classify_ret_ty(ccx, &mut fty.ret); } let mut offset = if fty.ret.is_indirect() { 4 } else { 0 }; diff --git a/src/librustc_trans/cabi_powerpc.rs b/src/librustc_trans/cabi_powerpc.rs index d118cc86f2443..efbdce67a8b2a 100644 --- a/src/librustc_trans/cabi_powerpc.rs +++ b/src/librustc_trans/cabi_powerpc.rs @@ -82,6 +82,14 @@ fn ty_size(ty: Type) -> usize { } } +fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { + if is_reg_ty(ret.ty) { + ret.extend_integer_width_to(32); + } else { + ret.make_indirect(ccx); + } +} + fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut usize) { let orig_offset = *offset; let size = ty_size(arg.ty) * 8; @@ -94,6 +102,8 @@ fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut usize) { if !is_reg_ty(arg.ty) { arg.cast = Some(struct_ty(ccx, arg.ty)); arg.pad = padding_ty(ccx, align, orig_offset); + } else { + arg.extend_integer_width_to(32); } } @@ -141,8 +151,8 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type { } pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { - if !fty.ret.is_ignore() && !is_reg_ty(fty.ret.ty) { - fty.ret.make_indirect(ccx); + if !fty.ret.is_ignore() { + classify_ret_ty(ccx, &mut fty.ret); } let mut offset = if fty.ret.is_indirect() { 4 } else { 0 }; diff --git a/src/librustc_trans/cabi_powerpc64.rs b/src/librustc_trans/cabi_powerpc64.rs index 7bc41d26f8b75..ba54e369fd838 100644 --- a/src/librustc_trans/cabi_powerpc64.rs +++ b/src/librustc_trans/cabi_powerpc64.rs @@ -153,6 +153,7 @@ fn is_homogenous_aggregate_ty(ty: Type) -> Option<(Type, u64)> { fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { if is_reg_ty(ret.ty) { + ret.extend_integer_width_to(64); return; } @@ -187,6 +188,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) { if is_reg_ty(arg.ty) { + arg.extend_integer_width_to(64); return; } diff --git a/src/librustc_trans/cabi_x86.rs b/src/librustc_trans/cabi_x86.rs index 415579eb221dd..b52231fa6b432 100644 --- a/src/librustc_trans/cabi_x86.rs +++ b/src/librustc_trans/cabi_x86.rs @@ -15,25 +15,29 @@ use super::common::*; use super::machine::*; pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { - if !fty.ret.is_ignore() && fty.ret.ty.kind() == Struct { - // Returning a structure. Most often, this will use - // a hidden first argument. On some platforms, though, - // small structs are returned as integers. - // - // Some links: - // http://www.angelcode.com/dev/callconv/callconv.html - // Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp - let t = &ccx.sess().target.target; - if t.options.is_like_osx || t.options.is_like_windows { - match llsize_of_alloc(ccx, fty.ret.ty) { - 1 => fty.ret.cast = Some(Type::i8(ccx)), - 2 => fty.ret.cast = Some(Type::i16(ccx)), - 4 => fty.ret.cast = Some(Type::i32(ccx)), - 8 => fty.ret.cast = Some(Type::i64(ccx)), - _ => fty.ret.make_indirect(ccx) + if !fty.ret.is_ignore() { + if fty.ret.ty.kind() == Struct { + // Returning a structure. Most often, this will use + // a hidden first argument. On some platforms, though, + // small structs are returned as integers. + // + // Some links: + // http://www.angelcode.com/dev/callconv/callconv.html + // Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp + let t = &ccx.sess().target.target; + if t.options.is_like_osx || t.options.is_like_windows { + match llsize_of_alloc(ccx, fty.ret.ty) { + 1 => fty.ret.cast = Some(Type::i8(ccx)), + 2 => fty.ret.cast = Some(Type::i16(ccx)), + 4 => fty.ret.cast = Some(Type::i32(ccx)), + 8 => fty.ret.cast = Some(Type::i64(ccx)), + _ => fty.ret.make_indirect(ccx) + } + } else { + fty.ret.make_indirect(ccx); } } else { - fty.ret.make_indirect(ccx); + fty.ret.extend_integer_width_to(32); } } @@ -42,6 +46,8 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { if arg.ty.kind() == Struct { arg.make_indirect(ccx); arg.attrs.set(Attribute::ByVal); + } else { + arg.extend_integer_width_to(32); } } } diff --git a/src/librustc_trans/cabi_x86_64.rs b/src/librustc_trans/cabi_x86_64.rs index e9e9e266c7786..805c7d345a0e7 100644 --- a/src/librustc_trans/cabi_x86_64.rs +++ b/src/librustc_trans/cabi_x86_64.rs @@ -400,6 +400,8 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { } else { arg.cast = Some(llreg_ty(ccx, &cls)); } + } else { + arg.extend_integer_width_to(32); } } diff --git a/src/librustc_trans/cabi_x86_win64.rs b/src/librustc_trans/cabi_x86_win64.rs index a5077f68fb58c..71ecb6e9ca104 100644 --- a/src/librustc_trans/cabi_x86_win64.rs +++ b/src/librustc_trans/cabi_x86_win64.rs @@ -26,6 +26,8 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { 8 => a.cast = Some(Type::i64(ccx)), _ => a.make_indirect(ccx) } + } else { + a.extend_integer_width_to(32); } }; diff --git a/src/rt/rust_test_helpers.c b/src/rt/rust_test_helpers.c index 00bfa63e6fea8..d2ebdcca80cf0 100644 --- a/src/rt/rust_test_helpers.c +++ b/src/rt/rust_test_helpers.c @@ -243,3 +243,7 @@ double rust_interesting_average(uint64_t n, ...) { va_end(pairs); return sum / n; } + +int32_t rust_int8_to_int32(int8_t x) { + return (int32_t)x; +} diff --git a/src/test/run-pass/cabi-int-widening.rs b/src/test/run-pass/cabi-int-widening.rs new file mode 100644 index 0000000000000..c7a2275933335 --- /dev/null +++ b/src/test/run-pass/cabi-int-widening.rs @@ -0,0 +1,22 @@ +// Copyright 2016 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. + +#[link(name = "rust_test_helpers")] +extern { + fn rust_int8_to_int32(_: i8) -> i32; +} + +fn main() { + let x = unsafe { + rust_int8_to_int32(-1) + }; + + assert!(x == -1); +} From a0943d0701d67d5260fa33dacf8afe9616e327c4 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 18 Mar 2016 15:30:15 -0600 Subject: [PATCH 5/8] Use DWARF 5 value for DW_LANG_Rust --- src/librustc_trans/debuginfo/metadata.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index 5690b18bc8ede..1b63fadca15aa 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -50,7 +50,9 @@ use syntax::{ast, codemap}; use syntax::parse::token; -const DW_LANG_RUST: c_uint = 0x9000; +// From DWARF 5. +// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1 +const DW_LANG_RUST: c_uint = 0x1c; #[allow(non_upper_case_globals)] const DW_ATE_boolean: c_uint = 0x02; #[allow(non_upper_case_globals)] From 6e41885bd813a1628b6ca54058ab9595e9957c67 Mon Sep 17 00:00:00 2001 From: Timon Van Overveldt Date: Sat, 19 Mar 2016 14:53:40 -0700 Subject: [PATCH 6/8] Fix backtraces on ARM EHABI. Before this patch, our rust_eh_personality_catch routine would cut backtracing short at the __rust_try function, due to it not handling the _US_FORCE_UNWIND bit properly, which is passed by libunwind implementations on ARM EHABI. Examples of where the _US_FORCE_UNWIND bit is passed to the PR: - GCC's libunwind: https://github.com/gcc-mirror/gcc/blob/f1717362de1e56fe1ffab540289d7d0c6ed48b20/libgcc/unwind-arm-common.inc#L590 - LLVM's libunwind: https://github.com/llvm-mirror/libunwind/blob/61278584b5c84c422ff5da10f46c3235c54636c9/src/UnwindLevel1-gcc-ext.c#L153 --- src/libstd/sys/common/unwind/gcc.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/common/unwind/gcc.rs b/src/libstd/sys/common/unwind/gcc.rs index ff6a11951dc5e..da7a340af3515 100644 --- a/src/libstd/sys/common/unwind/gcc.rs +++ b/src/libstd/sys/common/unwind/gcc.rs @@ -224,8 +224,13 @@ pub mod eabi { context: *mut uw::_Unwind_Context ) -> uw::_Unwind_Reason_Code { + // Backtraces on ARM will call the personality routine with + // state == _US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND. In those cases + // we want to continue unwinding the stack, otherwise all our backtraces + // would end at __rust_try. if (state as c_int & uw::_US_ACTION_MASK as c_int) - == uw::_US_VIRTUAL_UNWIND_FRAME as c_int { // search phase + == uw::_US_VIRTUAL_UNWIND_FRAME as c_int + && (state as c_int & uw::_US_FORCE_UNWIND as c_int) == 0 { // search phase uw::_URC_HANDLER_FOUND // catch! } else { // cleanup phase From 0936b5885d5886304ecb8639882f2e5a6d20ab7d Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 5 Apr 2016 11:02:49 +0200 Subject: [PATCH 7/8] Remove strange names created by lack of privacy-conscious name lookup The fixed issue that allowed this was #12808. --- src/liballoc/arc.rs | 44 ++++++++++++--------------- src/liballoc/rc.rs | 42 ++++++++++++------------- src/libcore/cell.rs | 74 +++++++++++++++++++++------------------------ 3 files changed, 74 insertions(+), 86 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 055029dddcddd..79bd5a9134487 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -124,9 +124,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; #[unsafe_no_drop_flag] #[stable(feature = "rust1", since = "1.0.0")] pub struct Arc { - // FIXME #12808: strange name to try to avoid interfering with - // field accesses of the contained type via Deref - _ptr: Shared>, + ptr: Shared>, } #[stable(feature = "rust1", since = "1.0.0")] @@ -144,9 +142,7 @@ impl, U: ?Sized> CoerceUnsized> for Arc {} #[unsafe_no_drop_flag] #[stable(feature = "arc_weak", since = "1.4.0")] pub struct Weak { - // FIXME #12808: strange name to try to avoid interfering with - // field accesses of the contained type via Deref - _ptr: Shared>, + ptr: Shared>, } #[stable(feature = "arc_weak", since = "1.4.0")] @@ -198,7 +194,7 @@ impl Arc { weak: atomic::AtomicUsize::new(1), data: data, }; - Arc { _ptr: unsafe { Shared::new(Box::into_raw(x)) } } + Arc { ptr: unsafe { Shared::new(Box::into_raw(x)) } } } /// Unwraps the contained value if the `Arc` has exactly one strong reference. @@ -230,11 +226,11 @@ impl Arc { atomic::fence(Acquire); unsafe { - let ptr = *this._ptr; + let ptr = *this.ptr; let elem = ptr::read(&(*ptr).data); // Make a weak pointer to clean up the implicit strong-weak reference - let _weak = Weak { _ptr: this._ptr }; + let _weak = Weak { ptr: this.ptr }; mem::forget(this); Ok(elem) @@ -274,7 +270,7 @@ impl Arc { // synchronize with the write coming from `is_unique`, so that the // events prior to that write happen before this read. match this.inner().weak.compare_exchange_weak(cur, cur + 1, Acquire, Relaxed) { - Ok(_) => return Weak { _ptr: this._ptr }, + Ok(_) => return Weak { ptr: this.ptr }, Err(old) => cur = old, } } @@ -303,13 +299,13 @@ impl Arc { // `ArcInner` structure itself is `Sync` because the inner data is // `Sync` as well, so we're ok loaning out an immutable pointer to these // contents. - unsafe { &**self._ptr } + unsafe { &**self.ptr } } // Non-inlined part of `drop`. #[inline(never)] unsafe fn drop_slow(&mut self) { - let ptr = *self._ptr; + let ptr = *self.ptr; // Destroy the data at this time, even though we may not free the box // allocation itself (there may still be weak pointers lying around). @@ -367,7 +363,7 @@ impl Clone for Arc { } } - Arc { _ptr: self._ptr } + Arc { ptr: self.ptr } } } @@ -435,7 +431,7 @@ impl Arc { // Materialize our own implicit weak pointer, so that it can clean // up the ArcInner as needed. - let weak = Weak { _ptr: this._ptr }; + let weak = Weak { ptr: this.ptr }; // mark the data itself as already deallocated unsafe { @@ -443,7 +439,7 @@ impl Arc { // here (due to zeroing) because data is no longer accessed by // other threads (due to there being no more strong refs at this // point). - let mut swap = Arc::new(ptr::read(&(**weak._ptr).data)); + let mut swap = Arc::new(ptr::read(&(**weak.ptr).data)); mem::swap(this, &mut swap); mem::forget(swap); } @@ -456,7 +452,7 @@ impl Arc { // As with `get_mut()`, the unsafety is ok because our reference was // either unique to begin with, or became one upon cloning the contents. unsafe { - let inner = &mut **this._ptr; + let inner = &mut **this.ptr; &mut inner.data } } @@ -488,7 +484,7 @@ impl Arc { // the Arc itself to be `mut`, so we're returning the only possible // reference to the inner data. unsafe { - let inner = &mut **this._ptr; + let inner = &mut **this.ptr; Some(&mut inner.data) } } else { @@ -557,7 +553,7 @@ impl Drop for Arc { // This structure has #[unsafe_no_drop_flag], so this drop glue may run // more than once (but it is guaranteed to be zeroed after the first if // it's run more than once) - let thin = *self._ptr as *const (); + let thin = *self.ptr as *const (); if thin as usize == mem::POST_DROP_USIZE { return; @@ -638,7 +634,7 @@ impl Weak { // Relaxed is valid for the same reason it is on Arc's Clone impl match inner.strong.compare_exchange_weak(n, n + 1, Relaxed, Relaxed) { - Ok(_) => return Some(Arc { _ptr: self._ptr }), + Ok(_) => return Some(Arc { ptr: self.ptr }), Err(old) => n = old, } } @@ -647,7 +643,7 @@ impl Weak { #[inline] fn inner(&self) -> &ArcInner { // See comments above for why this is "safe" - unsafe { &**self._ptr } + unsafe { &**self.ptr } } } @@ -681,7 +677,7 @@ impl Clone for Weak { } } - return Weak { _ptr: self._ptr }; + return Weak { ptr: self.ptr }; } } @@ -713,7 +709,7 @@ impl Drop for Weak { /// } // implicit drop /// ``` fn drop(&mut self) { - let ptr = *self._ptr; + let ptr = *self.ptr; let thin = ptr as *const (); // see comments above for why this check is here @@ -885,7 +881,7 @@ impl fmt::Debug for Arc { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Pointer for Arc { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Pointer::fmt(&*self._ptr, f) + fmt::Pointer::fmt(&*self.ptr, f) } } @@ -930,7 +926,7 @@ impl Weak { issue = "30425")] pub fn new() -> Weak { unsafe { - Weak { _ptr: Shared::new(Box::into_raw(box ArcInner { + Weak { ptr: Shared::new(Box::into_raw(box ArcInner { strong: atomic::AtomicUsize::new(0), weak: atomic::AtomicUsize::new(1), data: uninitialized(), diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index da803f57a59d3..c2f0a96132733 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -184,9 +184,7 @@ struct RcBox { #[unsafe_no_drop_flag] #[stable(feature = "rust1", since = "1.0.0")] pub struct Rc { - // FIXME #12808: strange names to try to avoid interfering with field - // accesses of the contained type via Deref - _ptr: Shared>, + ptr: Shared>, } #[stable(feature = "rust1", since = "1.0.0")] @@ -215,7 +213,7 @@ impl Rc { // pointers, which ensures that the weak destructor never frees // the allocation while the strong destructor is running, even // if the weak pointer is stored inside the strong one. - _ptr: Shared::new(Box::into_raw(box RcBox { + ptr: Shared::new(Box::into_raw(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value: value, @@ -254,7 +252,7 @@ impl Rc { // pointer while also handling drop logic by just crafting a // fake Weak. this.dec_strong(); - let _weak = Weak { _ptr: this._ptr }; + let _weak = Weak { ptr: this.ptr }; forget(this); Ok(val) } @@ -287,7 +285,7 @@ impl Rc { #[stable(feature = "rc_weak", since = "1.4.0")] pub fn downgrade(this: &Self) -> Weak { this.inc_weak(); - Weak { _ptr: this._ptr } + Weak { ptr: this.ptr } } /// Get the number of weak references to this value. @@ -348,7 +346,7 @@ impl Rc { #[stable(feature = "rc_unique", since = "1.4.0")] pub fn get_mut(this: &mut Self) -> Option<&mut T> { if Rc::is_unique(this) { - let inner = unsafe { &mut **this._ptr }; + let inner = unsafe { &mut **this.ptr }; Some(&mut inner.value) } else { None @@ -390,7 +388,7 @@ impl Rc { } else if Rc::weak_count(this) != 0 { // Can just steal the data, all that's left is Weaks unsafe { - let mut swap = Rc::new(ptr::read(&(**this._ptr).value)); + let mut swap = Rc::new(ptr::read(&(**this.ptr).value)); mem::swap(this, &mut swap); swap.dec_strong(); // Remove implicit strong-weak ref (no need to craft a fake @@ -404,7 +402,7 @@ impl Rc { // reference count is guaranteed to be 1 at this point, and we required // the `Rc` itself to be `mut`, so we're returning the only possible // reference to the inner value. - let inner = unsafe { &mut **this._ptr }; + let inner = unsafe { &mut **this.ptr }; &mut inner.value } } @@ -449,7 +447,7 @@ impl Drop for Rc { #[unsafe_destructor_blind_to_params] fn drop(&mut self) { unsafe { - let ptr = *self._ptr; + let ptr = *self.ptr; let thin = ptr as *const (); if thin as usize != mem::POST_DROP_USIZE { @@ -490,7 +488,7 @@ impl Clone for Rc { #[inline] fn clone(&self) -> Rc { self.inc_strong(); - Rc { _ptr: self._ptr } + Rc { ptr: self.ptr } } } @@ -691,7 +689,7 @@ impl fmt::Debug for Rc { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Pointer for Rc { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Pointer::fmt(&*self._ptr, f) + fmt::Pointer::fmt(&*self.ptr, f) } } @@ -711,9 +709,7 @@ impl From for Rc { #[unsafe_no_drop_flag] #[stable(feature = "rc_weak", since = "1.4.0")] pub struct Weak { - // FIXME #12808: strange names to try to avoid interfering with - // field accesses of the contained type via Deref - _ptr: Shared>, + ptr: Shared>, } #[stable(feature = "rc_weak", since = "1.4.0")] @@ -749,7 +745,7 @@ impl Weak { None } else { self.inc_strong(); - Some(Rc { _ptr: self._ptr }) + Some(Rc { ptr: self.ptr }) } } } @@ -783,7 +779,7 @@ impl Drop for Weak { /// ``` fn drop(&mut self) { unsafe { - let ptr = *self._ptr; + let ptr = *self.ptr; let thin = ptr as *const (); if thin as usize != mem::POST_DROP_USIZE { @@ -816,7 +812,7 @@ impl Clone for Weak { #[inline] fn clone(&self) -> Weak { self.inc_weak(); - Weak { _ptr: self._ptr } + Weak { ptr: self.ptr } } } @@ -848,7 +844,7 @@ impl Weak { pub fn new() -> Weak { unsafe { Weak { - _ptr: Shared::new(Box::into_raw(box RcBox { + ptr: Shared::new(Box::into_raw(box RcBox { strong: Cell::new(0), weak: Cell::new(1), value: uninitialized(), @@ -910,8 +906,8 @@ impl RcBoxPtr for Rc { // the contract anyway. // This allows the null check to be elided in the destructor if we // manipulated the reference count in the same function. - assume(!(*(&self._ptr as *const _ as *const *const ())).is_null()); - &(**self._ptr) + assume(!(*(&self.ptr as *const _ as *const *const ())).is_null()); + &(**self.ptr) } } } @@ -924,8 +920,8 @@ impl RcBoxPtr for Weak { // the contract anyway. // This allows the null check to be elided in the destructor if we // manipulated the reference count in the same function. - assume(!(*(&self._ptr as *const _ as *const *const ())).is_null()); - &(**self._ptr) + assume(!(*(&self.ptr as *const _ as *const *const ())).is_null()); + &(**self.ptr) } } } diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index b2cbc29b1c74c..a1c7a293af0b3 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -390,8 +390,8 @@ impl RefCell { pub fn borrow(&self) -> Ref { match BorrowRef::new(&self.borrow) { Some(b) => Ref { - _value: unsafe { &*self.value.get() }, - _borrow: b, + value: unsafe { &*self.value.get() }, + borrow: b, }, None => panic!("RefCell already mutably borrowed"), } @@ -438,8 +438,8 @@ impl RefCell { pub fn borrow_mut(&self) -> RefMut { match BorrowRefMut::new(&self.borrow) { Some(b) => RefMut { - _value: unsafe { &mut *self.value.get() }, - _borrow: b, + value: unsafe { &mut *self.value.get() }, + borrow: b, }, None => panic!("RefCell already borrowed"), } @@ -491,7 +491,7 @@ impl PartialEq for RefCell { impl Eq for RefCell {} struct BorrowRef<'b> { - _borrow: &'b Cell, + borrow: &'b Cell, } impl<'b> BorrowRef<'b> { @@ -501,7 +501,7 @@ impl<'b> BorrowRef<'b> { WRITING => None, b => { borrow.set(b + 1); - Some(BorrowRef { _borrow: borrow }) + Some(BorrowRef { borrow: borrow }) }, } } @@ -510,9 +510,9 @@ impl<'b> BorrowRef<'b> { impl<'b> Drop for BorrowRef<'b> { #[inline] fn drop(&mut self) { - let borrow = self._borrow.get(); + let borrow = self.borrow.get(); debug_assert!(borrow != WRITING && borrow != UNUSED); - self._borrow.set(borrow - 1); + self.borrow.set(borrow - 1); } } @@ -521,10 +521,10 @@ impl<'b> Clone for BorrowRef<'b> { fn clone(&self) -> BorrowRef<'b> { // Since this Ref exists, we know the borrow flag // is not set to WRITING. - let borrow = self._borrow.get(); + let borrow = self.borrow.get(); debug_assert!(borrow != WRITING && borrow != UNUSED); - self._borrow.set(borrow + 1); - BorrowRef { _borrow: self._borrow } + self.borrow.set(borrow + 1); + BorrowRef { borrow: self.borrow } } } @@ -534,10 +534,8 @@ impl<'b> Clone for BorrowRef<'b> { /// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] pub struct Ref<'b, T: ?Sized + 'b> { - // FIXME #12808: strange name to try to avoid interfering with - // field accesses of the contained type via Deref - _value: &'b T, - _borrow: BorrowRef<'b>, + value: &'b T, + borrow: BorrowRef<'b>, } #[stable(feature = "rust1", since = "1.0.0")] @@ -546,7 +544,7 @@ impl<'b, T: ?Sized> Deref for Ref<'b, T> { #[inline] fn deref(&self) -> &T { - self._value + self.value } } @@ -565,8 +563,8 @@ impl<'b, T: ?Sized> Ref<'b, T> { #[inline] pub fn clone(orig: &Ref<'b, T>) -> Ref<'b, T> { Ref { - _value: orig._value, - _borrow: orig._borrow.clone(), + value: orig.value, + borrow: orig.borrow.clone(), } } @@ -594,8 +592,8 @@ impl<'b, T: ?Sized> Ref<'b, T> { where F: FnOnce(&T) -> &U { Ref { - _value: f(orig._value), - _borrow: orig._borrow, + value: f(orig.value), + borrow: orig.borrow, } } @@ -627,9 +625,9 @@ impl<'b, T: ?Sized> Ref<'b, T> { pub fn filter_map(orig: Ref<'b, T>, f: F) -> Option> where F: FnOnce(&T) -> Option<&U> { - f(orig._value).map(move |new| Ref { - _value: new, - _borrow: orig._borrow, + f(orig.value).map(move |new| Ref { + value: new, + borrow: orig.borrow, }) } } @@ -667,8 +665,8 @@ impl<'b, T: ?Sized> RefMut<'b, T> { where F: FnOnce(&mut T) -> &mut U { RefMut { - _value: f(orig._value), - _borrow: orig._borrow, + value: f(orig.value), + borrow: orig.borrow, } } @@ -706,24 +704,24 @@ impl<'b, T: ?Sized> RefMut<'b, T> { pub fn filter_map(orig: RefMut<'b, T>, f: F) -> Option> where F: FnOnce(&mut T) -> Option<&mut U> { - let RefMut { _value, _borrow } = orig; - f(_value).map(move |new| RefMut { - _value: new, - _borrow: _borrow, + let RefMut { value, borrow } = orig; + f(value).map(move |new| RefMut { + value: new, + borrow: borrow, }) } } struct BorrowRefMut<'b> { - _borrow: &'b Cell, + borrow: &'b Cell, } impl<'b> Drop for BorrowRefMut<'b> { #[inline] fn drop(&mut self) { - let borrow = self._borrow.get(); + let borrow = self.borrow.get(); debug_assert!(borrow == WRITING); - self._borrow.set(UNUSED); + self.borrow.set(UNUSED); } } @@ -733,7 +731,7 @@ impl<'b> BorrowRefMut<'b> { match borrow.get() { UNUSED => { borrow.set(WRITING); - Some(BorrowRefMut { _borrow: borrow }) + Some(BorrowRefMut { borrow: borrow }) }, _ => None, } @@ -745,10 +743,8 @@ impl<'b> BorrowRefMut<'b> { /// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] pub struct RefMut<'b, T: ?Sized + 'b> { - // FIXME #12808: strange name to try to avoid interfering with - // field accesses of the contained type via Deref - _value: &'b mut T, - _borrow: BorrowRefMut<'b>, + value: &'b mut T, + borrow: BorrowRefMut<'b>, } #[stable(feature = "rust1", since = "1.0.0")] @@ -757,7 +753,7 @@ impl<'b, T: ?Sized> Deref for RefMut<'b, T> { #[inline] fn deref(&self) -> &T { - self._value + self.value } } @@ -765,7 +761,7 @@ impl<'b, T: ?Sized> Deref for RefMut<'b, T> { impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> { #[inline] fn deref_mut(&mut self) -> &mut T { - self._value + self.value } } From 60c988ec176b9653bc1c3a6d6a738646d15a5ad6 Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Sat, 2 Apr 2016 19:06:16 +0200 Subject: [PATCH 8/8] Fix libstd on DragonFly Following changes: * birthtime does not exist on DragonFly * errno: __dfly_error is no more. Use #[thread_local] static errno. * clock_gettime expects a c_ulong (use a type alias) These changes are required to build DragonFly snapshots again. --- src/libstd/os/dragonfly/fs.rs | 10 ---------- src/libstd/sys/unix/os.rs | 12 +++++++++++- src/libstd/sys/unix/time.rs | 7 ++++++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/libstd/os/dragonfly/fs.rs b/src/libstd/os/dragonfly/fs.rs index eb09800a18cb0..db672e5643531 100644 --- a/src/libstd/os/dragonfly/fs.rs +++ b/src/libstd/os/dragonfly/fs.rs @@ -63,10 +63,6 @@ pub trait MetadataExt { #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_ctime_nsec(&self) -> i64; #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_birthtime(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_birthtime_nsec(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_blksize(&self) -> u64; #[stable(feature = "metadata_ext2", since = "1.8.0")] fn st_blocks(&self) -> u64; @@ -129,12 +125,6 @@ impl MetadataExt for Metadata { fn st_ctime_nsec(&self) -> i64 { self.as_inner().as_inner().st_ctime_nsec as i64 } - fn st_birthtime(&self) -> i64 { - self.as_inner().as_inner().st_birthtime as i64 - } - fn st_birthtime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_birthtime_nsec as i64 - } fn st_blksize(&self) -> u64 { self.as_inner().as_inner().st_blksize as u64 } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index eed62c9ecfd15..94ebbd70ae83d 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -36,6 +36,7 @@ const TMPBUF_SZ: usize = 128; static ENV_LOCK: StaticMutex = StaticMutex::new(); /// Returns the platform-specific value of errno +#[cfg(not(target_os = "dragonfly"))] pub fn errno() -> i32 { extern { #[cfg_attr(any(target_os = "linux", target_os = "emscripten"), @@ -47,7 +48,6 @@ pub fn errno() -> i32 { target_env = "newlib"), link_name = "__errno")] #[cfg_attr(target_os = "solaris", link_name = "___errno")] - #[cfg_attr(target_os = "dragonfly", link_name = "__dfly_error")] #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "freebsd"), @@ -60,6 +60,16 @@ pub fn errno() -> i32 { } } +#[cfg(target_os = "dragonfly")] +pub fn errno() -> i32 { + extern { + #[thread_local] + static errno: c_int; + } + + errno as i32 +} + /// Gets a detailed string description for the given error number. pub fn error_string(errno: i32) -> String { extern { diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 1444cf31e853b..cc7abe25e35e5 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -303,8 +303,13 @@ mod inner { } } + #[cfg(not(target_os = "dragonfly"))] + pub type clock_t = libc::c_int; + #[cfg(target_os = "dragonfly")] + pub type clock_t = libc::c_ulong; + impl Timespec { - pub fn now(clock: libc::c_int) -> Timespec { + pub fn now(clock: clock_t) -> Timespec { let mut t = Timespec { t: libc::timespec { tv_sec: 0,