Skip to content

Commit bfa6fdc

Browse files
trans: Allow base::internalize_symbols() to internalize #[no_mangle] symbols
1 parent 928c398 commit bfa6fdc

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

src/librustc_trans/base.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -1421,21 +1421,7 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
14211421
.iter()
14221422
.cloned()
14231423
.filter(|trans_item|{
1424-
let def_id = match *trans_item {
1425-
TransItem::DropGlue(..) => {
1426-
return false
1427-
},
1428-
TransItem::Fn(ref instance) => {
1429-
instance.def
1430-
}
1431-
TransItem::Static(node_id) => {
1432-
tcx.map.local_def_id(node_id)
1433-
}
1434-
};
1435-
1436-
trans_item.explicit_linkage(tcx).is_some() ||
1437-
attr::contains_extern_indicator(tcx.sess.diagnostic(),
1438-
&tcx.get_attrs(def_id))
1424+
trans_item.explicit_linkage(tcx).is_some()
14391425
})
14401426
.map(|trans_item| symbol_map.get_or_compute(scx, trans_item))
14411427
.collect();
@@ -1900,8 +1886,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
19001886
partitioning::partition(scx,
19011887
items.iter().cloned(),
19021888
strategy,
1903-
&inlining_map,
1904-
scx.reachable())
1889+
&inlining_map)
19051890
});
19061891

19071892
assert!(scx.tcx().sess.opts.cg.codegen_units == codegen_units.len() ||

src/librustc_trans/partitioning.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ use symbol_map::SymbolMap;
133133
use syntax::ast::NodeId;
134134
use syntax::parse::token::{self, InternedString};
135135
use trans_item::TransItem;
136-
use util::nodemap::{FnvHashMap, FnvHashSet, NodeSet};
136+
use util::nodemap::{FnvHashMap, FnvHashSet};
137137

138138
pub enum PartitioningStrategy {
139139
/// Generate one codegen unit per source-level module.
@@ -254,8 +254,7 @@ const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
254254
pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
255255
trans_items: I,
256256
strategy: PartitioningStrategy,
257-
inlining_map: &InliningMap<'tcx>,
258-
reachable: &NodeSet)
257+
inlining_map: &InliningMap<'tcx>)
259258
-> Vec<CodegenUnit<'tcx>>
260259
where I: Iterator<Item = TransItem<'tcx>>
261260
{
@@ -265,8 +264,7 @@ pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
265264
// respective 'home' codegen unit. Regular translation items are all
266265
// functions and statics defined in the local crate.
267266
let mut initial_partitioning = place_root_translation_items(scx,
268-
trans_items,
269-
reachable);
267+
trans_items);
270268

271269
debug_dump(tcx, "INITIAL PARTITONING:", initial_partitioning.codegen_units.iter());
272270

@@ -304,8 +302,7 @@ struct PreInliningPartitioning<'tcx> {
304302
struct PostInliningPartitioning<'tcx>(Vec<CodegenUnit<'tcx>>);
305303

306304
fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
307-
trans_items: I,
308-
_reachable: &NodeSet)
305+
trans_items: I)
309306
-> PreInliningPartitioning<'tcx>
310307
where I: Iterator<Item = TransItem<'tcx>>
311308
{
@@ -344,6 +341,10 @@ fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
344341
// This is a non-generic functions, we always
345342
// make it visible externally on the chance that
346343
// it might be used in another codegen unit.
344+
// Later on base::internalize_symbols() will
345+
// assign "internal" linkage to those symbols
346+
// that are not referenced from other codegen
347+
// units (and are not publicly visible).
347348
llvm::ExternalLinkage
348349
} else {
349350
// In the current setup, generic functions cannot

src/librustc_trans/trans_item.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ impl<'a, 'tcx> TransItem<'tcx> {
251251

252252
/// True if the translation item should only be translated to LLVM IR if
253253
/// it is referenced somewhere (like inline functions, for example).
254-
pub fn is_instantiated_only_on_demand(&self, tcx: TyCtxt) -> bool {
254+
pub fn is_instantiated_only_on_demand(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool {
255+
if self.explicit_linkage(tcx).is_some() {
256+
return false;
257+
}
258+
255259
match *self {
256260
TransItem::Fn(ref instance) => {
257261
!instance.def.is_local() ||

0 commit comments

Comments
 (0)