Skip to content

Commit c5fbcd3

Browse files
committed
Auto merge of #86186 - JohnTitor:rollup-upaw6wx, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #82037 (Make symbols stripping work on MacOS X) - #84687 (Multiple improvements to RwLocks) - #85997 (rustdoc: Print a warning if the diff when comparing to old nightlies is empty) - #86051 (Updated code examples and wording in move keyword documentation ) - #86111 (fix off by one in `std::iter::Iterator` documentation) - #86113 (build doctests with lld if use-lld = true) - #86175 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1639a16 + a6b7e1c commit c5fbcd3

File tree

20 files changed

+219
-184
lines changed

20 files changed

+219
-184
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+42-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_fs_util::fix_windows_verbatim_for_gcc;
55
use rustc_hir::def_id::CrateNum;
66
use rustc_middle::middle::cstore::{DllImport, LibSource};
77
use rustc_middle::middle::dependency_format::Linkage;
8-
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo};
8+
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, Strip};
99
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest};
1010
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
1111
use rustc_session::search_paths::PathKind;
@@ -907,14 +907,6 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
907907
}
908908
}
909909

910-
fn escape_string(s: &[u8]) -> String {
911-
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
912-
let mut x = "Non-UTF-8 output: ".to_string();
913-
x.extend(s.iter().flat_map(|&b| ascii::escape_default(b)).map(char::from));
914-
x
915-
})
916-
}
917-
918910
match prog {
919911
Ok(prog) => {
920912
if !prog.status.success() {
@@ -1056,6 +1048,47 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
10561048
// ... and otherwise we're processing a `*.dwp` packed dwarf file.
10571049
SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
10581050
}
1051+
1052+
if sess.target.is_like_osx {
1053+
if let Some(option) = osx_strip_opt(sess.opts.debugging_opts.strip) {
1054+
strip_symbols_in_osx(sess, &out_filename, option);
1055+
}
1056+
}
1057+
}
1058+
1059+
fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: &str) {
1060+
let prog = Command::new("strip").arg(option).arg(out_filename).output();
1061+
match prog {
1062+
Ok(prog) => {
1063+
if !prog.status.success() {
1064+
let mut output = prog.stderr.clone();
1065+
output.extend_from_slice(&prog.stdout);
1066+
sess.struct_warn(&format!(
1067+
"stripping debug info with `strip` failed: {}",
1068+
prog.status
1069+
))
1070+
.note(&escape_string(&output))
1071+
.emit();
1072+
}
1073+
}
1074+
Err(e) => sess.fatal(&format!("unable to run `strip`: {}", e)),
1075+
}
1076+
}
1077+
1078+
fn osx_strip_opt<'a>(strip: Strip) -> Option<&'a str> {
1079+
match strip {
1080+
Strip::Debuginfo => Some("-S"),
1081+
Strip::Symbols => Some("-x"),
1082+
Strip::None => None,
1083+
}
1084+
}
1085+
1086+
fn escape_string(s: &[u8]) -> String {
1087+
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
1088+
let mut x = "Non-UTF-8 output: ".to_string();
1089+
x.extend(s.iter().flat_map(|&b| ascii::escape_default(b)).map(char::from));
1090+
x
1091+
})
10591092
}
10601093

