Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9ceac26
codegen-llvm shim function for function aliases for macos
jdonszelmann Jan 14, 2026
14a98da
run tests on apple
jdonszelmann Jan 27, 2026
acd2e87
test backtraces
jdonszelmann Jan 27, 2026
ffa3878
Split `is_msvc_link_exe` into a function
jyn514 Dec 12, 2025
4a192c8
Split `report_linker_output` into its own function
jyn514 Dec 12, 2025
0bea000
Split out linker-info from linker-messages
jyn514 Dec 12, 2025
8ee8d40
Set linker-messages to warn-by-default
jyn514 Dec 13, 2025
1fa165d
style: remove unneeded trailing commas
nyurik Feb 9, 2026
8c0a493
BikeshedGuaranteedNoDrop trait: add comments indicating that it can b…
RalfJung Feb 9, 2026
e1ed3bf
Remove out-of-date comment.
nnethercote Feb 10, 2026
1c4661c
Derive `Clone` for `QueryLatch`.
nnethercote Feb 9, 2026
b6b6dc0
mGCA: add associated const type check in dyn arm
zedddie Feb 5, 2026
963f82d
mGCA: add associated const obligations in wfck
zedddie Feb 7, 2026
ec03e39
bless tests
zedddie Feb 9, 2026
066a935
Move parts of `rustc_query_system::query::job` to `rustc_middle::job`.
nnethercote Feb 9, 2026
923de04
Move `rustc_middle::query::values` to `rustc_query_impl`.
nnethercote Feb 10, 2026
a34317e
Move `report_cycle`.
nnethercote Feb 10, 2026
0ebd56e
Remove accidental const stability marker on a struct
oli-obk Dec 4, 2025
628c37a
Restrict the set of things that const stability can be applied
oli-obk Dec 4, 2025
475b9d9
Prevent const stability attrs from being applied to macros via the no…
oli-obk Feb 10, 2026
32e49a8
Reenable a GCI+mGCA+GCPT test case
fmease Feb 10, 2026
b23d308
Support structs in type info reflection
SpriteOvO Jan 14, 2026
870fd90
Add generics info for structs in type info
SpriteOvO Jan 19, 2026
e903788
Support enums in type info reflection
SpriteOvO Jan 20, 2026
98e0c34
Support unions in type info reflection
SpriteOvO Feb 5, 2026
b410cb0
Simplify the writing of tuple type info
SpriteOvO Feb 7, 2026
a575fe1
Erase type lifetime before writing type ID
SpriteOvO Feb 10, 2026
6ab6734
Move ADT related code to a sub module for type info
SpriteOvO Feb 10, 2026
58335d6
Don't ICE on layout error in vtable computation
meithecatte Feb 10, 2026
e84931a
Rollup merge of #149937 - jyn514:linker-info, r=mati865
JonathanBrouwer Feb 10, 2026
fa00db4
Rollup merge of #151733 - jdonszelmann:eii-on-apple, r=oli-obk
JonathanBrouwer Feb 10, 2026
4169874
Rollup merge of #152120 - meithecatte:push-ltvwvkqrytno, r=petrochenkov
JonathanBrouwer Feb 10, 2026
9700a60
Rollup merge of #152419 - nnethercote:mv-more-query-system-code, r=Za…
JonathanBrouwer Feb 10, 2026
ddded41
Rollup merge of #152431 - oli-obk:limited_stability_attr, r=jdonszelmann
JonathanBrouwer Feb 10, 2026
12f3a94
Rollup merge of #152436 - fmease:reenable-gci-test-case, r=mati865
JonathanBrouwer Feb 10, 2026
6a60888
Rollup merge of #151142 - SpriteOvO:type-info-adt, r=oli-obk
JonathanBrouwer Feb 10, 2026
2f8326f
Rollup merge of #152146 - zedddie:mgca-improve-const-bindings-wfck, r…
JonathanBrouwer Feb 10, 2026
29057db
Rollup merge of #152372 - nyurik:clippy-rustc_trait_selection, r=mati865
JonathanBrouwer Feb 10, 2026
71e762e
Rollup merge of #152383 - RalfJung:BikeshedGuaranteedNoDrop, r=TaKO8Ki
JonathanBrouwer Feb 10, 2026
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
3 changes: 3 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4492,6 +4492,7 @@ name = "rustc_query_impl"
version = "0.0.0"
dependencies = [
"measureme",
"rustc_abi",
"rustc_data_structures",
"rustc_errors",
"rustc_hashes",
Expand All @@ -4501,7 +4502,9 @@ dependencies = [
"rustc_middle",
"rustc_query_system",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_thread_pool",
"tracing",
]

Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,20 @@ impl<S: Stage> AttributeParser<S> for ConstStabilityParser {
this.promotable = true;
}),
];
const ALLOWED_TARGETS: AllowedTargets = ALLOWED_TARGETS;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Impl { of_trait: false }),
Allow(Target::Impl { of_trait: true }),
Allow(Target::Use), // FIXME I don't think this does anything?
Allow(Target::Const),
Allow(Target::AssocConst),
Allow(Target::Trait),
Allow(Target::Static),
Allow(Target::Crate),
]);

