Skip to content

Commit 4542b32

Browse files
committed
[Arm64EC] Only decorate functions with #
1 parent f5d3fe2 commit 4542b32

File tree

13 files changed

+270
-55
lines changed

13 files changed

+270
-55
lines changed

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ jobs:
225225
fi
226226
exit ${STATUS}
227227
env:
228-
AWS_ACCESS_KEY_ID: ${{ env.CACHES_AWS_ACCESS_KEY_ID }}
229-
AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}
228+
SCCACHE_S3_NO_CREDENTIALS: 1
230229

231230
- name: create github artifacts
232231
run: src/ci/scripts/create-doc-artifacts.sh

compiler/rustc_codegen_llvm/src/consts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ impl<'ll> CodegenCx<'ll, '_> {
364364

365365
if !def_id.is_local() {
366366
let needs_dll_storage_attr = self.use_dll_storage_attrs
367-
&& !self.tcx.is_foreign_item(def_id)
367+
&& (!self.tcx.is_foreign_item(def_id)
368+
|| fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL))
368369
// Local definitions can never be imported, so we must not apply
369370
// the DLLImport annotation.
370371
&& !dso_local

compiler/rustc_codegen_ssa/src/back/linker.rs

+88-29
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,12 @@ pub(crate) trait Linker {
337337
fn debuginfo(&mut self, strip: Strip, natvis_debugger_visualizers: &[PathBuf]);
338338
fn no_crt_objects(&mut self);
339339
fn no_default_libraries(&mut self);
340-
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]);
340+
fn export_symbols(
341+
&mut self,
342+
tmpdir: &Path,
343+
crate_type: CrateType,
344+
symbols: &[(String, SymbolExportKind)],
345+
);
341346
fn subsystem(&mut self, subsystem: &str);
342347
fn linker_plugin_lto(&mut self);
343348
fn add_eh_frame_header(&mut self) {}
@@ -770,7 +775,12 @@ impl<'a> Linker for GccLinker<'a> {
770775
}
771776
}
772777

