From 3ec14474f8687ed85f538e0976ed4e262e2a3351 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 16 Jul 2024 18:39:02 -0400 Subject: [PATCH] _object: handle STB_GNU_UNIQUE (#99) Signed-off-by: William Woodruff --- abi3audit/_object.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/abi3audit/_object.py b/abi3audit/_object.py index 88356d5..3441372 100644 --- a/abi3audit/_object.py +++ b/abi3audit/_object.py @@ -73,11 +73,28 @@ class _So(_SharedObjectBase): An ELF-formatted shared object. """ + def __init__(self, extractor: extract.SharedObjectExtractor): + super().__init__(extractor) + + with self._extractor.path.open(mode="rb") as io, ELFFile(io) as elf: + # HACK: If the ELF contains a comment section, look for an indicator + # that the binary was produced by GCC. If so, we treat STB_LOOS + # as STB_GNU_UNIQUE, i.e. another kind of local symbol linkage. + comment = elf.get_section_by_name(".comment") + if comment is None: + logger.debug(f"{self._extractor.path} has no .comment") + self._loos_is_gnu_unique = False + else: + self._loos_is_gnu_unique = b"GCC" in comment.data() + logger.debug(f"{self._extractor.path} has .comment, {self._loos_is_gnu_unique=}") + def __iter__(self) -> Iterator[Symbol]: def get_visibility(_sym: Any) -> Visibility | None: elfviz: str = _sym.entry.st_info.bind if elfviz == "STB_LOCAL": return "local" + elif elfviz == "STB_LOOS" and self._loos_is_gnu_unique: + return "local" elif elfviz == "STB_GLOBAL": return "global" elif elfviz == "STB_WEAK":