Skip to content

Commit 4f4aaf6

Browse files
authored
Rollup merge of rust-lang#150811 - defid-aliases, r=bjorn3
Store defids instead of symbol names in the aliases list I was honestly surprised this worked in the past. This causes a cycle error since we now compute a symbol name in codegen_attrs, and then compute codegen attrs when we try to get the symbol name. It only worked when there weren't any codegen attributes to begin with, causing symbol name computation to skip the call to codegen_attrs. Like this we won't have the same problem. r? @bjorn3
2 parents 91ff785 + 6b88c6b commit 4f4aaf6

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_middle::mir::mono::Visibility;
1010
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf};
1111
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
1212
use rustc_session::config::CrateType;
13-
use rustc_span::Symbol;
1413
use rustc_target::spec::{Arch, RelocModel};
1514
use tracing::debug;
1615

@@ -92,17 +91,19 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
9291
}
9392

9493
impl CodegenCx<'_, '_> {
95-
fn add_aliases(&self, aliasee: &llvm::Value, aliases: &[(Symbol, Linkage, Visibility)]) {
94+
fn add_aliases(&self, aliasee: &llvm::Value, aliases: &[(DefId, Linkage, Visibility)]) {
9695
let ty = self.get_type_of_global(aliasee);
9796

9897
for (alias, linkage, visibility) in aliases {
98+
let symbol_name = self.tcx.symbol_name(Instance::mono(self.tcx, *alias));
99+
99100
tracing::debug!("ALIAS: {alias:?} {linkage:?} {visibility:?}");
100101
let lldecl = llvm::add_alias(
101102
self.llmod,
102103
ty,
103104
AddressSpace::ZERO,
104105
aliasee,
105-
&CString::new(alias.as_str()).unwrap(),
106+
&CString::new(symbol_name.name).unwrap(),
106107
);
107108

108109
llvm::set_visibility(lldecl, base::visibility_to_llvm(*visibility));

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rustc_middle::middle::codegen_fn_attrs::{
1313
use rustc_middle::mir::mono::Visibility;
1414
use rustc_middle::query::Providers;
1515
use rustc_middle::span_bug;
16-
use rustc_middle::ty::{self as ty, Instance, TyCtxt};
16+
use rustc_middle::ty::{self as ty, TyCtxt};
1717
use rustc_session::lint;
1818
use rustc_session::parse::feature_err;
19-
use rustc_span::{Span, Symbol, sym};
19+
use rustc_span::{Span, sym};
2020
use rustc_target::spec::Os;
2121

2222
use crate::errors;
@@ -291,8 +291,6 @@ fn process_builtin_attrs(
291291
)
292292
.expect("eii should have declaration macro with extern target attribute");
293293

294-
let symbol_name = tcx.symbol_name(Instance::mono(tcx, extern_item));
295-
296294
// this is to prevent a bug where a single crate defines both the default and explicit implementation
297295
// for an EII. In that case, both of them may be part of the same final object file. I'm not 100% sure
298296
// what happens, either rustc deduplicates the symbol or llvm, or it's random/order-dependent.
@@ -310,7 +308,7 @@ fn process_builtin_attrs(
310308
}
311309

312310
codegen_fn_attrs.foreign_item_symbol_aliases.push((
313-
Symbol::intern(symbol_name.name),
311+
extern_item,
314312
if i.is_default { Linkage::LinkOnceAny } else { Linkage::External },
315313
Visibility::Default,
316314
));

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::Cow;
22

33
use rustc_abi::Align;
44
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, Linkage, OptimizeAttr, RtsanSetting};
5+
use rustc_hir::def_id::DefId;
56
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
67
use rustc_span::Symbol;
78
use rustc_target::spec::SanitizerSet;
@@ -72,7 +73,7 @@ pub struct CodegenFnAttrs {
7273
/// generate this function under its real name,
7374
/// but *also* under the same name as this foreign function so that the foreign function has an implementation.
7475
// FIXME: make "SymbolName<'tcx>"
75-
pub foreign_item_symbol_aliases: Vec<(Symbol, Linkage, Visibility)>,
76+
pub foreign_item_symbol_aliases: Vec<(DefId, Linkage, Visibility)>,
7677
/// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an
7778
/// imported function has in the dynamic library. Note that this must not
7879
/// be set when `link_name` is set. This is for foreign items with the

0 commit comments

Comments
 (0)