]>
Commit | Line | Data |
---|---|---|
532ac7d7 | 1 | use crate::ty::subst::SubstsRef; |
dfeec247 XL |
2 | use crate::ty::{self, Ty, TyCtxt}; |
3 | use rustc_hir::def_id::{DefId, LOCAL_CRATE}; | |
4 | use rustc_macros::HashStable; | |
0531ce1d | 5 | |
ea8adc8c XL |
6 | /// The SymbolExportLevel of a symbols specifies from which kinds of crates |
7 | /// the symbol will be exported. `C` symbols will be exported from any | |
8 | /// kind of crate, including cdylibs which export very few things. | |
9 | /// `Rust` will only be exported if the crate produced is a Rust | |
10 | /// dylib. | |
3dfed10e | 11 | #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] |
ea8adc8c XL |
12 | pub enum SymbolExportLevel { |
13 | C, | |
14 | Rust, | |
15 | } | |
16 | ||
ea8adc8c XL |
17 | impl SymbolExportLevel { |
18 | pub fn is_below_threshold(self, threshold: SymbolExportLevel) -> bool { | |
0bf4aa26 XL |
19 | threshold == SymbolExportLevel::Rust // export everything from Rust dylibs |
20 | || self == SymbolExportLevel::C | |
ea8adc8c XL |
21 | } |
22 | } | |
0531ce1d | 23 | |
04454e1e FG |
24 | /// Kind of exported symbols. |
25 | #[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)] | |
26 | pub enum SymbolExportKind { | |
27 | Text, | |
28 | Data, | |
29 | Tls, | |
30 | } | |
31 | ||
32 | /// The `SymbolExportInfo` of a symbols specifies symbol-related information | |
33 | /// that is relevant to code generation and linking. | |
34 | #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] | |
35 | pub struct SymbolExportInfo { | |
36 | pub level: SymbolExportLevel, | |
37 | pub kind: SymbolExportKind, | |
38 | pub used: bool, | |
39 | } | |
40 | ||
3dfed10e | 41 | #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] |
83c7162d | 42 | pub enum ExportedSymbol<'tcx> { |
0531ce1d | 43 | NonGeneric(DefId), |
532ac7d7 | 44 | Generic(DefId, SubstsRef<'tcx>), |
dfeec247 | 45 | DropGlue(Ty<'tcx>), |
353b0b11 | 46 | ThreadLocalShim(DefId), |
3dfed10e | 47 | NoDefId(ty::SymbolName<'tcx>), |
0531ce1d XL |
48 | } |
49 | ||
83c7162d | 50 | impl<'tcx> ExportedSymbol<'tcx> { |
dfeec247 XL |
51 | /// This is the symbol name of an instance if it is instantiated in the |
52 | /// local crate. | |
3dfed10e | 53 | pub fn symbol_name_for_local_instance(&self, tcx: TyCtxt<'tcx>) -> ty::SymbolName<'tcx> { |
0531ce1d | 54 | match *self { |
dfeec247 | 55 | ExportedSymbol::NonGeneric(def_id) => tcx.symbol_name(ty::Instance::mono(tcx, def_id)), |
83c7162d XL |
56 | ExportedSymbol::Generic(def_id, substs) => { |
57 | tcx.symbol_name(ty::Instance::new(def_id, substs)) | |
58 | } | |
dfeec247 XL |
59 | ExportedSymbol::DropGlue(ty) => { |
60 | tcx.symbol_name(ty::Instance::resolve_drop_in_place(tcx, ty)) | |
0531ce1d | 61 | } |
353b0b11 FG |
62 | ExportedSymbol::ThreadLocalShim(def_id) => tcx.symbol_name(ty::Instance { |
63 | def: ty::InstanceDef::ThreadLocalShim(def_id), | |
64 | substs: ty::InternalSubsts::empty(), | |
65 | }), | |
dfeec247 | 66 | ExportedSymbol::NoDefId(symbol_name) => symbol_name, |
0531ce1d XL |
67 | } |
68 | } | |
69 | } | |
70 | ||
dc9dc135 | 71 | pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String { |
dfeec247 | 72 | format!( |
136023e0 | 73 | "rust_metadata_{}_{:08x}", |
17df50a5 | 74 | tcx.crate_name(LOCAL_CRATE), |
49aad941 | 75 | tcx.sess.local_stable_crate_id(), |
dfeec247 | 76 | ) |
83c7162d | 77 | } |