Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"

[[package]]
name = "ar_archive_writer"
version = "0.5.3"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73cd58deff2140a0a8eae87e417bd01db68a33e148aa93d1e8cd837e55e312b6"
checksum = "523e5e187fff36fcb8d1d19ccf0ca4ca43ec3d158316057f66dc6f72716bc5ec"
dependencies = [
"object 0.39.1",
]
Expand Down
3 changes: 1 addition & 2 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,7 @@
# Indicates whether stack protectors should be used
# via the unstable option `-Zstack-protector`.
#
# Valid options are : `none`(default),`basic`,`strong`, or `all`.
# `strong` and `basic` options may be buggy and are not recommended, see rust-lang/rust#114903.
# Valid options are : `none`(default), `strong`, or `all`.
#rust.stack-protector = "none"

# Prints each test name as it is executed, to help debug issues in the test harness itself.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_gcc/src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ pub fn new_context<'gcc>(sess: &Session) -> Context<'gcc> {
match sess.stack_protector() {
StackProtector::All => context.add_command_line_option("-fstack-protector-all"),
StackProtector::Strong => context.add_command_line_option("-fstack-protector-strong"),
StackProtector::Basic => context.add_command_line_option("-fstack-protector"),
StackProtector::None => (),
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ fn stackprotector_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll A
StackProtector::None => return None,
StackProtector::All => AttributeKind::StackProtectReq,
StackProtector::Strong => AttributeKind::StackProtectStrong,
StackProtector::Basic => AttributeKind::StackProtect,
};

