Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 81401ca

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 292256e + cb06d12 commit 81401ca

File tree

80 files changed

+767
-530
lines changed

Some content is hidden

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

80 files changed

+767
-530
lines changed

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
-compiler_builtins = { version = "=0.1.147", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.147", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -460,64 +460,6 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
460460
});
461461
}
462462

463-
sym::simd_fpow => {
464-
intrinsic_args!(fx, args => (a, b); intrinsic);
465-
466-
if !a.layout().ty.is_simd() {
467-
report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty);
468-
return;
469-
}
470-
471-
simd_pair_for_each_lane(fx, a, b, ret, &|fx, lane_ty, _ret_lane_ty, a_lane, b_lane| {
472-
match lane_ty.kind() {
473-
ty::Float(FloatTy::F32) => fx.lib_call(
474-
"powf",
475-
vec![AbiParam::new(types::F32), AbiParam::new(types::F32)],
476-
vec![AbiParam::new(types::F32)],
477-
&[a_lane, b_lane],
478-
)[0],
479-
ty::Float(FloatTy::F64) => fx.lib_call(
480-
"pow",
481-
vec![AbiParam::new(types::F64), AbiParam::new(types::F64)],
482-
vec![AbiParam::new(types::F64)],
483-
&[a_lane, b_lane],
484-
)[0],
485-
_ => unreachable!("{:?}", lane_ty),
486-
}
487-
});
488-
}
489-
490-
sym::simd_fpowi => {
491-
intrinsic_args!(fx, args => (a, exp); intrinsic);
492-
let exp = exp.load_scalar(fx);
493-
494-
if !a.layout().ty.is_simd() {
495-
report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty);
496-
return;
497-
}
498-
499-
simd_for_each_lane(
500-
fx,
501-
a,
502-
ret,
503-
&|fx, lane_ty, _ret_lane_ty, lane| match lane_ty.kind() {
504-
ty::Float(FloatTy::F32) => fx.lib_call(
505-
"__powisf2", // compiler-builtins
506-
vec![AbiParam::new(types::F32), AbiParam::new(types::I32)],
507-
vec![AbiParam::new(types::F32)],
508-
&[lane, exp],
509-
)[0],
510-
ty::Float(FloatTy::F64) => fx.lib_call(
511-
"__powidf2", // compiler-builtins
512-
vec![AbiParam::new(types::F64), AbiParam::new(types::I32)],
513-
vec![AbiParam::new(types::F64)],
514-
&[lane, exp],
515-
)[0],
516-
_ => unreachable!("{:?}", lane_ty),
517-
},
518-
);
519-
}
520-
521463
sym::simd_fsin
522464
| sym::simd_fcos
523465
| sym::simd_fexp

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
772772
sym::simd_floor => "floor",
773773
sym::simd_fma => "fma",
774774
sym::simd_relaxed_fma => "fma", // FIXME: this should relax to non-fused multiply-add when necessary
775-
sym::simd_fpowi => "__builtin_powi",
776-
sym::simd_fpow => "pow",
777775
sym::simd_fsin => "sin",
778776
sym::simd_fsqrt => "sqrt",
779777
sym::simd_round => "round",
@@ -788,24 +786,16 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
788786
let mut vector_elements = vec![];
789787
for i in 0..in_len {
790788
let index = bx.context.new_rvalue_from_long(bx.ulong_type, i as i64);
791-
// we have to treat fpowi specially, since fpowi's second argument is always an i32
792789
let mut arguments = vec![];
793-
if name == sym::simd_fpowi {
794-
arguments = vec![
795-
bx.extract_element(args[0].immediate(), index).to_rvalue(),
796-
args[1].immediate(),
797-
];
798-
} else {
799-
for arg in args {
800-
let mut element = bx.extract_element(arg.immediate(), index).to_rvalue();
801-
// FIXME: it would probably be better to not have casts here and use the proper
802-
// instructions.
803-
if let Some(typ) = cast_type {
804-
element = bx.context.new_cast(None, element, typ);
805-
}
806-
arguments.push(element);
790+
for arg in args {
791+
let mut element = bx.extract_element(arg.immediate(), index).to_rvalue();
792+
// FIXME: it would probably be better to not have casts here and use the proper
793+
// instructions.
794+
if let Some(typ) = cast_type {
795+
element = bx.context.new_cast(None, element, typ);
807796
}
808-
};
797+
arguments.push(element);
798+
}
809799
let mut result = bx.context.new_call(None, function, &arguments);
810800
if cast_type.is_some() {
811801
result = bx.context.new_cast(None, result, elem_ty);
@@ -829,8 +819,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
829819
| sym::simd_floor
830820
| sym::simd_fma
831821
| sym::simd_relaxed_fma
832-
| sym::simd_fpow
833-
| sym::simd_fpowi
834822
| sym::simd_fsin
835823
| sym::simd_fsqrt
836824
| sym::simd_round

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,8 +1581,6 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15811581
sym::simd_floor => ("floor", bx.type_func(&[vec_ty], vec_ty)),
15821582
sym::simd_fma => ("fma", bx.type_func(&[vec_ty, vec_ty, vec_ty], vec_ty)),
15831583
sym::simd_relaxed_fma => ("fmuladd", bx.type_func(&[vec_ty, vec_ty, vec_ty], vec_ty)),
1584-
sym::simd_fpowi => ("powi", bx.type_func(&[vec_ty, bx.type_i32()], vec_ty)),
1585-
sym::simd_fpow => ("pow", bx.type_func(&[vec_ty, vec_ty], vec_ty)),
15861584
sym::simd_fsin => ("sin", bx.type_func(&[vec_ty], vec_ty)),
15871585
sym::simd_fsqrt => ("sqrt", bx.type_func(&[vec_ty], vec_ty)),
15881586
sym::simd_round => ("round", bx.type_func(&[vec_ty], vec_ty)),
@@ -1615,8 +1613,6 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
16151613
| sym::simd_flog
16161614
| sym::simd_floor
16171615
| sym::simd_fma
1618-
| sym::simd_fpow
1619-
| sym::simd_fpowi
16201616
| sym::simd_fsin
16211617
| sym::simd_fsqrt
16221618
| sym::simd_relaxed_fma

compiler/rustc_codegen_ssa/src/back/apple.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env;
22
use std::fmt::{Display, from_fn};
33
use std::num::ParseIntError;
44

5+
use rustc_middle::middle::exported_symbols::SymbolExportKind;
56
use rustc_session::Session;
67
use rustc_target::spec::Target;
78

@@ -26,6 +27,89 @@ pub(super) fn macho_platform(target: &Target) -> u32 {
2627
}
2728
}
2829

30+
/// Add relocation and section data needed for a symbol to be considered
31+
/// undefined by ld64.
32+
///
33+
/// The relocation must be valid, and hence must point to a valid piece of
34+
/// machine code, and hence this is unfortunately very architecture-specific.
35+
///
36+
///
37+
/// # New architectures
38+
///
39+
/// The values here are basically the same as emitted by the following program:
40+
///
41+
/// ```c
42+
/// // clang -c foo.c -target $CLANG_TARGET
43+
/// void foo(void);
44+
///
45+
/// extern int bar;
46+
///
47+
/// void* foobar[2] = {
48+
/// (void*)foo,
49+
/// (void*)&bar,
50+
/// // ...
51+
/// };
52+
/// ```
53+
///
54+
/// Can be inspected with:
55+
/// ```console
56+
/// objdump --macho --reloc foo.o
57+
/// objdump --macho --full-contents foo.o
58+
/// ```
59+
pub(super) fn add_data_and_relocation(
60+
file: &mut object::write::Object<'_>,
61+
section: object::write::SectionId,
62+
symbol: object::write::SymbolId,
63+
target: &Target,
64+
kind: SymbolExportKind,
65+
) -> object::write::Result<()> {
66+
let authenticated_pointer =
67+
kind == SymbolExportKind::Text && target.llvm_target.starts_with("arm64e");
68+
69+
let data: &[u8] = match target.pointer_width {
70+
_ if authenticated_pointer => &[0, 0, 0, 0, 0, 0, 0, 0x80],
71+
32 => &[0; 4],
72+
64 => &[0; 8],
73+
pointer_width => unimplemented!("unsupported Apple pointer width {pointer_width:?}"),
74+
};
75+
76+
if target.arch == "x86_64" {
77+
// Force alignment for the entire section to be 16 on x86_64.
78+
file.section_mut(section).append_data(&[], 16);
79+
} else {
80+
// Elsewhere, the section alignment is the same as the pointer width.
81+
file.section_mut(section).append_data(&[], target.pointer_width as u64);
82+
}
83+
84+
let offset = file.section_mut(section).append_data(data, data.len() as u64);
85+
86+
let flags = if authenticated_pointer {
87+
object::write::RelocationFlags::MachO {
88+
r_type: object::macho::ARM64_RELOC_AUTHENTICATED_POINTER,
89+
r_pcrel: false,
90+
r_length: 3,
91+
}
92+
} else if target.arch == "arm" {
93+
// FIXME(madsmtm): Remove once `object` supports 32-bit ARM relocations:
94+
// https://github.com/gimli-rs/object/pull/757
95+
object::write::RelocationFlags::MachO {
96+
r_type: object::macho::ARM_RELOC_VANILLA,
97+
r_pcrel: false,
98+
r_length: 2,
99+
}
100+
} else {
101+
object::write::RelocationFlags::Generic {
102+
kind: object::RelocationKind::Absolute,
103+
encoding: object::RelocationEncoding::Generic,
104+
size: target.pointer_width as u8,
105+
}
106+
};
107+
108+
file.add_relocation(section, object::write::Relocation { offset, addend: 0, symbol, flags })?;
109+
110+
Ok(())
111+
}
112+
29113
/// Deployment target or SDK version.
30114
///
31115
/// The size of the numbers in here are limited by Mach-O's `LC_BUILD_VERSION`.

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,8 @@ fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor
20582058
/// linker, and since they never participate in the linking, using `KEEP` in the linker scripts
20592059
/// can't keep them either. This causes #47384.
20602060
///
2061-
/// To keep them around, we could use `--whole-archive` and equivalents to force rlib to
2062-
/// participate in linking like object files, but this proves to be expensive (#93791). Therefore
2061+
/// To keep them around, we could use `--whole-archive`, `-force_load` and equivalents to force rlib
2062+
/// to participate in linking like object files, but this proves to be expensive (#93791). Therefore
20632063
/// we instead just introduce an undefined reference to them. This could be done by `-u` command
20642064
/// line option to the linker or `EXTERN(...)` in linker scripts, however they does not only
20652065
/// introduce an undefined reference, but also make them the GC roots, preventing `--gc-sections`
@@ -2101,8 +2101,20 @@ fn add_linked_symbol_object(
21012101
file.set_mangling(object::write::Mangling::None);
21022102
}
21032103

2104+
// ld64 requires a relocation to load undefined symbols, see below.
2105+
// Not strictly needed if linking with lld, but might as well do it there too.
2106+
let ld64_section_helper = if file.format() == object::BinaryFormat::MachO {
2107+
Some(file.add_section(
2108+
file.segment_name(object::write::StandardSegment::Data).to_vec(),
2109+
"__data".into(),
2110+
object::SectionKind::Data,
2111+
))
2112+
} else {
2113+
None
2114+
};
2115+
21042116
for (sym, kind) in symbols.iter() {
2105-
file.add_symbol(object::write::Symbol {
2117+
let symbol = file.add_symbol(object::write::Symbol {
21062118
name: sym.clone().into(),
21072119
value: 0,
21082120
size: 0,
@@ -2116,6 +2128,47 @@ fn add_linked_symbol_object(
21162128
section: object::write::SymbolSection::Undefined,
21172129
flags: object::SymbolFlags::None,
21182130
});
2131+
2132+
// The linker shipped with Apple's Xcode, ld64, works a bit differently from other linkers.
2133+
//
2134+
// Code-wise, the relevant parts of ld64 are roughly:
2135+
// 1. Find the `ArchiveLoadMode` based on commandline options, default to `parseObjects`.
2136+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/Options.cpp#L924-L932
2137+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/Options.h#L55
2138+
//
2139+
// 2. Read the archive table of contents (__.SYMDEF file).
2140+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/archive_file.cpp#L294-L325
2141+
//
2142+
// 3. Begin linking by loading "atoms" from input files.
2143+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/doc/design/linker.html
2144+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/InputFiles.cpp#L1349
2145+
//
2146+
// a. Directly specified object files (`.o`) are parsed immediately.
2147+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/macho_relocatable_file.cpp#L4611-L4627
2148+
//
2149+
// - Undefined symbols are not atoms (`n_value > 0` denotes a common symbol).
2150+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/macho_relocatable_file.cpp#L2455-L2468
2151+
// https://maskray.me/blog/2022-02-06-all-about-common-symbols
2152+
//
2153+
// - Relocations/fixups are atoms.
2154+
// https://github.com/apple-oss-distributions/ld64/blob/ce6341ae966b3451aa54eeb049f2be865afbd578/src/ld/parsers/macho_relocatable_file.cpp#L2088-L2114
2155+
//
2156+
// b. Archives are not parsed yet.
2157+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/archive_file.cpp#L467-L577
2158+
//
2159+
// 4. When a symbol is needed by an atom, parse the object file that contains the symbol.
2160+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/InputFiles.cpp#L1417-L1491
2161+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/archive_file.cpp#L579-L597
2162+
//
2163+
// All of the steps above are fairly similar to other linkers, except that **it completely
2164+
// ignores undefined symbols**.
2165+
//
2166+
// So to make this trick work on ld64, we need to do something else to load the relevant
2167+
// object files. We do this by inserting a relocation (fixup) for each symbol.
2168+
if let Some(section) = ld64_section_helper {
2169+
apple::add_data_and_relocation(&mut file, section, symbol, &sess.target, *kind)
2170+
.expect("failed adding relocation");
2171+
}
21192172
}
21202173

21212174
let path = tmpdir.join("symbols.o");

compiler/rustc_errors/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(box_into_inner)]
1616
#![feature(box_patterns)]
1717
#![feature(error_reporter)]
18-
#![feature(extract_if)]
1918
#![feature(if_let_guard)]
2019
#![feature(let_chains)]
2120
#![feature(negative_impls)]

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10111011
),
10121012
rustc_attr!(
10131013
rustc_force_inline, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, EncodeCrossCrate::Yes,
1014-
"#![rustc_force_inline] forces a free function to be inlined"
1014+
"#[rustc_force_inline] forces a free function to be inlined"
10151015
),
10161016

10171017
// ==========================================================================

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ hir_analysis_unused_generic_parameter_adt_no_phantom_data_help =
605605
hir_analysis_unused_generic_parameter_ty_alias_help =
606606
consider removing `{$param_name}` or referring to it in the body of the type alias
607607
608+
hir_analysis_useless_impl_item = this item cannot be used as its where bounds are not satisfied for the `Self` type
609+
608610
hir_analysis_value_of_associated_struct_already_specified =
609611
the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified
610612
.label = re-bound here

0 commit comments

Comments
 (0)