fn finalize(mut self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
if self.promotable {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ pub(crate) fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) {
}
}

pub(crate) fn count_params(llfn: &Value) -> c_uint {
LLVMCountParams(llfn)
}

/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
unsafe {
Expand Down
120 changes: 108 additions & 12 deletions compiler/rustc_codegen_llvm/src/mono_item.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::ffi::CString;

use rustc_abi::AddressSpace;
Expand All @@ -6,13 +7,17 @@ use rustc_hir::attrs::Linkage;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::mir::mono::Visibility;
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf};
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt};
use rustc_session::config::CrateType;
use rustc_target::callconv::FnAbi;
use rustc_target::spec::{Arch, RelocModel};
use tracing::debug;

use crate::abi::FnAbiLlvmExt;
use crate::builder::Builder;
use crate::context::CodegenCx;
use crate::errors::SymbolAlreadyDefined;
use crate::type_of::LayoutLlvmExt;
Expand Down Expand Up @@ -45,7 +50,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
self.assume_dso_local(g, false);

let attrs = self.tcx.codegen_instance_attrs(instance.def);
self.add_aliases(g, &attrs.foreign_item_symbol_aliases);
self.add_static_aliases(g, &attrs.foreign_item_symbol_aliases);

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

let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
let attrs = self.tcx.codegen_instance_attrs(instance.def);

let lldecl =
self.predefine_without_aliases(instance, &attrs, linkage, visibility, symbol_name);
self.add_function_aliases(instance, lldecl, &attrs, &attrs.foreign_item_symbol_aliases);

self.instances.borrow_mut().insert(instance, lldecl);
}
}

impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
fn predefine_without_aliases(
&self,
instance: Instance<'tcx>,
attrs: &Cow<'_, CodegenFnAttrs>,
linkage: Linkage,
visibility: Visibility,
symbol_name: &str,
) -> &'ll llvm::Value {
let fn_abi: &FnAbi<'tcx, Ty<'tcx>> = self.fn_abi_of_instance(instance, ty::List::empty());
let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance));
llvm::set_linkage(lldecl, base::linkage_to_llvm(linkage));
let attrs = self.tcx.codegen_instance_attrs(instance.def);
base::set_link_section(lldecl, &attrs);
base::set_link_section(lldecl, attrs);
if (linkage == Linkage::LinkOnceODR || linkage == Linkage::WeakODR)
&& self.tcx.sess.target.supports_comdat()
{
Expand All @@ -84,20 +107,45 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {

self.assume_dso_local(lldecl, false);

self.add_aliases(lldecl, &attrs.foreign_item_symbol_aliases);

self.instances.borrow_mut().insert(instance, lldecl);
lldecl
}
}

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

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

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

/// See [`add_static_aliases`](Self::add_static_aliases) for docs.
fn add_function_aliases(
&self,
aliasee_instance: Instance<'tcx>,
aliasee: &'ll llvm::Value,
attrs: &Cow<'_, CodegenFnAttrs>,
aliases: &[(DefId, Linkage, Visibility)],
) {
for (alias, linkage, visibility) in aliases {
let symbol_name = self.tcx.symbol_name(Instance::mono(self.tcx, *alias));
tracing::debug!("FUNCTION ALIAS: {alias:?} {linkage:?} {visibility:?}");

// predefine another copy of the original instance
// with a new symbol name
let alias_lldecl = self.predefine_without_aliases(
aliasee_instance,
attrs,
*linkage,
*visibility,
symbol_name.name,
);

let fn_abi: &FnAbi<'tcx, Ty<'tcx>> =
self.fn_abi_of_instance(aliasee_instance, ty::List::empty());

// both the alias and the aliasee have the same ty
let fn_ty = fn_abi.llvm_type(self);
let start_llbb = Builder::append_block(self, alias_lldecl, "start");
let mut start_bx = Builder::build(self, start_llbb);

let num_params = llvm::count_params(alias_lldecl);
let mut args = Vec::with_capacity(num_params as usize);
for index in 0..num_params {
args.push(llvm::get_param(alias_lldecl, index));
}

start_bx.tail_call(
fn_ty,
Some(attrs),
fn_abi,
aliasee,
&args,
None,
Some(aliasee_instance),
);
}
}

/// A definition or declaration can be assumed to be local to a group of
/// libraries that form a single DSO or executable.
/// Marks the local as DSO if so.
Expand Down
Loading
Loading