Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8463164

Browse files
[Arm64EC] Only decorate functions with #
1 parent 8de4c72 commit 8463164

File tree

9 files changed

+186
-52
lines changed

9 files changed

+186
-52
lines changed

‎compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 90 additions & 30 deletions
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,11 +824,12 @@ 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, kind) in symbols {
828+
let kind_marker = if *kind == SymbolExportKind::Data { " DATA" } else { "" };
818829
debug!(" _{symbol}");
819830
// Quote the name in case it's reserved by linker in some way
820831
// (this accounts for names with dots in particular).
821-
writeln!(f, " \"{symbol}\"")?;
832+
writeln!(f, " \"{symbol}\"{kind_marker}")?;
822833
}
823834
};
824835
if let Err(error) = res {
@@ -831,7 +842,7 @@ impl<'a> Linker for GccLinker<'a> {
831842
writeln!(f, "{{")?;
832843
if !symbols.is_empty() {
833844
writeln!(f, " global:")?;
834-
for sym in symbols {
845+
for (sym, _) in symbols {
835846
debug!(" {sym};");
836847
writeln!(f, " {sym};")?;
837848
}
@@ -1098,7 +1109,12 @@ impl<'a> Linker for MsvcLinker<'a> {
10981109
// crates. Upstream rlibs may be linked statically to this dynamic library,
10991110
// in which case they may continue to transitively be used and hence need
11001111
// their symbols exported.
1101-
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
1112+
fn export_symbols(
1113+
&mut self,
1114+
tmpdir: &Path,
1115+
crate_type: CrateType,
1116+
symbols: &[(String, SymbolExportKind)],
1117+
) {
11021118
// Symbol visibility takes care of this typically
11031119
if crate_type == CrateType::Executable {
11041120
let should_export_executable_symbols =
@@ -1116,9 +1132,10 @@ impl<'a> Linker for MsvcLinker<'a> {
11161132
// straight to exports.
11171133
writeln!(f, "LIBRARY")?;
11181134
writeln!(f, "EXPORTS")?;
1119-
for symbol in symbols {
1135+
for (symbol, kind) in symbols {
1136+
let kind_marker = if *kind == SymbolExportKind::Data { " DATA" } else { "" };
11201137
debug!(" _{symbol}");
1121-
writeln!(f, " {symbol}")?;
1138+
writeln!(f, " {symbol}{kind_marker}")?;
11221139
}
11231140
};
11241141
if let Err(error) = res {
@@ -1259,14 +1276,19 @@ impl<'a> Linker for EmLinker<'a> {
12591276
self.cc_arg("-nodefaultlibs");
12601277
}
12611278

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

12651287
self.cc_arg("-s");
12661288

12671289
let mut arg = OsString::from("EXPORTED_FUNCTIONS=");
12681290
let encoded = serde_json::to_string(
1269-
&symbols.iter().map(|sym| "_".to_owned() + sym).collect::<Vec<_>>(),
1291+
&symbols.iter().map(|(sym, _)| "_".to_owned() + sym).collect::<Vec<_>>(),
12701292
)
12711293
.unwrap();
12721294
debug!("{encoded}");
@@ -1428,8 +1450,13 @@ impl<'a> Linker for WasmLd<'a> {
14281450

14291451
fn no_default_libraries(&mut self) {}
14301452

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

@@ -1563,7 +1590,7 @@ impl<'a> Linker for L4Bender<'a> {
15631590
self.cc_arg("-nostdlib");
15641591
}
15651592

1566-
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
1593+
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[(String,SymbolExportKind)]) {
15671594
// ToDo, not implemented, copy from GCC
15681595
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
15691596
}
@@ -1720,12 +1747,17 @@ impl<'a> Linker for AixLinker<'a> {
17201747

17211748
fn no_default_libraries(&mut self) {}
17221749

1723-
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
1750+
fn export_symbols(
1751+
&mut self,
1752+
tmpdir: &Path,
1753+
_crate_type: CrateType,
1754+
symbols: &[(String, SymbolExportKind)],
1755+
) {
17241756
let path = tmpdir.join("list.exp");
17251757
let res: io::Result<()> = try {
17261758
let mut f = File::create_buffered(&path)?;
17271759
// FIXME: use llvm-nm to generate export list.
1728-
for symbol in symbols {
1760+
for (symbol, _) in symbols {
17291761
debug!(" _{symbol}");
17301762
writeln!(f, " {symbol}")?;
17311763
}
@@ -1769,9 +1801,12 @@ fn for_each_exported_symbols_include_dep<'tcx>(
17691801
}
17701802
}
17711803

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

17771812
if let CrateType::ProcMacro = crate_type {
@@ -1781,25 +1816,29 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
17811816
}
17821817
}
17831818

1784-
fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
1819+
fn exported_symbols_for_non_proc_macro(
1820+
tcx: TyCtxt<'_>,
1821+
crate_type: CrateType,
1822+
) -> Vec<(String, SymbolExportKind)> {
17851823
let mut symbols = Vec::new();
17861824
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
17871825
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
17881826
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
17891827
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
17901828
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
17911829
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,
1830+
symbols.push((
1831+
symbol_export::exporting_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
1832+
info.kind,
17941833
));
1795-
symbol_export::extend_exported_symbols(&mut symbols, tcx, symbol, cnum);
1834+
symbol_export::extend_exported_symbols(&mut symbols, tcx, symbol, info,cnum);
17961835
}
17971836
});
17981837

17991838
symbols
18001839
}
18011840

1802-
fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
1841+
fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<(String,SymbolExportKind)> {
18031842
// `exported_symbols` will be empty when !should_codegen.
18041843
if !tcx.sess.opts.output_types.should_codegen() {
18051844
return Vec::new();
@@ -1809,7 +1848,10 @@ fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> {
18091848
let proc_macro_decls_name = tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id);
18101849
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
18111850

1812-
vec![proc_macro_decls_name, metadata_symbol_name]
1851+
vec![
1852+
(proc_macro_decls_name, SymbolExportKind::Text),
1853+
(metadata_symbol_name, SymbolExportKind::Text),
1854+
]
18131855
}
18141856

18151857
pub(crate) fn linked_symbols(
@@ -1831,7 +1873,9 @@ pub(crate) fn linked_symbols(
18311873
|| info.used
18321874
{
18331875
symbols.push((
1834-
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
1876+
symbol_export::linking_symbol_name_for_instance_in_crate(
1877+
tcx, symbol, info.kind, cnum,
1878+
),
18351879
info.kind,
18361880
));
18371881
}
@@ -1906,7 +1950,13 @@ impl<'a> Linker for PtxLinker<'a> {
19061950

19071951
fn ehcont_guard(&mut self) {}
19081952

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

19111961
fn subsystem(&mut self, _subsystem: &str) {}
19121962

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

19762026
fn ehcont_guard(&mut self) {}
19772027

1978-
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
2028+
fn export_symbols(
2029+
&mut self,
2030+
_tmpdir: &Path,
2031+
_crate_type: CrateType,
2032+
symbols: &[(String, SymbolExportKind)],
2033+
) {
19792034
match _crate_type {
19802035
CrateType::Cdylib => {
1981-
for sym in symbols {
2036+
for (sym, _) in symbols {
19822037
self.link_args(&["--export-symbol", sym]);
19832038
}
19842039
}
@@ -2052,11 +2107,16 @@ impl<'a> Linker for BpfLinker<'a> {
20522107

20532108
fn ehcont_guard(&mut self) {}
20542109

2055-
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
2110+
fn export_symbols(
2111+
&mut self,
2112+
tmpdir: &Path,
2113+
_crate_type: CrateType,
2114+
symbols: &[(String, SymbolExportKind)],
2115+
) {
20562116
let path = tmpdir.join("symbols");
20572117
let res: io::Result<()> = try {
20582118
let mut f = File::create_buffered(&path)?;
2059-
for sym in symbols {
2119+
for (sym, _) in symbols {
20602120
writeln!(f, "{sym}")?;
20612121
}
20622122
};

‎compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ fn calling_convention_for_symbol<'tcx>(
680680
pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
681681
tcx: TyCtxt<'tcx>,
682682
symbol: ExportedSymbol<'tcx>,
683+
export_kind: SymbolExportKind,
683684
instantiating_crate: CrateNum,
684685
) -> String {
685686
let mut undecorated = symbol_name_for_instance_in_crate(tcx, symbol, instantiating_crate);
@@ -700,8 +701,9 @@ pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
700701
let prefix = match &target.arch[..] {
701702
"x86" => Some('_'),
702703
"x86_64" => None,
703-
"arm64ec" => Some('#'),
704-
// Only x86/64 use symbol decorations.
704+
// Only functions are decorated for arm64ec.
705+
"arm64ec" if export_kind == SymbolExportKind::Text => Some('#'),
706+
// Only x86/64 and arm64ec use symbol decorations.
705707
_ => return undecorated,
706708
};
707709

@@ -741,9 +743,10 @@ pub(crate) fn exporting_symbol_name_for_instance_in_crate<'tcx>(
741743
/// Add it to the symbols list for all kernel functions, so that it is exported in the linked
742744
/// object.
743745
pub(crate) fn extend_exported_symbols<'tcx>(
744-
symbols: &mut Vec<String>,
746+
symbols: &mut Vec<(String,SymbolExportKind)>,
745747
tcx: TyCtxt<'tcx>,
746748
symbol: ExportedSymbol<'tcx>,
749+
info: SymbolExportInfo,
747750
instantiating_crate: CrateNum,
748751
) {
749752
let (callconv, _) = calling_convention_for_symbol(tcx, symbol);
@@ -755,7 +758,7 @@ pub(crate) fn extend_exported_symbols<'tcx>(
755758
let undecorated = symbol_name_for_instance_in_crate(tcx, symbol, instantiating_crate);
756759

757760
// Add the symbol for the kernel descriptor (with .kd suffix)
758-
symbols.push(format!("{undecorated}.kd"));
761+
symbols.push((format!("{undecorated}.kd"), info.kind));
759762
}
760763

761764
fn maybe_emutls_symbol_name<'tcx>(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /