Skip to content

Commit 3aa8814

Browse files
Ignore hidden symbols from shared objects
Issue #604
1 parent e3422aa commit 3aa8814

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

libwild/src/elf.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,7 @@ pub(crate) fn slice_from_all_bytes_mut<T: object::Pod>(data: &mut [u8]) -> &mut
513513
.unwrap()
514514
.0
515515
}
516+
517+
pub(crate) fn is_hidden_symbol(symbol: &crate::elf::Symbol) -> bool {
518+
symbol.st_visibility() == object::elf::STV_HIDDEN
519+
}

libwild/src/resolution.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,12 @@ fn resolve_symbol<'data>(
883883
is_from_shared_object: bool,
884884
) -> Result {
885885
// Don't try to resolve symbols that are already defined, e.g. locals and globals that we
886-
// define. Also don't try to resolve symbol zero - the undefined symbol.
887-
if !definition_out.is_undefined() || local_symbol_index.0 == 0 {
886+
// define. Also don't try to resolve symbol zero - the undefined symbol. Hidden symbols exported
887+
// from shared objects don't make sense, so we skip resolving them as well.
888+
if !definition_out.is_undefined()
889+
|| local_symbol_index.0 == 0
890+
|| (is_from_shared_object && crate::elf::is_hidden_symbol(local_symbol))
891+
{
888892
return Ok(());
889893
}
890894

libwild/src/symbol_db.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,10 +932,12 @@ trait SymbolLoader<'data> {
932932
for symbol in self.object().symbols.iter() {
933933
let symbol_id = symbols_out.next;
934934
let mut value_flags = self.compute_value_flags(symbol);
935-
if symbol.is_undefined(e) {
935+
936+
if symbol.is_undefined(e) || self.should_ignore_symbol(symbol) {
936937
symbols_out.set_next(value_flags, SymbolId::undefined(), file_id);
937938
continue;
938939
}
940+
939941
let resolution = symbol_id;
940942

941943
let local_index = symbol_id.offset_from(base_symbol_id);
@@ -983,6 +985,11 @@ trait SymbolLoader<'data> {
983985
false
984986
}
985987

988+
/// Returns whether the supplied symbol should be ignore.
989+
fn should_ignore_symbol(&self, _symbol: &crate::elf::Symbol) -> bool {
990+
false
991+
}
992+
986993
fn get_symbol_name_and_version(
987994
&self,
988995
symbol: &crate::elf::Symbol,
@@ -1141,6 +1148,11 @@ impl<'data> SymbolLoader<'data> for DynamicObjectSymbolLoader<'_, 'data> {
11411148
fn object(&self) -> &crate::elf::File<'data> {
11421149
self.object
11431150
}
1151+
1152+
fn should_ignore_symbol(&self, symbol: &crate::elf::Symbol) -> bool {
1153+
// Shared objects shouldn't export hidden symbols. If for some reason they do, ignore them.
1154+
crate::elf::is_hidden_symbol(symbol)
1155+
}
11441156
}
11451157

11461158
#[derive(Clone, Copy)]

0 commit comments

Comments
 (0)