rust/src/linkage.rs

32 lines
1.1 KiB
Rust
Raw Normal View History

use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
2019-03-11 14:36:29 -05:00
use crate::prelude::*;
pub(crate) fn get_clif_linkage(mono_item: MonoItem<'_>, linkage: RLinkage, visibility: Visibility) -> Linkage {
2019-03-11 14:36:29 -05:00
match (linkage, visibility) {
(RLinkage::External, Visibility::Default) => Linkage::Export,
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
2020-03-19 06:09:21 -05:00
(RLinkage::External, Visibility::Hidden) => Linkage::Hidden,
2019-03-11 14:36:29 -05:00
_ => panic!("{:?} = {:?} {:?}", mono_item, linkage, visibility),
}
}
pub(crate) fn get_static_linkage(tcx: TyCtxt<'_>, def_id: DefId) -> Linkage {
2019-03-11 14:36:29 -05:00
let fn_attrs = tcx.codegen_fn_attrs(def_id);
if let Some(linkage) = fn_attrs.linkage {
match linkage {
RLinkage::External => Linkage::Export,
RLinkage::Internal => Linkage::Local,
RLinkage::ExternalWeak | RLinkage::WeakAny => Linkage::Preemptible,
_ => panic!("{:?}", linkage),
}
} else {
if tcx.is_reachable_non_generic(def_id) {
Linkage::Export
} else {
Linkage::Hidden
}
2019-03-11 14:36:29 -05:00
}
}