Skip to content

Commit

Permalink
refactor: add elfutils.get_undefined_symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Sep 14, 2021
1 parent 195681a commit 8a03a19
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions auditwheel/elfutils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from os.path import basename, realpath, relpath
from typing import Dict, Iterator, List, Optional, Tuple
from typing import Dict, Iterator, List, Optional, Set, Tuple

from elftools.common.exceptions import ELFError
from elftools.elf.elffile import ELFFile
Expand Down Expand Up @@ -139,12 +139,8 @@ def is_subdir(path: str, directory: str) -> bool:
return True


def filter_undefined_symbols(
path: str, symbols: Dict[str, List[str]]
) -> Dict[str, List[str]]:
if not symbols:
return {}
undef_symbols = set("*")
def get_undefined_symbols(path: str) -> Set[str]:
undef_symbols = set()
with open(path, "rb") as f:
elf = ELFFile(f)
section = elf.get_section_by_name(".dynsym")
Expand All @@ -153,11 +149,18 @@ def filter_undefined_symbols(
for sym in section.iter_symbols():
if sym["st_shndx"] == "SHN_UNDEF":
undef_symbols.add(sym.name)
return undef_symbols


def filter_undefined_symbols(
path: str, symbols: Dict[str, List[str]]
) -> Dict[str, List[str]]:
if not symbols:
return {}
undef_symbols = set("*") | get_undefined_symbols(path)
result = {}
for lib, sym_list in symbols.items():
intersection = set(sym_list) & undef_symbols
if intersection:
result[lib] = sorted(intersection)

return result

0 comments on commit 8a03a19

Please sign in to comment.