Skip to content

Commit

Permalink
Fix missing relationship between Mach-O's symbol & libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Sep 21, 2024
1 parent 77c633c commit 388fc5e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/MachO/BinaryParser.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -2718,12 +2718,16 @@ ok_error_t BinaryParser::do_fixup(DYLD_CHAINED_FORMAT fmt, int32_t ord, const st
if (symbol != nullptr) {
binding_info->symbol_ = symbol;
symbol->binding_info_ = binding_info.get();
if (symbol->library_ordinal() == ord) {
symbol->library_ = binding_info->library_;
}
} else {
LIEF_INFO("New symbol discovered: {}", symbol_name);
auto symbol = std::make_unique<Symbol>();
symbol->type_ = 0;
symbol->numberof_sections_ = 0;
symbol->description_ = 0;
symbol->library_ = binding_info->library_;
symbol->name(symbol_name);

binding_info->symbol_ = symbol.get();
Expand Down
23 changes: 23 additions & 0 deletions tests/macho/test_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ def test_dynsym_command():

assert indirect_symbols[3].name == "_printf"

def test_symbol_library():
macho = lief.MachO.parse(get_sample("MachO/macho-arm64-osx-vtable-chained-fixups.bin")).at(0)
symbols = macho.symbols
assert len(symbols) == 16

bindings = list(macho.bindings)
assert len(bindings) == 3

assert bindings[0].symbol.name == "_printf"
assert bindings[0].symbol.is_external
assert bindings[0].symbol.library.name == "/usr/lib/libSystem.B.dylib"
assert bindings[0].symbol.library_ordinal == 2

assert bindings[1].symbol.is_external
assert bindings[1].symbol.name == "__ZTVN10__cxxabiv117__class_type_infoE"
assert bindings[1].symbol.library.name == "/usr/lib/libc++.1.dylib"
assert bindings[1].symbol.library_ordinal == 1

assert bindings[2].symbol.is_external
assert bindings[2].symbol.name == "__ZTVN10__cxxabiv120__si_class_type_infoE"
assert bindings[2].symbol.library.name == "/usr/lib/libc++.1.dylib"
assert bindings[2].symbol.library_ordinal == 1

@pytest.mark.skipif(not lief.__extended__, reason="needs LIEF extended")
def test_demangling():
macho = lief.MachO.parse(get_sample("MachO/FAT_MachO_x86_x86-64_library_libc++abi.dylib")).at(0)
Expand Down

0 comments on commit 388fc5e

Please sign in to comment.