Skip to content

Commit 48ef38d

Browse files
committed
Auto merge of #135959 - matthiaskrgr:rollup-0jenyfw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #135366 (Enable `unreachable_pub` lint in `test` and `proc_macro` crates) - #135638 (Make it possible to build GCC on CI) - #135648 (support wasm inline assembly in `naked_asm!`) - #135827 (CI: free disk with in-tree script instead of GitHub Action) - #135855 (Only assert the `Parser` size on specific arches) - #135878 (ci: use 8 core arm runner for dist-aarch64-linux) - #135905 (Enable kernel sanitizers for aarch64-unknown-none-softfloat) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1c9837d + b3fcd56 commit 48ef38d

File tree

31 files changed

+664
-100
lines changed

31 files changed

+664
-100
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
# intensive jobs to run on free runners, which however also have
110110
# less disk space.
111111
- name: free up disk space
112-
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be
112+
run: src/ci/scripts/free-disk-space.sh
113113
if: matrix.free_disk
114114

115115
# Rust Log Analyzer can't currently detect the PR number of a GitHub

Diff for: compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+168-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind};
12
use rustc_attr_parsing::InstructionSetAttr;
3+
use rustc_hir::def_id::DefId;
24
use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
35
use rustc_middle::mir::{Body, InlineAsmOperand};
4-
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf};
5-
use rustc_middle::ty::{Instance, TyCtxt};
6-
use rustc_middle::{bug, ty};
6+
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
7+
use rustc_middle::ty::{Instance, Ty, TyCtxt};
8+
use rustc_middle::{bug, span_bug, ty};
79
use rustc_span::sym;
10+
use rustc_target::callconv::{ArgAbi, FnAbi, PassMode};
11+
use rustc_target::spec::WasmCAbi;
812

913
use crate::common;
1014
use crate::traits::{AsmCodegenMethods, BuilderMethods, GlobalAsmOperandRef, MiscCodegenMethods};
@@ -32,7 +36,8 @@ pub(crate) fn codegen_naked_asm<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
3236

3337
let item_data = cx.codegen_unit().items().get(&MonoItem::Fn(instance)).unwrap();
3438
let name = cx.mangled_name(instance);
35-
let (begin, end) = prefix_and_suffix(cx.tcx(), instance, &name, item_data);
39+
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
40+
let (begin, end) = prefix_and_suffix(cx.tcx(), instance, &name, item_data, fn_abi);
3641

3742
let mut template_vec = Vec::new();
3843
template_vec.push(rustc_ast::ast::InlineAsmTemplatePiece::String(begin.into()));
@@ -103,6 +108,7 @@ enum AsmBinaryFormat {
103108
Elf,
104109
Macho,
105110
Coff,
111+
Wasm,
106112
}
107113

