Skip to content

Commit fffec7b

Browse files
committed
Auto merge of #152454 - matthiaskrgr:rollup-43Fv9gu, r=<try>
Rollup of 12 pull requests try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: test-various try-job: armhf-gnu try-job: aarch64-apple
2 parents d34f1f9 + 36787bf commit fffec7b

File tree

88 files changed

+2152
-847
lines changed

Some content is hidden

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

88 files changed

+2152
-847
lines changed

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ the Zulip stream is the best place to *ask* for help.
1010

1111
Documentation for contributing to the compiler or tooling is located in the [Guide to Rustc
1212
Development][rustc-dev-guide], commonly known as the [rustc-dev-guide]. Documentation for the
13-
standard library in the [Standard library developers Guide][std-dev-guide], commonly known as the [std-dev-guide].
13+
standard library is in the [Standard library developers Guide][std-dev-guide], commonly known as the [std-dev-guide].
1414

1515
## Making changes to subtrees and submodules
1616

‎Cargo.lock‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,6 +4492,7 @@ name = "rustc_query_impl"
44924492
version = "0.0.0"
44934493
dependencies = [
44944494
"measureme",
4495+
"rustc_abi",
44954496
"rustc_data_structures",
44964497
"rustc_errors",
44974498
"rustc_hashes",
@@ -4501,7 +4502,9 @@ dependencies = [
45014502
"rustc_middle",
45024503
"rustc_query_system",
45034504
"rustc_serialize",
4505+
"rustc_session",
45044506
"rustc_span",
4507+
"rustc_thread_pool",
45054508
"tracing",
45064509
]
45074510

‎INSTALL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ itself back on after some time).
233233

234234
### MSVC
235235

236-
MSVC builds of Rust additionally requires an installation of:
236+
MSVC builds of Rust additionally require an installation of:
237237

238238
- Visual Studio 2022 (or later) build tools so `rustc` can use its linker. Older
239239
Visual Studio versions such as 2019 *may* work but aren't actively tested.