773-
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
778+
fn export_symbols(
779+
&mut self,
780+
tmpdir: &Path,
781+
crate_type: CrateType,
782+
symbols: &[(String, SymbolExportKind)],
783+
) {
774784
// Symbol visibility in object files typically takes care of this.
775785
if crate_type == CrateType::Executable {
776786
let should_export_executable_symbols =
@@ -799,7 +809,7 @@ impl<'a> Linker for GccLinker<'a> {
799809
// Write a plain, newline-separated list of symbols
800810
let res: io::Result<()> = try {
801811
let mut f = File::create_buffered(&path)?;
802-
for sym in symbols {
812+
for (sym, _) in symbols {
803813
debug!(" _{sym}");
804814
writeln!(f, "_{sym}")?;
805815
}
@@ -814,7 +824,7 @@ impl<'a> Linker for GccLinker<'a> {
814824
// .def file similar to MSVC one but without LIBRARY section
815825
// because LD doesn't like when it's empty
816826
writeln!(f, "EXPORTS")?;
817-
for symbol in symbols {
827+
for (symbol, _) in symbols {
818828
debug!(" _{symbol}");
819829
// Quote the name in case it's reserved by linker in some way
820830
// (this accounts for names with dots in particular).
@@ -831,7 +841,7 @@ impl<'a> Linker for GccLinker<'a> {
831841
writeln!(f, "{{")?;
832842
if !symbols.is_empty() {
833843
writeln!(f, " global:")?;
834-
for sym in symbols {
844+
for (sym, _) in symbols {
835845
debug!(" {sym};");
836846
writeln!(f, " {sym};")?;
837847
}
@@ -1098,7 +1108,12 @@ impl<'a> Linker for MsvcLinker<'a> {
10981108
// crates. Upstream rlibs may be linked statically to this dynamic library,
10991109
// in which case they may continue to transitively be used and hence need
11001110
// their symbols exported.
1101-
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
1111+
fn export_symbols(
1112+
&mut self,
1113+
tmpdir: &Path,
1114+
crate_type: CrateType,
1115+
symbols: &[(String, SymbolExportKind)],
1116+
) {
11021117
// Symbol visibility takes care of this typically
11031118
if crate_type == CrateType::Executable {
11041119
let should_export_executable_symbols =
@@ -1116,9 +1131,10 @@ impl<'a> Linker for MsvcLinker<'a> {
11161131
// straight to exports.
11171132
writeln!(f, "LIBRARY")?;
11181133
writeln!(f, "EXPORTS")?;
1119-
for symbol in symbols {
1134+
for (symbol, kind) in symbols {
1135+
let kind_marker = if *kind == SymbolExportKind::Data { " DATA" } else { "" };
11201136
debug!(" _{symbol}");
1121-
writeln!(f, " {symbol}")?;
1137+
writeln!(f, " {symbol}{kind_marker}")?;
11221138
}
11231139
};
11241140
if let Err(error) = res {
@@ -1259,14 +1275,19 @@ impl<'a> Linker for EmLinker<'a> {
12591275
self.cc_arg("-nodefaultlibs");
12601276
}
12611277

1262-
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
1278+
fn export_symbols(
1279+
&mut self,
1280+
_tmpdir: &Path,
1281+
_crate_type: CrateType,
1282+
symbols: &[(String, SymbolExportKind)],
1283+
) {
12631284
debug!("EXPORTED SYMBOLS:");
12641285

12651286
self.cc_arg("-s");
12661287

12671288
let mut arg = OsString::from("EXPORTED_FUNCTIONS=");
12681289
let encoded = serde_json::to_string(
1269-
&symbols.iter().map(|sym| "_".to_owned() + sym).collect::<Vec<_>>(),
1290+
&symbols.iter().map(|(sym, _)| "_".to_owned() + sym).collect::<Vec<_>>(),
12701291
)
12711292
.unwrap();
12721293
debug!("{encoded}");
@@ -1428,8 +1449,13 @@ impl<'a> Linker for WasmLd<'a> {
14281449

14291450
fn no_default_libraries(&mut self) {}
14301451

1431-
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
1432-
for sym in symbols {
1452+
fn export_symbols(
1453+
&mut self,
1454+
_tmpdir: &Path,
1455+
_crate_type: CrateType,
1456+
symbols: &[(String, SymbolExportKind)],
1457+
) {
1458+
for (sym, _) in symbols {
14331459
self.link_args(&["--export", sym]);
14341460
}
14351461

@@ -1563,7 +1589,7 @@ impl<'a> Linker for L4Bender<'a> {
15631589
self.cc_arg("-nostdlib");
15641590
}
15651591

1566-
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
1592+
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[(String, SymbolExportKind)]) {
15671593
// ToDo, not implemented, copy from GCC
15681594
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
15691595
}
@@ -1720,12 +1746,17 @@ impl<'a> Linker for AixLinker<'a> {
17201746

17211747
fn no_default_libraries(&mut self) {}
17221748

1723-
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
1749+
fn export_symbols(
1750+
&mut self,
1751+
tmpdir: &Path,
1752+
_crate_type: CrateType,
1753+
symbols: &[(String, SymbolExportKind)],
1754+
) {
17241755
let path = tmpdir.join("list.exp");
17251756
let res: io::Result<()> = try {
17261757
let mut f = File::create_buffered(&path)?;
17271758
// FIXME: use llvm-nm to generate export list.
1728-
for symbol in symbols {
1759+
for (symbol, _) in symbols {
17291760
debug!(" _{symbol}");
17301761
writeln!(f, " {symbol}")?;
17311762
}
@@ -1769,9 +1800,12 @@ fn for_each_exported_symbols_include_dep<'tcx>(
17691800
}
17701801
}
17711802

1772-
pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
1803+
pub(crate) fn exported_symbols(
1804+
tcx: TyCtxt<'_>,
1805+
crate_type: CrateType,
1806+
) -> Vec<(String, SymbolExportKind)> {
17731807
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
1774-
return exports.iter().map(ToString::to_string).collect();
1808+
return exports.iter().map(|name| (name.to_string(), SymbolExportKind::Text)).collect();
17751809
}
17761810

17771811
if let CrateType::ProcMacro = crate_type {
@@ -1781,25 +1815,29 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
17811815
}
17821816
}
17831817

1784-
fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
1818+
fn exported_symbols_for_non_proc_macro(
1819+
tcx: TyCtxt<'_>,
1820+
crate_type: CrateType,
1821+
) -> Vec<(String, SymbolExportKind)> {
17851822
let mut symbols = Vec::new();
17861823
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
17871824
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
17881825
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
17891826
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
17901827
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
17911828
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum) {
1792-
symbols.push(symbol_export::exporting_symbol_name_for_instance_in_crate(
1793-
tcx, symbol, cnum,
1829+
symbols.push((
1830+
symbol_export::exporting_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
1831+
info.kind,
17941832
));
1795-
symbol_export::extend_exported_symbols(&mut symbols, tcx, symbol, cnum);
1833+
symbol_export::extend_exported_symbols(&mut symbols, tcx, symbol, info, cnum);
17961834
}
17971835
});
17981836

17991837
symbols
18001838
}
18011839

1802-
fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
1840+
fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<(String, SymbolExportKind)> {
18031841
// `exported_symbols` will be empty when !should_codegen.
18041842
if !tcx.sess.opts.output_types.should_codegen() {
18051843
return Vec::new();
@@ -1809,7 +1847,10 @@ fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
18091847
let proc_macro_decls_name = tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id);
18101848
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
18111849

1812-
vec![proc_macro_decls_name, metadata_symbol_name]
1850+
vec![
1851+
(proc_macro_decls_name, SymbolExportKind::Text),
1852+
(metadata_symbol_name, SymbolExportKind::Text),
1853+
]
18131854
}
18141855

18151856
pub(crate) fn linked_symbols(
@@ -1831,7 +1872,9 @@ pub(crate) fn linked_symbols(
18311872
|| info.used
18321873
{
18331874
symbols.push((
1834-
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
1875+
symbol_export::linking_symbol_name_for_instance_in_crate(
1876+
tcx, symbol, info.kind, cnum,
1877+
),
18351878
info.kind,
18361879
));
18371880
}
@@ -1906,7 +1949,13 @@ impl<'a> Linker for PtxLinker<'a> {
19061949

19071950
fn ehcont_guard(&mut self) {}
19081951

1909-
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, _symbols: &[String]) {}
1952+
fn export_symbols(
1953+
&mut self,
1954+
_tmpdir: &Path,
1955+
_crate_type: CrateType,
1956+
_symbols: &[(String, SymbolExportKind)],
1957+
) {
1958+
}
19101959

19111960
fn subsystem(&mut self, _subsystem: &str) {}
19121961

@@ -1975,10 +2024,15 @@ impl<'a> Linker for LlbcLinker<'a> {
19752024

19762025
fn ehcont_guard(&mut self) {}
19772026

1978-
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
2027+
fn export_symbols(
2028+
&mut self,
2029+
_tmpdir: &Path,
2030+
_crate_type: CrateType,
2031+
symbols: &[(String, SymbolExportKind)],
2032+
) {
19792033
match _crate_type {
19802034
CrateType::Cdylib => {
1981-
for sym in symbols {
2035+
for (sym, _) in symbols {
19822036
self.link_args(&["--export-symbol", sym]);
19832037
}
19842038
}
@@ -2052,11 +2106,16 @@ impl<'a> Linker for BpfLinker<'a> {
20522106

20532107
fn ehcont_guard(&mut self) {}
20542108

2055-
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
2109+
fn export_symbols(
2110+
&mut self,
2111+
tmpdir: &Path,
2112+
_crate_type: CrateType,
2113+
symbols: &[(String, SymbolExportKind)],
2114+
) {
20562115
let path = tmpdir.join("symbols");
20572116
let res: io::Result<()> = try {
20582117
let mut f = File::create_buffered(&path)?;
2059-
for sym in symbols {
2118+
for (sym, _) in symbols {
20602119
writeln!(f, "{sym}")?;
20612120
}
20622121
};

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ fn calling_convention_for_symbol<'tcx>(
692692
pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
693693
tcx: TyCtxt<'tcx>,
694694
symbol: ExportedSymbol<'tcx>,
695+
export_kind: SymbolExportKind,
695696
instantiating_crate: CrateNum,
696697
) -> String {
697698
let mut undecorated = symbol_name_for_instance_in_crate(tcx, symbol, instantiating_crate);
@@ -712,8 +713,9 @@ pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
712713
let prefix = match &target.arch[..] {
713714
"x86" => Some('_'),
714715
"x86_64" => None,
715-
"arm64ec" => Some('#'),
716-
// Only x86/64 use symbol decorations.
716+
// Only functions are decorated for arm64ec.
717+
"arm64ec" if export_kind == SymbolExportKind::Text => Some('#'),
718+
// Only x86/64 and arm64ec use symbol decorations.
717719
_ => return undecorated,
718720
};
719721

@@ -753,9 +755,10 @@ pub(crate) fn exporting_symbol_name_for_instance_in_crate<'tcx>(
753755
/// Add it to the symbols list for all kernel functions, so that it is exported in the linked
754756
/// object.
755757
pub(crate) fn extend_exported_symbols<'tcx>(
756-
symbols: &mut Vec<String>,
758+
symbols: &mut Vec<(String, SymbolExportKind)>,
757759
tcx: TyCtxt<'tcx>,
758760
symbol: ExportedSymbol<'tcx>,
761+
info: SymbolExportInfo,
759762
instantiating_crate: CrateNum,
760763
) {
761764
let (conv, _) = calling_convention_for_symbol(tcx, symbol);
@@ -767,7 +770,7 @@ pub(crate) fn extend_exported_symbols<'tcx>(
767770
let undecorated = symbol_name_for_instance_in_crate(tcx, symbol, instantiating_crate);
768771

769772
// Add the symbol for the kernel descriptor (with .kd suffix)
770-
symbols.push(format!("{undecorated}.kd"));
773+
symbols.push((format!("{undecorated}.kd"), info.kind));
771774
}
772775

773776
fn maybe_emutls_symbol_name<'tcx>(

0 commit comments

Comments
 (0)