Skip to content

Commit ffa0d7e

Browse files
committed
Auto merge of rust-lang#129949 - tgross35:rollup-352zljc, r=tgross35
Rollup of 8 pull requests Successful merges: - rust-lang#101339 (enable -Zrandomize-layout in debug CI builds ) - rust-lang#127021 (Add target support for RTEMS Arm) - rust-lang#128871 (bypass linker configuration and cross target check for specific commands) - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance) - rust-lang#129529 (Add test to build crates used by r-a on stable) - rust-lang#129624 (Adjust `memchr` pinning and run `cargo update`) - rust-lang#129796 (Unify scraped examples with other code examples) - rust-lang#129939 (explain why Rvalue::Len still exists) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 842d6fc + 6aeb9b4 commit ffa0d7e

File tree

87 files changed

+1737
-597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1737
-597
lines changed

Cargo.lock

+154-131
Large diffs are not rendered by default.

compiler/rustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ features = ['unprefixed_malloc_on_supported_platforms']
3030
jemalloc = ['dep:jemalloc-sys']
3131
llvm = ['rustc_driver_impl/llvm']
3232
max_level_info = ['rustc_driver_impl/max_level_info']
33+
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
3334
rustc_use_parallel_compiler = ['rustc_driver_impl/rustc_use_parallel_compiler']
3435
# tidy-alphabetical-end

