From fe046c1865d92957c4d26c0057b600f10747709a Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Thu, 6 Oct 2022 11:50:47 -0400 Subject: [PATCH] _object: filter non-external symbols in dylibs Signed-off-by: William Woodruff --- abi3audit/_object.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/abi3audit/_object.py b/abi3audit/_object.py index 56f66b7..4339a71 100644 --- a/abi3audit/_object.py +++ b/abi3audit/_object.py @@ -152,17 +152,13 @@ def __iter__(self) -> Iterator[Symbol]: raise SharedObjectError("shared object has no symbol table") for symbol in symtab_cmd.symbols: - # TODO(ww): Do a better job of filtering here. - # The Mach-O symbol table includes all kinds of junk, including - # symbolic entries for debuggers. We should exclude all of - # these non-function/data entries, as well as any symbols - # that isn't marked as external (since we're linking against - # the Python interpreter for the ABI). - if (name := symbol.name) is None: + # We only care about symbols that have the external bit set, + # since these are the ones resolved when linking to CPython. + if not symbol.type & 0x01: continue # All symbols on macOS are prefixed with _; remove it. - yield Symbol(name[1:]) + yield Symbol(symbol.name[1:]) class _Dll(_SharedObjectBase):