Skip to content

Commit 7b715cf

Browse files
committed
[Arm64EC] Only decorate functions with #
1 parent d6c1e45 commit 7b715cf

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,9 @@ pub(crate) fn linked_symbols(
18291829
|| info.used
18301830
{
18311831
symbols.push((
1832-
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
1832+
symbol_export::linking_symbol_name_for_instance_in_crate(
1833+
tcx, symbol, info.kind, cnum,
1834+
),
18331835
info.kind,
18341836
));
18351837
}

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ fn calling_convention_for_symbol<'tcx>(
628628
pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
629629
tcx: TyCtxt<'tcx>,
630630
symbol: ExportedSymbol<'tcx>,
631+
export_kind: SymbolExportKind,
631632
instantiating_crate: CrateNum,
632633
) -> String {
633634
let mut undecorated = symbol_name_for_instance_in_crate(tcx, symbol, instantiating_crate);
@@ -648,8 +649,9 @@ pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
648649
let prefix = match &target.arch[..] {
649650
"x86" => Some('_'),
650651
"x86_64" => None,
651-
"arm64ec" => Some('#'),
652-
// Only x86/64 use symbol decorations.
652+
// Only functions are decorated for arm64ec.
653+
"arm64ec" if export_kind == SymbolExportKind::Text => Some('#'),
654+
// Only x86/64 and arm64ec use symbol decorations.
653655
_ => return undecorated,
654656
};
655657

compiler/rustc_codegen_ssa/src/base.rs

+32-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
1313
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
1414
use rustc_data_structures::unord::UnordMap;
15+
use rustc_hir::Target;
1516
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1617
use rustc_hir::lang_items::LangItem;
1718
use rustc_metadata::EncodedMetadata;
@@ -967,21 +968,35 @@ impl CrateInfo {
967968
// by the compiler, but that's ok because all this stuff is unstable anyway.
968969
let target = &tcx.sess.target;
969970
if !are_upstream_rust_objects_already_included(tcx.sess) {
970-
let missing_weak_lang_items: FxIndexSet<Symbol> = info
971+
let add_prefix = match (target.is_like_windows, target.arch.as_ref()) {
972+
(true, "x86") => |name: String, _: SymbolExportKind| format!("_{name}"),
973+
(true, "arm64ec") => {
974+
// Only functions are decorated for arm64ec.
975+
|name: String, export_kind: SymbolExportKind| match export_kind {
976+
SymbolExportKind::Text => format!("#{name}"),
977+
_ => name,
978+
}
979+
}
980+
_ => |name: String, _: SymbolExportKind| name,
981+
};
982+
let missing_weak_lang_items: FxIndexSet<(Symbol, SymbolExportKind)> = info
971983
.used_crates
972984
.iter()
973985
.flat_map(|&cnum| tcx.missing_lang_items(cnum))
974986
.filter(|l| l.is_weak())
975987
.filter_map(|&l| {
976988
let name = l.link_name()?;
977-
lang_items::required(tcx, l).then_some(name)
989+
let export_kind = match l.target() {
990+
Target::Fn => SymbolExportKind::Text,
991+
Target::Static => SymbolExportKind::Data,
992+
_ => bug!(
993+
"Don't know what the export kind is for lang item of kind {:?}",
994+
l.target()
995+
),
996+
};
997+
lang_items::required(tcx, l).then_some((name, export_kind))
978998
})
979999
.collect();
980-
let prefix = match (target.is_like_windows, target.arch.as_ref()) {
981-
(true, "x86") => "_",
982-
(true, "arm64ec") => "#",
983-
_ => "",
984-
};
9851000

9861001
// This loop only adds new items to values of the hash map, so the order in which we
9871002
// iterate over the values is not important.
@@ -994,10 +1009,13 @@ impl CrateInfo {
9941009
.for_each(|(_, linked_symbols)| {
9951010
let mut symbols = missing_weak_lang_items
9961011
.iter()
997-
.map(|item| {
1012+
.map(|(item, export_kind)| {
9981013
(
999-
format!("{prefix}{}", mangle_internal_symbol(tcx, item.as_str())),
1000-
SymbolExportKind::Text,
1014+
add_prefix(
1015+
mangle_internal_symbol(tcx, item.as_str()),
1016+
*export_kind,
1017+
),
1018+
*export_kind,
10011019
)
10021020
})
10031021
.collect::<Vec<_>>();
@@ -1012,12 +1030,12 @@ impl CrateInfo {
10121030
// errors.
10131031
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
10141032
(
1015-
format!(
1016-
"{prefix}{}",
1033+
add_prefix(
10171034
mangle_internal_symbol(
10181035
tcx,
1019-
global_fn_name(method.name).as_str()
1020-
)
1036+
global_fn_name(method.name).as_str(),
1037+
),
1038+
SymbolExportKind::Text,
10211039
),
10221040
SymbolExportKind::Text,
10231041
)

compiler/rustc_middle/src/middle/exported_symbols.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl SymbolExportLevel {
2222
}
2323

2424
/// Kind of exported symbols.
25-
#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)]
25+
#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable, Hash)]
2626
pub enum SymbolExportKind {
2727
Text,
2828
Data,

0 commit comments

Comments
 (0)