108114
impl AsmBinaryFormat {
@@ -111,6 +117,8 @@ impl AsmBinaryFormat {
111117
Self::Coff
112118
} else if target.is_like_osx {
113119
Self::Macho
120+
} else if target.is_like_wasm {
121+
Self::Wasm
114122
} else {
115123
Self::Elf
116124
}
@@ -122,6 +130,7 @@ fn prefix_and_suffix<'tcx>(
122130
instance: Instance<'tcx>,
123131
asm_name: &str,
124132
item_data: &MonoItemData,
133+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
125134
) -> (String, String) {
126135
use std::fmt::Write;
127136

@@ -169,7 +178,7 @@ fn prefix_and_suffix<'tcx>(
169178
}
170179
Linkage::LinkOnceAny | Linkage::LinkOnceODR | Linkage::WeakAny | Linkage::WeakODR => {
171180
match asm_binary_format {
172-
AsmBinaryFormat::Elf | AsmBinaryFormat::Coff => {
181+
AsmBinaryFormat::Elf | AsmBinaryFormat::Coff | AsmBinaryFormat::Wasm => {
173182
writeln!(w, ".weak {asm_name}")?;
174183
}
175184
AsmBinaryFormat::Macho => {
@@ -264,7 +273,161 @@ fn prefix_and_suffix<'tcx>(
264273
writeln!(end, "{}", arch_suffix).unwrap();
265274
}
266275
}
276+
AsmBinaryFormat::Wasm => {
277+
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
278+
279+
writeln!(begin, ".section {section},\"\",@").unwrap();
280+
// wasm functions cannot be aligned, so skip
281+
write_linkage(&mut begin).unwrap();
282+
if let Visibility::Hidden = item_data.visibility {
283+
writeln!(begin, ".hidden {asm_name}").unwrap();
284+
}
285+
writeln!(begin, ".type {asm_name}, @function").unwrap();
286+
if !arch_prefix.is_empty() {
287+
writeln!(begin, "{}", arch_prefix).unwrap();
288+
}
289+
writeln!(begin, "{asm_name}:").unwrap();
290+
writeln!(
291+
begin,
292+
".functype {asm_name} {}",
293+
wasm_functype(tcx, fn_abi, instance.def_id())
294+
)
295+
.unwrap();
296+
297+
writeln!(end).unwrap();
298+
// .size is ignored for function symbols, so we can skip it
299+
writeln!(end, "end_function").unwrap();
300+
}
267301
}
268302

269303
(begin, end)
270304
}
305+
306+
/// The webassembly type signature for the given function.
307+
///
308+
/// Used by the `.functype` directive on wasm targets.
309+
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id: DefId) -> String {
310+
let mut signature = String::with_capacity(64);
311+
312+
let ptr_type = match tcx.data_layout.pointer_size.bits() {
313+
32 => "i32",
314+
64 => "i64",
315+
other => bug!("wasm pointer size cannot be {other} bits"),
316+
};
317+
318+
// FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
319+
// please also add `wasm32-unknown-unknown` back in `tests/assembly/wasm32-naked-fn.rs`
320+
// basically the commit introducing this comment should be reverted
321+
if let PassMode::Pair { .. } = fn_abi.ret.mode {
322+
let _ = WasmCAbi::Legacy;
323+
span_bug!(
324+
tcx.def_span(def_id),
325+
"cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
326+
);
327+
}
328+
329+
let hidden_return = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
330+
331+
signature.push('(');
332+
333+
if hidden_return {
334+
signature.push_str(ptr_type);
335+
if !fn_abi.args.is_empty() {
336+
signature.push_str(", ");
337+
}
338+
}
339+
340+
let mut it = fn_abi.args.iter().peekable();
341+
while let Some(arg_abi) = it.next() {
342+
wasm_type(tcx, &mut signature, arg_abi, ptr_type, def_id);
343+
if it.peek().is_some() {
344+
signature.push_str(", ");
345+
}
346+
}
347+
348+
signature.push_str(") -> (");
349+
350+
if !hidden_return {
351+
wasm_type(tcx, &mut signature, &fn_abi.ret, ptr_type, def_id);
352+
}
353+
354+
signature.push(')');
355+
356+
signature
357+
}
358+
359+
fn wasm_type<'tcx>(
360+
tcx: TyCtxt<'tcx>,
361+
signature: &mut String,
362+
arg_abi: &ArgAbi<'_, Ty<'tcx>>,
363+
ptr_type: &'static str,
364+
def_id: DefId,
365+
) {
366+
match arg_abi.mode {
367+
PassMode::Ignore => { /* do nothing */ }
368+
PassMode::Direct(_) => {
369+
let direct_type = match arg_abi.layout.backend_repr {
370+
BackendRepr::Scalar(scalar) => wasm_primitive(scalar.primitive(), ptr_type),
371+
BackendRepr::Vector { .. } => "v128",
372+
BackendRepr::Memory { .. } => {
373+
// FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
374+
let _ = WasmCAbi::Legacy;
375+
span_bug!(
376+
tcx.def_span(def_id),
377+
"cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
378+
);
379+
}
380+
other => unreachable!("unexpected BackendRepr: {:?}", other),
381+
};
382+
383+
signature.push_str(direct_type);
384+
}
385+
PassMode::Pair(_, _) => match arg_abi.layout.backend_repr {
386+
BackendRepr::ScalarPair(a, b) => {
387+
signature.push_str(wasm_primitive(a.primitive(), ptr_type));
388+
signature.push_str(", ");
389+
signature.push_str(wasm_primitive(b.primitive(), ptr_type));
390+
}
391+
other => unreachable!("{other:?}"),
392+
},
393+
PassMode::Cast { pad_i32, ref cast } => {
394+
// For wasm, Cast is used for single-field primitive wrappers like `struct Wrapper(i64);`
395+
assert!(!pad_i32, "not currently used by wasm calling convention");
396+
assert!(cast.prefix[0].is_none(), "no prefix");
397+
assert_eq!(cast.rest.total, arg_abi.layout.size, "single item");
398+
399+
let wrapped_wasm_type = match cast.rest.unit.kind {
400+
RegKind::Integer => match cast.rest.unit.size.bytes() {
401+
..=4 => "i32",
402+
..=8 => "i64",
403+
_ => ptr_type,
404+
},
405+
RegKind::Float => match cast.rest.unit.size.bytes() {
406+
..=4 => "f32",
407+
..=8 => "f64",
408+
_ => ptr_type,
409+
},
410+
RegKind::Vector => "v128",
411+
};
412+
413+
signature.push_str(wrapped_wasm_type);
414+
}
415+
PassMode::Indirect { .. } => signature.push_str(ptr_type),
416+
}
417+
}
418+
419+
fn wasm_primitive(primitive: Primitive, ptr_type: &'static str) -> &'static str {
420+
match primitive {
421+
Primitive::Int(integer, _) => match integer {
422+
Integer::I8 | Integer::I16 | Integer::I32 => "i32",
423+
Integer::I64 => "i64",
424+
Integer::I128 => "i64, i64",
425+
},
426+
Primitive::Float(float) => match float {
427+
Float::F16 | Float::F32 => "f32",
428+
Float::F64 => "f64",
429+
Float::F128 => "i64, i64",
430+
},
431+
Primitive::Pointer(_) => ptr_type,
432+
}
433+
}

Diff for: compiler/rustc_parse/src/parser/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ pub struct Parser<'a> {
189189
}
190190

