diff --git a/snapcraft/internal/elf.py b/snapcraft/internal/elf.py index 98de6ba89a..b3bdb51473 100644 --- a/snapcraft/internal/elf.py +++ b/snapcraft/internal/elf.py @@ -298,8 +298,10 @@ def __init__(self, *, path: str) -> None: self.elf_type: str = "ET_NONE" try: + logger.debug("Extracting ELF attributes:", path) self._extract_attributes() except (UnicodeDecodeError, AttributeError, ConstructError) as exception: + logger.debug("Extracting ELF attributes exception: ", str(exception)) raise errors.CorruptedElfFileError(path, exception) def _extract_attributes(self) -> None: # noqa: C901 @@ -335,10 +337,15 @@ def _extract_attributes(self) -> None: # noqa: C901 self.execstack_set = True elif isinstance(segment, elftools.elf.segments.InterpSegment): self.interp = segment.get_interp_name() - elif isinstance(segment, elftools.elf.segments.NoteSegment): - for note in segment.iter_notes(): - if note.n_name == "GNU" and note.n_type == "NT_GNU_BUILD_ID": - self.build_id = _ensure_str(note.n_desc) + + build_id_section = elf.get_section_by_name(".note.gnu.build-id") + if ( + isinstance(build_id_section, elftools.elf.sections.NoteSection) + and build_id_section.header["sh_type"] != "SHT_NOBITS" + ): + for note in build_id_section.iter_notes(): + if note.n_name == "GNU" and note.n_type == "NT_GNU_BUILD_ID": + self.build_id = _ensure_str(note.n_desc) # If we are processing a detached debug info file, these # sections will be present but empty.