compiler/rustc_abi/src/layout.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ fn univariant<
968968
let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align };
969969
let mut max_repr_align = repr.align;
970970
let mut inverse_memory_index: IndexVec<u32, FieldIdx> = fields.indices().collect();
971-
let optimize = !repr.inhibit_struct_field_reordering();
972-
if optimize && fields.len() > 1 {
971+
let optimize_field_order = !repr.inhibit_struct_field_reordering();
972+
if optimize_field_order && fields.len() > 1 {
973973
let end = if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
974974
let optimizing = &mut inverse_memory_index.raw[..end];
975975
let fields_excluding_tail = &fields.raw[..end];
@@ -1176,7 +1176,7 @@ fn univariant<
11761176
// If field 5 has offset 0, offsets[0] is 5, and memory_index[5] should be 0.
11771177
// Field 5 would be the first element, so memory_index is i:
11781178
// Note: if we didn't optimize, it's already right.
1179-
let memory_index = if optimize {
1179+
let memory_index = if optimize_field_order {
11801180
inverse_memory_index.invert_bijective_mapping()
11811181
} else {
11821182
debug_assert!(inverse_memory_index.iter().copied().eq(fields.indices()));
@@ -1189,6 +1189,9 @@ fn univariant<
11891189
}
11901190
let mut layout_of_single_non_zst_field = None;
11911191
let mut abi = Abi::Aggregate { sized };
1192+
1193+
let optimize_abi = !repr.inhibit_newtype_abi_optimization();
1194+
11921195
// Try to make this a Scalar/ScalarPair.
11931196
if sized && size.bytes() > 0 {
11941197
// We skip *all* ZST here and later check if we are good in terms of alignment.
@@ -1205,7 +1208,7 @@ fn univariant<
12051208
match field.abi {
12061209
// For plain scalars, or vectors of them, we can't unpack
12071210
// newtypes for `#[repr(C)]`, as that affects C ABIs.
1208-
Abi::Scalar(_) | Abi::Vector { .. } if optimize => {
1211+
Abi::Scalar(_) | Abi::Vector { .. } if optimize_abi => {
12091212
abi = field.abi;
12101213
}
12111214
// But scalar pairs are Rust-specific and get

compiler/rustc_abi/src/lib.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ bitflags! {
4343
const IS_SIMD = 1 << 1;
4444
const IS_TRANSPARENT = 1 << 2;
4545
// Internal only for now. If true, don't reorder fields.
46+
// On its own it does not prevent ABI optimizations.
4647
const IS_LINEAR = 1 << 3;
47-
// If true, the type's layout can be randomized using
48-
// the seed stored in `ReprOptions.field_shuffle_seed`
48+
// If true, the type's crate has opted into layout randomization.
49+
// Other flags can still inhibit reordering and thus randomization.
50+
// The seed stored in `ReprOptions.field_shuffle_seed`.
4951
const RANDOMIZE_LAYOUT = 1 << 4;
5052
// Any of these flags being set prevent field reordering optimisation.
51-
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits()
53+
const FIELD_ORDER_UNOPTIMIZABLE = ReprFlags::IS_C.bits()
5254
| ReprFlags::IS_SIMD.bits()
5355
| ReprFlags::IS_LINEAR.bits();
56+
const ABI_UNOPTIMIZABLE = ReprFlags::IS_C.bits() | ReprFlags::IS_SIMD.bits();
5457
}
5558
}
5659

@@ -139,10 +142,14 @@ impl ReprOptions {
139142
self.c() || self.int.is_some()
140143
}
141144

145+
pub fn inhibit_newtype_abi_optimization(&self) -> bool {
146+
self.flags.intersects(ReprFlags::ABI_UNOPTIMIZABLE)
147+
}
148+
142149
/// Returns `true` if this `#[repr()]` guarantees a fixed field order,
143150
/// e.g. `repr(C)` or `repr(<int>)`.
144151
pub fn inhibit_struct_field_reordering(&self) -> bool {
145-
self.flags.intersects(ReprFlags::IS_UNOPTIMISABLE) || self.int.is_some()
152+
self.flags.intersects(ReprFlags::FIELD_ORDER_UNOPTIMIZABLE) || self.int.is_some()
146153
}
147154

148155
/// Returns `true` if this type is valid for reordering and `-Z randomize-layout`

compiler/rustc_ast/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
# FIXME: bumping memchr to 2.7.1 causes linker errors in MSVC thin-lto
87
# tidy-alphabetical-start
98
bitflags = "2.4.1"
10-
memchr = "=2.5.0"
9+
memchr = "2.7.4"
1110
rustc_ast_ir = { path = "../rustc_ast_ir" }
1211
rustc_data_structures = { path = "../rustc_data_structures" }
1312
rustc_index = { path = "../rustc_index" }

compiler/rustc_driver_impl/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rustc_hir_analysis = { path = "../rustc_hir_analysis" }
2323
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
2424
rustc_hir_typeck = { path = "../rustc_hir_typeck" }
2525
rustc_incremental = { path = "../rustc_incremental" }
26+
rustc_index = { path = "../rustc_index" }
2627
rustc_infer = { path = "../rustc_infer" }
2728
rustc_interface = { path = "../rustc_interface" }
2829
rustc_lint = { path = "../rustc_lint" }
@@ -72,6 +73,10 @@ ctrlc = "3.4.4"
7273
# tidy-alphabetical-start
7374
llvm = ['rustc_interface/llvm']
7475
max_level_info = ['rustc_log/max_level_info']
76+
rustc_randomized_layouts = [
77+
'rustc_index/rustc_randomized_layouts',
78+
'rustc_middle/rustc_randomized_layouts'
79+
]
7580
rustc_use_parallel_compiler = [
7681
'rustc_data_structures/rustc_use_parallel_compiler',
7782
'rustc_interface/rustc_use_parallel_compiler',

compiler/rustc_index/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ nightly = [
2020
"dep:rustc_macros",
2121
"rustc_index_macros/nightly",
2222
]
23+
rustc_randomized_layouts = []
2324
# tidy-alphabetical-end

compiler/rustc_index/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ pub use vec::IndexVec;
3333
///
3434
/// </div>
3535
#[macro_export]
36+
#[cfg(not(feature = "rustc_randomized_layouts"))]
3637
macro_rules! static_assert_size {
3738
($ty:ty, $size:expr) => {
3839
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
3940
};
4041
}
42+
43+
#[macro_export]
44+
#[cfg(feature = "rustc_randomized_layouts")]
45+
macro_rules! static_assert_size {
46+
($ty:ty, $size:expr) => {
47+
// no effect other than using the statements.
48+
// struct sizes are not deterministic under randomized layouts
49+
const _: (usize, usize) = ($size, ::std::mem::size_of::<$ty>());
50+
};
51+
}

compiler/rustc_middle/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ tracing = "0.1"
4040

4141
[features]
4242
# tidy-alphabetical-start
43+
rustc_randomized_layouts = []
4344
rustc_use_parallel_compiler = ["dep:rustc-rayon-core"]
4445
# tidy-alphabetical-end

compiler/rustc_middle/src/mir/syntax.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,9 @@ pub enum Rvalue<'tcx> {
13071307
/// If the type of the place is an array, this is the array length. For slices (`[T]`, not
13081308
/// `&[T]`) this accesses the place's metadata to determine the length. This rvalue is
13091309
/// ill-formed for places of other types.
1310+
///
1311+
/// This cannot be a `UnOp(PtrMetadata, _)` because that expects a value, and we only
1312+
/// have a place, and `UnOp(PtrMetadata, RawPtr(place))` is not a thing.
13101313
Len(Place<'tcx>),
13111314

13121315
/// Performs essentially all of the casts that can be performed via `as`.

compiler/rustc_middle/src/query/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ macro_rules! define_callbacks {
337337
// Ensure that values grow no larger than 64 bytes by accident.
338338
// Increase this limit if necessary, but do try to keep the size low if possible
339339
#[cfg(target_pointer_width = "64")]
340+
#[cfg(not(feature = "rustc_randomized_layouts"))]
340341
const _: () = {
341342
if mem::size_of::<Value<'static>>() > 64 {
342343
panic!("{}", concat!(

compiler/rustc_middle/src/ty/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
3535
use rustc_errors::{Diag, ErrorGuaranteed, StashKey};
3636
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
3737
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
38+
use rustc_hir::LangItem;
3839
use rustc_index::IndexVec;
3940
use rustc_macros::{
4041
extension, Decodable, Encodable, HashStable, TyDecodable, TyEncodable, TypeFoldable,
@@ -1570,8 +1571,15 @@ impl<'tcx> TyCtxt<'tcx> {
15701571
flags.insert(ReprFlags::RANDOMIZE_LAYOUT);
15711572
}
15721573

1574+
// box is special, on the one hand the compiler assumes an ordered layout, with the pointer
1575+
// always at offset zero. On the other hand we want scalar abi optimizations.
1576+
let is_box = self.is_lang_item(did.to_def_id(), LangItem::OwnedBox);
1577+
15731578
// This is here instead of layout because the choice must make it into metadata.
1574-
if !self.consider_optimizing(|| format!("Reorder fields of {:?}", self.def_path_str(did))) {
1579+
if is_box
1580+
|| !self
1581+
.consider_optimizing(|| format!("Reorder fields of {:?}", self.def_path_str(did)))
1582+
{
15751583
flags.insert(ReprFlags::IS_LINEAR);
15761584
}
15771585

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,8 @@ supported_targets! {
16951695
("armv7r-none-eabihf", armv7r_none_eabihf),
16961696
("armv8r-none-eabihf", armv8r_none_eabihf),
16971697

1698+
("armv7-rtems-eabihf", armv7_rtems_eabihf),
1699+
16981700
("x86_64-pc-solaris", x86_64_pc_solaris),
16991701
("sparcv9-sun-solaris", sparcv9_sun_solaris),
17001702

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub(crate) fn target() -> Target {
4+
Target {
5+
llvm_target: "armv7-unknown-none-eabihf".into(),
6+
metadata: crate::spec::TargetMetadata {
7+
description: Some("Armv7 RTEMS (Requires RTEMS toolchain and kernel".into()),
8+
tier: Some(3),
9+
host_tools: Some(false),
10+
std: Some(true),
11+
},
12+
pointer_width: 32,
13+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
14+
arch: "arm".into(),
15+
16+
options: TargetOptions {
17+
os: "rtems".into(),
18+
families: cvs!["unix"],
19+
abi: "eabihf".into(),
20+
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
21+
linker: None,
22+
relocation_model: RelocModel::Static,
23+
panic_strategy: PanicStrategy::Abort,
24+
features: "+thumb2,+neon,+vfp3".into(),
25+
max_atomic_width: Some(64),
26+
emit_debug_gdb_scripts: false,
27+
// GCC defaults to 8 for arm-none here.
28+
c_enum_min_bits: Some(8),
29+
eh_frame_header: false,
30+
no_default_libraries: false,
31+
env: "newlib".into(),
32+
..Default::default()
33+
},
34+
}
35+
}

compiler/rustc_type_ir/src/elaborate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn supertrait_def_ids<I: Interner>(
237237
cx: I,
238238
trait_def_id: I::DefId,
239239
) -> impl Iterator<Item = I::DefId> {
240-
let mut set: HashSet<I::DefId> = HashSet::default();
240+
let mut set = HashSet::default();
241241
let mut stack = vec![trait_def_id];
242242

243243
set.insert(trait_def_id);

config.example.toml

+3
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@
519519
# are disabled statically" because `max_level_info` is enabled, set this value to `true`.
520520
#debug-logging = rust.debug-assertions (boolean)
521521

522+
# Whether or not to build rustc, tools and the libraries with randomized type layout
523+
#randomize-layout = false
524+
522525
# Whether or not overflow checks are enabled for the compiler and standard
523526
# library.
524527
#

0 commit comments

Comments
 (0)