191191
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules with
192-
// nonterminals. Make sure it doesn't unintentionally get bigger.
193-
#[cfg(all(target_pointer_width = "64", not(target_arch = "s390x")))]
192+
// nonterminals. Make sure it doesn't unintentionally get bigger. We only check a few arches
193+
// though, because `TokenTypeSet(u128)` alignment varies on others, changing the total size.
194+
#[cfg(all(target_pointer_width = "64", any(target_arch = "aarch64", target_arch = "x86_64")))]
194195
rustc_data_structures::static_assert_size!(Parser<'_>, 288);
195196

196197
/// Stores span information about a closure.

Diff for: compiler/rustc_target/src/spec/targets/aarch64_unknown_none_softfloat.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
// For example, `-C target-cpu=cortex-a53`.
88

99
use crate::spec::{
10-
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, StackProbeType, Target, TargetOptions,
10+
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType, Target,
11+
TargetOptions,
1112
};
1213

1314
pub(crate) fn target() -> Target {
@@ -19,6 +20,7 @@ pub(crate) fn target() -> Target {
1920
relocation_model: RelocModel::Static,
2021
disable_redzone: true,
2122
max_atomic_width: Some(128),
23+
supported_sanitizers: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS,
2224
stack_probes: StackProbeType::Inline,
2325
panic_strategy: PanicStrategy::Abort,
2426
..Default::default()

Diff for: library/proc_macro/src/bridge/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::marker::PhantomData;
44

55
#[repr(C)]
6-
pub struct Closure<'a, A, R> {
6+
pub(super) struct Closure<'a, A, R> {
77
call: unsafe extern "C" fn(*mut Env, A) -> R,
88
env: *mut Env,
99
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
@@ -26,7 +26,7 @@ impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
2626
}
2727

2828
impl<'a, A, R> Closure<'a, A, R> {
29-
pub fn call(&mut self, arg: A) -> R {
29+
pub(super) fn call(&mut self, arg: A) -> R {
3030
unsafe { (self.call)(self.env, arg) }
3131
}
3232
}

Diff for: library/proc_macro/src/bridge/fxhash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::hash::{BuildHasherDefault, Hasher};
99
use std::ops::BitXor;
1010

1111
/// Type alias for a hashmap using the `fx` hash algorithm.
12-
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
12+
pub(super) type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
1313

1414
/// A speedy hash algorithm for use within rustc. The hashmap in alloc by
1515
/// default uses SipHash which isn't quite as speedy as we want. In the compiler
@@ -23,7 +23,7 @@ pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
2323
/// similar or slightly worse than FNV, but the speed of the hash function
2424
/// itself is much higher because it works on up to 8 bytes at a time.
2525
#[derive(Default)]
26-
pub struct FxHasher {
26+
pub(super) struct FxHasher {
2727
hash: usize,
2828
}
2929

Diff for: library/proc_macro/src/bridge/rpc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ macro_rules! rpc_encode_decode {
6767
mod tag {
6868
#[repr(u8)] enum Tag { $($variant),* }
6969

70-
$(pub const $variant: u8 = Tag::$variant as u8;)*
70+
$(pub(crate) const $variant: u8 = Tag::$variant as u8;)*
7171
}
7272

7373
match self {
@@ -89,7 +89,7 @@ macro_rules! rpc_encode_decode {
8989
mod tag {
9090
#[repr(u8)] enum Tag { $($variant),* }
9191

92-
$(pub const $variant: u8 = Tag::$variant as u8;)*
92+
$(pub(crate) const $variant: u8 = Tag::$variant as u8;)*
9393
}
9494

9595
match u8::decode(r, s) {

Diff for: library/proc_macro/src/bridge/selfless_reify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! define_reify_functions {
4444
fn $name:ident $(<$($param:ident),*>)?
4545
for $(extern $abi:tt)? fn($($arg:ident: $arg_ty:ty),*) -> $ret_ty:ty;
4646
)+) => {
47-
$(pub const fn $name<
47+
$(pub(super) const fn $name<
4848
$($($param,)*)?
4949
F: Fn($($arg_ty),*) -> $ret_ty + Copy
5050
>(f: F) -> $(extern $abi)? fn($($arg_ty),*) -> $ret_ty {

Diff for: library/proc_macro/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![allow(internal_features)]
3333
#![deny(ffi_unwind_calls)]
3434
#![warn(rustdoc::unescaped_backticks)]
35+
#![warn(unreachable_pub)]
3536

3637
#[unstable(feature = "proc_macro_internals", issue = "27812")]
3738
#[doc(hidden)]

Diff for: library/test/src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl TestOpts {
4444
}
4545

4646
/// Result of parsing the options.
47-
pub type OptRes = Result<TestOpts, String>;
47+
pub(crate) type OptRes = Result<TestOpts, String>;
4848
/// Result of parsing the option part.
4949
type OptPartRes<T> = Result<T, String>;
5050

0 commit comments

Comments
 (0)