Some(sspattr.create_attr(cx.llcx))
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,7 @@ mod desc {
"either no value or one of `legacy` (the default), `off`, or `next`";
pub(crate) const parse_annotate_moves: &str =
"either a boolean (`yes`, `no`, `on`, `off`, etc.), or a size limit in bytes";
pub(crate) const parse_stack_protector: &str =
"one of (`none` (default), `basic`, `strong`, or `all`)";
pub(crate) const parse_stack_protector: &str = "one of (`none` (default), `strong`, or `all`)";
pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set)";
pub(crate) const parse_proc_macro_execution_strategy: &str =
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_session/src/options/mitigation_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ impl DeniedPartialMitigationLevel {
pub fn level_str(&self) -> &'static str {
match self {
DeniedPartialMitigationLevel::StackProtector(StackProtector::All) => "=all",
DeniedPartialMitigationLevel::StackProtector(StackProtector::Basic) => "=basic",
DeniedPartialMitigationLevel::StackProtector(StackProtector::Strong) => "=strong",
// currently `=disabled` should not appear
DeniedPartialMitigationLevel::Enabled(false) => "=disabled",
Expand All @@ -36,9 +35,6 @@ impl std::fmt::Display for DeniedPartialMitigationLevel {
DeniedPartialMitigationLevel::StackProtector(StackProtector::All) => {
write!(f, "all")
}
DeniedPartialMitigationLevel::StackProtector(StackProtector::Basic) => {
write!(f, "basic")
}
DeniedPartialMitigationLevel::StackProtector(StackProtector::Strong) => {
write!(f, "strong")
}
Expand Down
125 changes: 57 additions & 68 deletions compiler/rustc_span/src/span_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,32 +352,13 @@ impl Interned {
}
const _: () = Interned::INDEX.assert_is_bottom();

// This code is very hot, and converting span to an enum and matching on it doesn't optimize away
// properly. So we are using a macro emulating such a match, but expand it directly to an if-else
// chain.
macro_rules! match_span_kind {
(
$span:expr,
InlineCtxt($span1:ident) => $arm1:expr,
InlineParent($span2:ident) => $arm2:expr,
InlinePair($span3:ident) => $arm3:expr,
Interned($span4:ident) => $arm4:expr,
) => {{
let span64 = $span.0;
if InlineCtxt::PREFIX.get(span64) == InlineCtxt::PREFIX_VALUE {
let $span1 = InlineCtxt::from_span($span);
$arm1
} else if InlineParent::PREFIX.get(span64) == InlineParent::PREFIX_VALUE {
let $span2 = InlineParent::from_span($span);
$arm2
} else if InlinePair::PREFIX.get(span64) == InlinePair::PREFIX_VALUE {
let $span3 = InlinePair::from_span($span);
$arm3
} else {
let $span4 = Interned::from_span($span);
$arm4
}
}};
/// Values of this type should never actually be materialized, because they are just temporaries
/// and `Span::kind` is inlined.
enum SpanKind {
InlineCtxt(InlineCtxt),
InlineParent(InlineParent),
InlinePair(InlinePair),
Interned(Interned),
}

/// The dummy span has zero position, length, and context, and no parent.
Expand Down Expand Up @@ -446,6 +427,20 @@ impl Span {
.or_else(|| InlinePair::try_new_span(lo, len, ctxt, parent))
}

#[inline]
fn kind(self) -> SpanKind {
let span64 = self.0;
if InlineCtxt::PREFIX.get(span64) == InlineCtxt::PREFIX_VALUE {
SpanKind::InlineCtxt(InlineCtxt::from_span(self))
} else if InlineParent::PREFIX.get(span64) == InlineParent::PREFIX_VALUE {
SpanKind::InlineParent(InlineParent::from_span(self))
} else if InlinePair::PREFIX.get(span64) == InlinePair::PREFIX_VALUE {
SpanKind::InlinePair(InlinePair::from_span(self))
} else {
SpanKind::Interned(Interned::from_span(self))
}
}

#[inline]
pub fn data(self) -> SpanData {
let data = self.data_untracked();
Expand All @@ -459,12 +454,11 @@ impl Span {
/// This function must not be used outside the incremental engine.
#[inline]
pub fn data_untracked(self) -> SpanData {
match_span_kind! {
self,
InlineCtxt(span) => span.data(),
InlineParent(span) => span.data(),
InlinePair(span) => span.data(),
Interned(span) => span.data(),
match self.kind() {
SpanKind::InlineCtxt(span) => span.data(),
SpanKind::InlineParent(span) => span.data(),
SpanKind::InlinePair(span) => span.data(),
SpanKind::Interned(span) => span.data(),
}
}

Expand All @@ -478,20 +472,18 @@ impl Span {
/// means it's not the same as an equality comparison with `DUMMY_SP`.
#[inline]
pub fn is_dummy(self) -> bool {
match_span_kind! {
self,
InlineCtxt(span) => span.lo == 0 && span.len == 0,
InlineParent(span) => span.lo == 0 && span.len == 0,
InlinePair(span) => span.lo == 0 && span.len == 0,
Interned(span) => span.data().is_dummy(),
match self.kind() {
SpanKind::InlineCtxt(span) => span.lo == 0 && span.len == 0,
SpanKind::InlineParent(span) => span.lo == 0 && span.len == 0,
SpanKind::InlinePair(span) => span.lo == 0 && span.len == 0,
SpanKind::Interned(span) => span.data().is_dummy(),
}
}

#[inline]
pub fn map_ctxt(self, map: impl FnOnce(SyntaxContext) -> SyntaxContext) -> Span {
let data = match_span_kind! {
self,
InlineCtxt(span) => {
let data = match self.kind() {
SpanKind::InlineCtxt(span) => {
// This format occurs 1-2 orders of magnitude more often than others (#125017),
// so it makes sense to micro-optimize it to avoid `span.data()` and `Span::new()`.
let new_ctxt = map(SyntaxContext::from_u32(span.ctxt));
Expand All @@ -501,10 +493,10 @@ impl Span {
} else {
span.data().with_ctxt(new_ctxt)
};
},
InlineParent(span) => span.data(),
InlinePair(span) => span.data(),
Interned(span) => span.data(),
}
SpanKind::InlineParent(span) => span.data(),
SpanKind::InlinePair(span) => span.data(),
SpanKind::Interned(span) => span.data(),
};

data.with_ctxt(map(data.ctxt))
Expand All @@ -514,37 +506,35 @@ impl Span {
/// It's a cut-down version of `data_untracked` and doesn't require taking the interner lock.
#[inline]
pub fn ctxt(self) -> SyntaxContext {
let ctxt32 = match_span_kind! {
self,
InlineCtxt(span) => span.ctxt,
InlineParent(_span) => return SyntaxContext::root(),
InlinePair(span) => span.ctxt,
Interned(span) => span.ctxt,
};
SyntaxContext::from_u32(ctxt32)
SyntaxContext::from_u32(match self.kind() {
SpanKind::InlineCtxt(span) => span.ctxt,
SpanKind::InlineParent(_span) => return SyntaxContext::root(),
SpanKind::InlinePair(span) => span.ctxt,
SpanKind::Interned(span) => span.ctxt,
})
}

#[inline]
pub fn with_parent(self, parent: Option<LocalDefId>) -> Span {
let data = match_span_kind! {
self,
InlineCtxt(span) => {
let data = match self.kind() {
SpanKind::InlineCtxt(span) => {
// This format occurs 1-2 orders of magnitude more often than others (#126544),
// so it makes sense to micro-optimize it to avoid `span.data()`.
match parent {
None => return self,
Some(parent)
if let Some(span) =
Span::try_new_span_with_parent(span.lo, span.len, span.ctxt, parent) =>
if let Some(span) = Span::try_new_span_with_parent(
span.lo, span.len, span.ctxt, parent,
) =>
{
return span;
}
_ => span.data(),
}
},
InlineParent(span) => span.data(),
InlinePair(span) => span.data(),
Interned(span) => span.data(),
}
SpanKind::InlineParent(span) => span.data(),
SpanKind::InlinePair(span) => span.data(),
SpanKind::Interned(span) => span.data(),
};

if let Some(old_parent) = data.parent {
Expand All @@ -556,12 +546,11 @@ impl Span {
#[inline]
pub fn parent(self) -> Option<LocalDefId> {
let to_parent = |parent| Some(LocalDefId { local_def_index: DefIndex::from_u32(parent) });
match_span_kind! {
self,
InlineCtxt(_span) => None,
InlineParent(span) => to_parent(span.parent),
InlinePair(span) => to_parent(span.parent),
Interned(span) => span.data().parent,
match self.kind() {
SpanKind::InlineCtxt(_span) => None,
SpanKind::InlineParent(span) => to_parent(span.parent),
SpanKind::InlinePair(span) => to_parent(span.parent),
SpanKind::Interned(span) => span.data().parent,
}
}

Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,12 +1204,6 @@ crate::target_spec_enum! {
/// Disable stack canary generation.
None = "none",

/// On LLVM, mark all generated LLVM functions with the `ssp` attribute (see
/// llvm/docs/LangRef.rst). This triggers stack canary generation in
/// functions which contain an array of a byte-sized type with more than
/// eight elements.
Basic = "basic",

/// On LLVM, mark all generated LLVM functions with the `sspstrong`
/// attribute (see llvm/docs/LangRef.rst). This triggers stack canary
/// generation in functions which either contain an array, or which take
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ impl char {
///
/// ## Greek sigma
///
/// In Greek, the letter simga (uppercase 'Σ') has two lowercase forms:
/// In Greek, the letter sigma (uppercase 'Σ') has two lowercase forms:
/// 'σ' which is used in most situations, and 'ς' which appears only
/// at the end of a word. [`char::to_lowercase()`] always uses the first form:
///
Expand Down
7 changes: 4 additions & 3 deletions library/std/src/sys/thread/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ impl Thread {
// >= PTHREAD_STACK_MIN, it must be an alignment issue.
// Round up to the nearest page and try again.
let page_size = sys::pal::conf::page_size();
let stack_size =
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
let stack_size = stack_size.checked_next_multiple_of(page_size);

// Some libc implementations, e.g. musl, place an upper bound
// on the stack size, in which case we can only gracefully return
// an error here.
if libc::pthread_attr_setstacksize(attr.get(), stack_size) != 0 {
if stack_size.is_none_or(|stack_size| {
libc::pthread_attr_setstacksize(attr.get(), stack_size) != 0
}) {
return Err(io::const_error!(
io::ErrorKind::InvalidInput,
"invalid stack size"
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/thread/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,14 @@ fn test_minimal_thread_stack() {
assert_eq!(before, 0);
assert_eq!(COUNT.load(Ordering::Relaxed), 1);
}

// Test that a stack size too large to round up to the page size is an error.
// The cfg mirrors the one around the rounding in the unix `Thread::new`.
#[cfg(all(unix, not(any(target_os = "espidf", target_os = "nuttx"))))]
// FIXME(https://github.com/rust-lang/miri/issues/5594): Miri ignores the requested stack size.
#[cfg_attr(skip_unsupported_miri_tests, ignore)]
#[test]
fn test_huge_thread_stack() {
let builder = thread::Builder::new().stack_size(usize::MAX);
assert!(builder.spawn(|| {}).is_err());
}
Loading
Loading