2020-03-31 06:20:19 -05:00
|
|
|
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
|
2019-03-11 14:36:29 -05:00
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2020-08-28 05:10:48 -05:00
|
|
|
pub(crate) fn get_clif_linkage(
|
|
|
|
mono_item: MonoItem<'_>,
|
|
|
|
linkage: RLinkage,
|
|
|
|
visibility: Visibility,
|
2021-03-27 11:32:41 -05:00
|
|
|
is_compiler_builtins: bool,
|
2020-08-28 05:10:48 -05:00
|
|
|
) -> Linkage {
|
2019-03-11 14:36:29 -05:00
|
|
|
match (linkage, visibility) {
|
2021-03-27 11:32:41 -05:00
|
|
|
(RLinkage::External, Visibility::Default) if is_compiler_builtins => Linkage::Hidden,
|
2019-03-11 14:36:29 -05:00
|
|
|
(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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-16 14:20:12 -05:00
|
|
|
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),
|
|
|
|
}
|
2020-10-28 15:46:08 -05:00
|
|
|
} else if tcx.is_reachable_non_generic(def_id) {
|
|
|
|
Linkage::Export
|
2019-03-11 14:36:29 -05:00
|
|
|
} else {
|
2020-10-28 15:46:08 -05:00
|
|
|
Linkage::Hidden
|
2019-03-11 14:36:29 -05:00
|
|
|
}
|
|
|
|
}
|