Refactor exported_symbols and linked_symbols for code reuse
This commit is contained in:
parent
78f0e72431
commit
c475117ffb
@ -12,7 +12,7 @@ use std::{env, mem, str};
|
||||
|
||||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
||||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_serialize::{json, Encoder};
|
||||
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
|
||||
@ -1519,22 +1519,13 @@ impl<'a> L4Bender<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
|
||||
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
|
||||
return exports.clone();
|
||||
}
|
||||
|
||||
let mut symbols = Vec::new();
|
||||
|
||||
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
|
||||
fn for_each_exported_symbols_include_dep<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
crate_type: CrateType,
|
||||
mut callback: impl FnMut(ExportedSymbol<'tcx>, SymbolExportInfo, CrateNum),
|
||||
) {
|
||||
for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() {
|
||||
if info.level.is_below_threshold(export_threshold) {
|
||||
symbols.push(symbol_export::symbol_name_for_instance_in_crate(
|
||||
tcx,
|
||||
symbol,
|
||||
LOCAL_CRATE,
|
||||
));
|
||||
}
|
||||
callback(symbol, info, LOCAL_CRATE);
|
||||
}
|
||||
|
||||
let formats = tcx.dependency_formats(());
|
||||
@ -1544,16 +1535,26 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
|
||||
let cnum = CrateNum::new(index + 1);
|
||||
// For each dependency that we are linking to statically ...
|
||||
if *dep_format == Linkage::Static {
|
||||
// ... we add its symbol list to our export list.
|
||||
for &(symbol, info) in tcx.exported_symbols(cnum).iter() {
|
||||
if !info.level.is_below_threshold(export_threshold) {
|
||||
continue;
|
||||
}
|
||||
|
||||
symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
|
||||
callback(symbol, info, cnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
|
||||
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
|
||||
return exports.clone();
|
||||
}
|
||||
|
||||
let mut symbols = Vec::new();
|
||||
|
||||
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
|
||||
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
|
||||
if info.level.is_below_threshold(export_threshold) {
|
||||
symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
|
||||
}
|
||||
});
|
||||
|
||||
symbols
|
||||
}
|
||||
@ -1572,33 +1573,14 @@ pub(crate) fn linked_symbols(
|
||||
let mut symbols = Vec::new();
|
||||
|
||||
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
|
||||
for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() {
|
||||
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
|
||||
if info.level.is_below_threshold(export_threshold) || info.used {
|
||||
symbols.push((
|
||||
symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, LOCAL_CRATE),
|
||||
symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum),
|
||||
info.kind,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let formats = tcx.dependency_formats(());
|
||||
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
|
||||
|
||||
for (index, dep_format) in deps.iter().enumerate() {
|
||||
let cnum = CrateNum::new(index + 1);
|
||||
// For each dependency that we are linking to statically ...
|
||||
if *dep_format == Linkage::Static {
|
||||
// ... we add its symbol list to our export list.
|
||||
for &(symbol, info) in tcx.exported_symbols(cnum).iter() {
|
||||
if info.level.is_below_threshold(export_threshold) || info.used {
|
||||
symbols.push((
|
||||
symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum),
|
||||
info.kind,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
symbols
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user