10611094
fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) {

Diff for: compiler/rustc_codegen_ssa/src/back/linker.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -526,15 +526,18 @@ impl<'a> Linker for GccLinker<'a> {
526526
fn control_flow_guard(&mut self) {}
527527

528528
fn debuginfo(&mut self, strip: Strip) {
529+
// MacOS linker doesn't support stripping symbols directly anymore.
530+
if self.sess.target.is_like_osx {
531+
return;
532+
}
533+
529534
match strip {
530535
Strip::None => {}
531536
Strip::Debuginfo => {
532-
// MacOS linker does not support longhand argument --strip-debug
533-
self.linker_arg("-S");
537+
self.linker_arg("--strip-debug");
534538
}
535539
Strip::Symbols => {
536-
// MacOS linker does not support longhand argument --strip-all
537-
self.linker_arg("-s");
540+
self.linker_arg("--strip-all");
538541
}
539542
}
540543
}

Diff for: library/core/src/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait Iterator {
138138
/// A more complex example:
139139
///
140140
/// ```
141-
/// // The even numbers from zero to ten.
141+
/// // The even numbers in the range of zero to nine.
142142
/// let iter = (0..10).filter(|x| x % 2 == 0);
143143
///
144144
/// // We might iterate from zero to ten times. Knowing that it's five

Diff for: library/std/src/keyword_docs.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,13 @@ mod mod_keyword {}
987987
/// Capture a [closure]'s environment by value.
988988
///
989989
/// `move` converts any variables captured by reference or mutable reference
990-
/// to owned by value variables.
990+
/// to variables captured by value.
991991
///
992992
/// ```rust
993-
/// let capture = "hello";
994-
/// let closure = move || {
995-
/// println!("rust says {}", capture);
996-
/// };
993+
/// let data = vec![1, 2, 3];
994+
/// let closure = move || println!("captured {:?} by value", data);
995+
///
996+
/// // data is no longer available, it is owned by the closure
997997
/// ```
998998
///
999999
/// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
@@ -1004,31 +1004,29 @@ mod mod_keyword {}
10041004
/// ```rust
10051005
/// fn create_fn() -> impl Fn() {
10061006
/// let text = "Fn".to_owned();
1007-
///
10081007
/// move || println!("This is a: {}", text)
10091008
/// }
10101009
///
10111010
/// let fn_plain = create_fn();
1012-
///
10131011
/// fn_plain();
10141012
/// ```
10151013
///
10161014
/// `move` is often used when [threads] are involved.
10171015
///
10181016
/// ```rust
1019-
/// let x = 5;
1017+
/// let data = vec![1, 2, 3];
10201018
///
10211019
/// std::thread::spawn(move || {
1022-
/// println!("captured {} by value", x)
1020+
/// println!("captured {:?} by value", data)
10231021
/// }).join().unwrap();
10241022
///
1025-
/// // x is no longer available
1023+
/// // data was moved to the spawned thread, so we cannot use it here
10261024
/// ```
10271025
///
10281026
/// `move` is also valid before an async block.
10291027
///
10301028
/// ```rust
1031-
/// let capture = "hello";
1029+
/// let capture = "hello".to_owned();
10321030
/// let block = async move {
10331031
/// println!("rust says {} from async block", capture);
10341032
/// };

Diff for: library/std/src/panicking.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::process;
1919
use crate::sync::atomic::{AtomicBool, Ordering};
2020
use crate::sys::stdio::panic_output;
2121
use crate::sys_common::backtrace::{self, RustBacktrace};
22-
use crate::sys_common::rwlock::RWLock;
22+
use crate::sys_common::rwlock::StaticRWLock;
2323
use crate::sys_common::thread_info;
2424
use crate::thread;
2525

@@ -74,7 +74,7 @@ enum Hook {
7474
Custom(*mut (dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send)),
7575
}
7676

77-
static HOOK_LOCK: RWLock = RWLock::new();
77+
static HOOK_LOCK: StaticRWLock = StaticRWLock::new();
7878
static mut HOOK: Hook = Hook::Default;
7979

8080
/// Registers a custom panic hook, replacing any that was previously registered.
@@ -117,10 +117,10 @@ pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) {
117117
}
118118

119119
unsafe {
120-
HOOK_LOCK.write();
120+
let guard = HOOK_LOCK.write();
121121
let old_hook = HOOK;
122122
HOOK = Hook::Custom(Box::into_raw(hook));
123-
HOOK_LOCK.write_unlock();
123+
drop(guard);
124124

125125
if let Hook::Custom(ptr) = old_hook {
126126
#[allow(unused_must_use)]
@@ -165,10 +165,10 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
165165
}
166166

167167
unsafe {
168-
HOOK_LOCK.write();
168+
let guard = HOOK_LOCK.write();
169169
let hook = HOOK;
170170
HOOK = Hook::Default;
171-
HOOK_LOCK.write_unlock();
171+
drop(guard);
172172

173173
match hook {
174174
Hook::Default => Box::new(default_hook),
@@ -608,7 +608,7 @@ fn rust_panic_with_hook(
608608

609609
unsafe {
610610
let mut info = PanicInfo::internal_constructor(message, location);
611-
HOOK_LOCK.read();
611+
let _guard = HOOK_LOCK.read();
612612
match HOOK {
613613
// Some platforms (like wasm) know that printing to stderr won't ever actually
614614
// print anything, and if that's the case we can skip the default
@@ -626,7 +626,6 @@ fn rust_panic_with_hook(
626626
(*ptr)(&info);
627627
}
628628
};
629-
HOOK_LOCK.read_unlock();
630629
}
631630

632631
if panics > 1 {

Diff for: library/std/src/sync/rwlock.rs

+4-30
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ mod tests;
33

44
use crate::cell::UnsafeCell;
55
use crate::fmt;
6-
use crate::mem;
76
use crate::ops::{Deref, DerefMut};
8-
use crate::ptr;
97
use crate::sync::{poison, LockResult, TryLockError, TryLockResult};
108
use crate::sys_common::rwlock as sys;
119

@@ -66,7 +64,7 @@ use crate::sys_common::rwlock as sys;
6664
/// [`Mutex`]: super::Mutex
6765
#[stable(feature = "rust1", since = "1.0.0")]
6866
pub struct RwLock<T: ?Sized> {
69-
inner: Box<sys::RWLock>,
67+
inner: sys::MovableRWLock,
7068
poison: poison::Flag,
7169
data: UnsafeCell<T>,
7270
}
@@ -130,7 +128,7 @@ impl<T> RwLock<T> {
130128
#[stable(feature = "rust1", since = "1.0.0")]
131129
pub fn new(t: T) -> RwLock<T> {
132130
RwLock {
133-
inner: box sys::RWLock::new(),
131+
inner: sys::MovableRWLock::new(),
134132
poison: poison::Flag::new(),
135133
data: UnsafeCell::new(t),
136134
}
@@ -376,24 +374,8 @@ impl<T: ?Sized> RwLock<T> {
376374
where
377375
T: Sized,
378376
{
379-
// We know statically that there are no outstanding references to
380-
// `self` so there's no need to lock the inner lock.
381-
//
382-
// To get the inner value, we'd like to call `data.into_inner()`,
383-
// but because `RwLock` impl-s `Drop`, we can't move out of it, so
384-
// we'll have to destructure it manually instead.
385-
unsafe {
386-
// Like `let RwLock { inner, poison, data } = self`.
387-
let (inner, poison, data) = {
388-
let RwLock { ref inner, ref poison, ref data } = self;
389-
(ptr::read(inner), ptr::read(poison), ptr::read(data))
390-
};
391-
mem::forget(self);
392-
inner.destroy(); // Keep in sync with the `Drop` impl.
393-
drop(inner);
394-
395-
poison::map_result(poison.borrow(), |_| data.into_inner())
396-
}
377+
let data = self.data.into_inner();
378+
poison::map_result(self.poison.borrow(), |_| data)
397379
}
398380

399381
/// Returns a mutable reference to the underlying data.
@@ -424,14 +406,6 @@ impl<T: ?Sized> RwLock<T> {
424406
}
425407
}
426408

427-
#[stable(feature = "rust1", since = "1.0.0")]
428-
unsafe impl<#[may_dangle] T: ?Sized> Drop for RwLock<T> {
429-
fn drop(&mut self) {
430-
// IMPORTANT: This code needs to be kept in sync with `RwLock::into_inner`.
431-
unsafe { self.inner.destroy() }
432-
}
433-
}
434-
435409
#[stable(feature = "rust1", since = "1.0.0")]
436410
impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
437411
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

Diff for: library/std/src/sys/hermit/rwlock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub struct RWLock {
88
state: UnsafeCell<State>,
99
}
1010

11+
pub type MovableRWLock = Box<RWLock>;
12+
1113
enum State {
1214
Unlocked,
1315
Reading(usize),

Diff for: library/std/src/sys/sgx/rwlock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub struct RWLock {
1313
writer: SpinMutex<WaitVariable<bool>>,
1414
}
1515

16+
pub type MovableRWLock = Box<RWLock>;
17+
1618
// Check at compile time that RWLock size matches C definition (see test_c_rwlock_initializer below)
1719
//
1820
// # Safety

Diff for: library/std/src/sys/unix/os.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use crate::str;
2020
use crate::sys::cvt;
2121
use crate::sys::fd;
2222
use crate::sys::memchr;
23-
use crate::sys::rwlock::{RWLockReadGuard, StaticRWLock};
24-
use crate::sys_common::mutex::{StaticMutex, StaticMutexGuard};
23+
use crate::sys_common::rwlock::{StaticRWLock, StaticRWLockReadGuard};
2524
use crate::vec;
2625

2726
use libc::{c_char, c_int, c_void};
@@ -490,8 +489,8 @@ pub unsafe fn environ() -> *mut *const *const c_char {
490489

491490
static ENV_LOCK: StaticRWLock = StaticRWLock::new();
492491

493-
pub fn env_read_lock() -> RWLockReadGuard {
494-
ENV_LOCK.read_with_guard()
492+
pub fn env_read_lock() -> StaticRWLockReadGuard {
493+
ENV_LOCK.read()
495494
}
496495

497496
/// Returns a vector of (variable, value) byte-vector pairs for all the
@@ -551,7 +550,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
551550
let v = CString::new(v.as_bytes())?;
552551

553552
unsafe {
554-
let _guard = ENV_LOCK.write_with_guard();
553+
let _guard = ENV_LOCK.write();
555554
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop)
556555
}
557556
}
@@ -560,7 +559,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
560559
let nbuf = CString::new(n.as_bytes())?;
561560

562561
unsafe {
563-
let _guard = ENV_LOCK.write_with_guard();
562+
let _guard = ENV_LOCK.write();
564563
cvt(libc::unsetenv(nbuf.as_ptr())).map(drop)
565564
}
566565
}

0 commit comments

Comments
 (0)