‎RELEASES.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ Compatibility Notes
15461546
- [Check well-formedness of the source type's signature in fn pointer casts.](https://github.com/rust-lang/rust/pull/129021) This partly closes a soundness hole that comes when casting a function item to function pointer
15471547
- [Use equality instead of subtyping when resolving type dependent paths.](https://github.com/rust-lang/rust/pull/129073)
15481548
- Linking on macOS now correctly includes Rust's default deployment target. Due to a linker bug, you might have to pass `MACOSX_DEPLOYMENT_TARGET` or fix your `#[link]` attributes to point to the correct frameworks. See <https://github.com/rust-lang/rust/pull/129369>.
1549-
- [Rust will now correctly raise an error for `repr(Rust)` written on non-`struct`/`enum`/`union` items, since it previous did not have any effect.](https://github.com/rust-lang/rust/pull/129422)
1549+
- [Rust will now correctly raise an error for `repr(Rust)` written on non-`struct`/`enum`/`union` items, since it previously did not have any effect.](https://github.com/rust-lang/rust/pull/129422)
15501550
- The future incompatibility lint `deprecated_cfg_attr_crate_type_name` [has been made into a hard error](https://github.com/rust-lang/rust/pull/129670). It was used to deny usage of `#![crate_type]` and `#![crate_name]` attributes in `#![cfg_attr]`, which required a hack in the compiler to be able to change the used crate type and crate name after cfg expansion.
15511551
Users can use `--crate-type` instead of `#![cfg_attr(..., crate_type = "...")]` and `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]` when running `rustc`/`cargo rustc` on the command line.
15521552
Use of those two attributes outside of `#![cfg_attr]` continue to be fully supported.
@@ -1722,7 +1722,7 @@ Cargo
17221722
Compatibility Notes
17231723
-------------------
17241724
- We now [disallow setting some built-in cfgs via the command-line](https://github.com/rust-lang/rust/pull/126158) with the newly added [`explicit_builtin_cfgs_in_flags`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#explicit-builtin-cfgs-in-flags) lint in order to prevent incoherent state, eg. `windows` cfg active but target is Linux based. The appropriate [`rustc` flag](https://doc.rust-lang.org/rustc/command-line-arguments.html) should be used instead.
1725-
- The standard library has a new implementation of `binary_search` which is significantly improves performance ([#128254](https://github.com/rust-lang/rust/pull/128254)). However when a sorted slice has multiple values which compare equal, the new implementation may select a different value among the equal ones than the old implementation.
1725+
- The standard library has a new implementation of `binary_search` which significantly improves performance ([#128254](https://github.com/rust-lang/rust/pull/128254)). However when a sorted slice has multiple values which compare equal, the new implementation may select a different value among the equal ones than the old implementation.
17261726
- [illumos/Solaris now sets `MSG_NOSIGNAL` when writing to sockets](https://github.com/rust-lang/rust/pull/128259). This avoids killing the process with SIGPIPE when writing to a closed socket, which matches the existing behavior on other UNIX targets.
17271727
- [Removes a problematic hack that always passed the --whole-archive linker flag for tests, which may cause linker errors for code accidentally relying on it.](https://github.com/rust-lang/rust/pull/128400)
17281728
- The WebAssembly target features `multivalue` and `reference-types` are now
@@ -1872,7 +1872,7 @@ These changes do not affect any public interfaces of Rust, but they represent
18721872
significant improvements to the performance or internals of rustc and related
18731873
tools.
18741874

1875-
- [Add a Rust-for Linux `auto` CI job to check kernel builds.](https://github.com/rust-lang/rust/pull/125209/)
1875+
- [Add a Rust-for-Linux `auto` CI job to check kernel builds.](https://github.com/rust-lang/rust/pull/125209/)
18761876

18771877
Version 1.80.1 (2024-08-08)
18781878
===========================
@@ -4510,7 +4510,7 @@ Compatibility Notes
45104510
saturating to `0` instead][89926]. In the real world the panic happened mostly
45114511
on platforms with buggy monotonic clock implementations rather than catching
45124512
programming errors like reversing the start and end times. Such programming
4513-
errors will now results in `0` rather than a panic.
4513+
errors will now result in `0` rather than a panic.
45144514
- In a future release we're planning to increase the baseline requirements for
45154515
the Linux kernel to version 3.2, and for glibc to version 2.17. We'd love
45164516
your feedback in [PR #95026][95026].

‎compiler/rustc_attr_parsing/src/attributes/stability.rs‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,20 @@ impl<S: Stage> AttributeParser<S> for ConstStabilityParser {
244244
this.promotable = true;
245245
}),
246246
];
247-
const ALLOWED_TARGETS: AllowedTargets = ALLOWED_TARGETS;
247+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
248+
Allow(Target::Fn),
249+
Allow(Target::Method(MethodKind::Inherent)),
250+
Allow(Target::Method(MethodKind::TraitImpl)),
251+
Allow(Target::Method(MethodKind::Trait { body: true })),
252+
Allow(Target::Impl { of_trait: false }),
253+
Allow(Target::Impl { of_trait: true }),
254+
Allow(Target::Use), // FIXME I don't think this does anything?
255+
Allow(Target::Const),
256+
Allow(Target::AssocConst),
257+
Allow(Target::Trait),
258+
Allow(Target::Static),
259+
Allow(Target::Crate),
260+
]);
248261

249262
fn finalize(mut self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
250263
if self.promotable {

‎compiler/rustc_codegen_llvm/src/llvm/mod.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ pub(crate) fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) {
284284
}
285285
}
286286

287+
pub(crate) fn count_params(llfn: &Value) -> c_uint {
288+
LLVMCountParams(llfn)
289+
}
290+
287291
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
288292
pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
289293
unsafe {

‎compiler/rustc_codegen_llvm/src/mono_item.rs‎

Lines changed: 108 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::ffi::CString;
23

34
use rustc_abi::AddressSpace;
@@ -6,13 +7,17 @@ use rustc_hir::attrs::Linkage;
67
use rustc_hir::def::DefKind;
78
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
89
use rustc_middle::bug;
10+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
911
use rustc_middle::mir::mono::Visibility;
1012
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf};
11-
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
13+
use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
1214
use rustc_session::config::CrateType;
15+
use rustc_target::callconv::FnAbi;
1316
use rustc_target::spec::{Arch, RelocModel};
1417
use tracing::debug;
1518

19+
use crate::abi::FnAbiLlvmExt;
20+
use crate::builder::Builder;
1621
use crate::context::CodegenCx;
1722
use crate::errors::SymbolAlreadyDefined;
1823
use crate::type_of::LayoutLlvmExt;
@@ -45,7 +50,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
4550
self.assume_dso_local(g, false);
4651

4752
let attrs = self.tcx.codegen_instance_attrs(instance.def);
48-
self.add_aliases(g, &attrs.foreign_item_symbol_aliases);
53+
self.add_static_aliases(g, &attrs.foreign_item_symbol_aliases);
4954

5055
self.instances.borrow_mut().insert(instance, g);
5156
}
@@ -59,11 +64,29 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
5964
) {
6065
assert!(!instance.args.has_infer());
6166

62-
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
67+
let attrs = self.tcx.codegen_instance_attrs(instance.def);
68+
69+
let lldecl =
70+
self.predefine_without_aliases(instance, &attrs, linkage, visibility, symbol_name);
71+
self.add_function_aliases(instance, lldecl, &attrs, &attrs.foreign_item_symbol_aliases);
72+
73+
self.instances.borrow_mut().insert(instance, lldecl);
74+
}
75+
}
76+
77+
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
78+
fn predefine_without_aliases(
79+
&self,
80+
instance: Instance<'tcx>,
81+
attrs: &Cow<'_, CodegenFnAttrs>,
82+
linkage: Linkage,
83+
visibility: Visibility,
84+
symbol_name: &str,
85+
) -> &'ll llvm::Value {
86+
let fn_abi: &FnAbi<'tcx, Ty<'tcx>> = self.fn_abi_of_instance(instance, ty::List::empty());
6387
let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance));
6488
llvm::set_linkage(lldecl, base::linkage_to_llvm(linkage));
65-
let attrs = self.tcx.codegen_instance_attrs(instance.def);
66-
base::set_link_section(lldecl, &attrs);
89+
base::set_link_section(lldecl, attrs);
6790
if (linkage == Linkage::LinkOnceODR || linkage == Linkage::WeakODR)
6891
&& self.tcx.sess.target.supports_comdat()
6992
{
@@ -84,20 +107,45 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
84107

85108
self.assume_dso_local(lldecl, false);
86109

87-
self.add_aliases(lldecl, &attrs.foreign_item_symbol_aliases);
88-
89-
self.instances.borrow_mut().insert(instance, lldecl);
110+
lldecl
90111
}
91-
}
92112

93-
impl CodegenCx<'_, '_> {
94-
fn add_aliases(&self, aliasee: &llvm::Value, aliases: &[(DefId, Linkage, Visibility)]) {
113+
/// LLVM has the concept of an `alias`.
114+
/// We need this for the "externally implementable items" feature,
115+
/// though it's generally useful.
116+
///
117+
/// On macos, though this might be a more general problem, function symbols
118+
/// have a fixed target architecture. This is necessary, since macos binaries
119+
/// may contain code for both ARM and x86 macs.
120+
///
121+
/// LLVM *can* add attributes for target architecture to function symbols,
122+
/// cannot do so for statics, but importantly, also cannot for aliases
123+
/// *even* when aliases may refer to a function symbol.
124+
///
125+
/// This is not a problem: instead of using LLVM aliases, we can just generate
126+
/// a new function symbol (with target architecture!) which effectively comes down to:
127+
///
128+
/// ```ignore (illustrative example)
129+
/// fn alias_name(...args) {
130+
/// original_name(...args)
131+
/// }
132+
/// ```
133+
///
134+
/// That's also an alias.
135+
///
136+
/// This does mean that the alias symbol has a different address than the original symbol
137+
/// (assuming no optimizations by LLVM occur). This is unacceptable for statics.
138+
/// So for statics we do want to use LLVM aliases, which is fine,
139+
/// since for those we don't care about target architecture anyway.
140+
///
141+
/// So, this function is for static aliases. See [`add_function_aliases`](Self::add_function_aliases) for the alternative.
142+
fn add_static_aliases(&self, aliasee: &llvm::Value, aliases: &[(DefId, Linkage, Visibility)]) {
95143
let ty = self.get_type_of_global(aliasee);
96144

97145
for (alias, linkage, visibility) in aliases {
98146
let symbol_name = self.tcx.symbol_name(Instance::mono(self.tcx, *alias));
147+
tracing::debug!("STATIC ALIAS: {alias:?} {linkage:?} {visibility:?}");
99148

100-
tracing::debug!("ALIAS: {alias:?} {linkage:?} {visibility:?}");
101149
let lldecl = llvm::add_alias(
102150
self.llmod,
103151
ty,
@@ -111,6 +159,54 @@ impl CodegenCx<'_, '_> {
111159
}
112160
}
113161

162+
/// See [`add_static_aliases`](Self::add_static_aliases) for docs.
163+
fn add_function_aliases(
164+
&self,
165+
aliasee_instance: Instance<'tcx>,
166+
aliasee: &'ll llvm::Value,
167+
attrs: &Cow<'_, CodegenFnAttrs>,
168+
aliases: &[(DefId, Linkage, Visibility)],
169+
) {
170+
for (alias, linkage, visibility) in aliases {
171+
let symbol_name = self.tcx.symbol_name(Instance::mono(self.tcx, *alias));
172+
tracing::debug!("FUNCTION ALIAS: {alias:?} {linkage:?} {visibility:?}");
173+
174+
// predefine another copy of the original instance
175+
// with a new symbol name
176+
let alias_lldecl = self.predefine_without_aliases(
177+
aliasee_instance,
178+
attrs,
179+
*linkage,
180+
*visibility,
181+
symbol_name.name,
182+
);
183+
184+
let fn_abi: &FnAbi<'tcx, Ty<'tcx>> =
185+
self.fn_abi_of_instance(aliasee_instance, ty::List::empty());
186+
187+
// both the alias and the aliasee have the same ty
188+
let fn_ty = fn_abi.llvm_type(self);
189+
let start_llbb = Builder::append_block(self, alias_lldecl, "start");
190+
let mut start_bx = Builder::build(self, start_llbb);
191+
192+
let num_params = llvm::count_params(alias_lldecl);
193+
let mut args = Vec::with_capacity(num_params as usize);
194+
for index in 0..num_params {
195+
args.push(llvm::get_param(alias_lldecl, index));
196+
}
197+
198+
start_bx.tail_call(
199+
fn_ty,
200+
Some(attrs),
201+
fn_abi,
202+
aliasee,
203+
&args,
204+
None,
205+
Some(aliasee_instance),
206+
);
207+
}
208+
}
209+
114210
/// A definition or declaration can be assumed to be local to a group of
115211
/// libraries that form a single DSO or executable.
116212
/// Marks the local as DSO if so.

0 commit comments

Comments
 (0)