Add VersionIndex::is_hidden() to check if a symbol should be visible for linking

Also, change VersionIndex methods to act on a reference so that they don't move/consume
the value when called.
This commit is contained in:
Christopher Cole 2022-10-28 13:57:47 -07:00
parent da3eaf169e
commit 899e6035f6
No known key found for this signature in database
GPG Key ID: 0AC856975983E9DB
2 changed files with 45 additions and 6 deletions

View File

@ -931,6 +931,10 @@ pub const DF_P1_GROUPPERM: i64 = 0x00000002;
pub const VER_NDX_LOCAL: u16 = 0;
/// Symbol is global
pub const VER_NDX_GLOBAL: u16 = 1;
/// .gnu.version index mask
pub const VER_NDX_VERSION: u16 = 0x7fff;
/// Symbol is hidden
pub const VER_NDX_HIDDEN: u16 = 0x8000;
// .gnu.version_d VerDef.vd_version reserved values
/// Only defined valid vd_version value

View File

@ -29,16 +29,20 @@ pub type VersionTable<'data> = ParsingTable<'data, VersionIndex>;
pub struct VersionIndex(pub u16);
impl VersionIndex {
pub fn index(self) -> u16 {
self.0
pub fn index(&self) -> u16 {
self.0 & gabi::VER_NDX_VERSION
}
pub fn is_local(self) -> bool {
self.0 == gabi::VER_NDX_LOCAL
pub fn is_local(&self) -> bool {
self.index() == gabi::VER_NDX_LOCAL
}
pub fn is_global(self) -> bool {
self.0 == gabi::VER_NDX_GLOBAL
pub fn is_global(&self) -> bool {
self.index() == gabi::VER_NDX_GLOBAL
}
pub fn is_hidden(&self) -> bool {
(self.0 & gabi::VER_NDX_HIDDEN) != 0
}
}
@ -1292,3 +1296,34 @@ mod parse_tests {
}
}
}
#[cfg(test)]
mod version_index_tests {
use super::*;
#[test]
fn is_local() {
let idx = VersionIndex(0);
assert!(idx.is_local());
}
#[test]
fn is_global() {
let idx = VersionIndex(1);
assert!(idx.is_global());
}
#[test]
fn index_visible() {
let idx = VersionIndex(42);
assert_eq!(idx.index(), 42);
assert!(!idx.is_hidden());
}
#[test]
fn index_hidden() {
let idx = VersionIndex(42 | gabi::VER_NDX_HIDDEN);
assert_eq!(idx.index(), 42);
assert!(idx.is_hidden());
}
}