Merge pull request #1327 from bjorn3/linkage_hidden

Add support for hidden visibility
This commit is contained in:
Pat Hickey
2020-03-17 11:34:41 -07:00
committed by GitHub
3 changed files with 27 additions and 8 deletions

View File

@@ -383,8 +383,9 @@ fn translate_function_linkage(linkage: Linkage) -> faerie::Decl {
match linkage {
Linkage::Import => faerie::Decl::function_import().into(),
Linkage::Local => faerie::Decl::function().into(),
Linkage::Export => faerie::Decl::function().global().into(),
Linkage::Preemptible => faerie::Decl::function().weak().into(),
Linkage::Hidden => faerie::Decl::function().global().hidden().into(),
Linkage::Export => faerie::Decl::function().global().into(),
}
}
@@ -396,13 +397,19 @@ fn translate_data_linkage(linkage: Linkage, writable: bool, align: Option<u8>) -
.with_writable(writable)
.with_align(align)
.into(),
Linkage::Export => faerie::Decl::data()
.global()
Linkage::Preemptible => faerie::Decl::data()
.weak()
.with_writable(writable)
.with_align(align)
.into(),
Linkage::Preemptible => faerie::Decl::data()
.weak()
Linkage::Hidden => faerie::Decl::data()
.global()
.hidden()
.with_writable(writable)
.with_align(align)
.into(),
Linkage::Export => faerie::Decl::data()
.global()
.with_writable(writable)
.with_align(align)
.into(),

View File

@@ -58,6 +58,11 @@ pub enum Linkage {
Local,
/// Defined inside the module, visible outside it, and may be preempted.
Preemptible,
/// Defined inside the module, visible inside the current static linkage unit, but not outside.
///
/// A static linkage unit is the combination of all object files passed to a linker to create
/// an executable or dynamic library.
Hidden,
/// Defined inside the module, and visible outside it.
Export,
}
@@ -66,14 +71,20 @@ impl Linkage {
fn merge(a: Self, b: Self) -> Self {
match a {
Self::Export => Self::Export,
Self::Hidden => match b {
Self::Export => Self::Export,
Self::Preemptible => Self::Preemptible,
_ => Self::Hidden,
},
Self::Preemptible => match b {
Self::Export => Self::Export,
_ => Self::Preemptible,
},
Self::Local => match b {
Self::Export => Self::Export,
Self::Hidden => Self::Hidden,
Self::Preemptible => Self::Preemptible,
_ => Self::Local,
Self::Local | Self::Import => Self::Local,
},
Self::Import => b,
}
@@ -83,7 +94,7 @@ impl Linkage {
pub fn is_definable(self) -> bool {
match self {
Self::Import => false,
Self::Local | Self::Preemptible | Self::Export => true,
Self::Local | Self::Preemptible | Self::Hidden | Self::Export => true,
}
}
@@ -91,7 +102,7 @@ impl Linkage {
pub fn is_final(self) -> bool {
match self {
Self::Import | Self::Preemptible => false,
Self::Local | Self::Export => true,
Self::Local | Self::Hidden | Self::Export => true,
}
}
}

View File

@@ -474,6 +474,7 @@ fn translate_linkage(linkage: Linkage) -> (SymbolScope, bool) {
let scope = match linkage {
Linkage::Import => SymbolScope::Unknown,
Linkage::Local => SymbolScope::Compilation,
Linkage::Hidden => SymbolScope::Linkage,
Linkage::Export | Linkage::Preemptible => SymbolScope::Dynamic,
};
// TODO: this matches rustc_codegen_cranelift, but may be wrong.