Skip to content

Commit

Permalink
_object: handle STB_GNU_UNIQUE (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <william@trailofbits.com>
  • Loading branch information
woodruffw authored Jul 16, 2024
1 parent 2e8106b commit 3ec1447
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions abi3audit/_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 3ec1447

Please sign in to comment.