← Back to issue list

elf: pyelftools to parse ELF files rather than readelf

View original Github issue

Metadata

Project
snapcraft
Number
#1913
Type
pull request
State
merged
Author
jhenstridge
Labels
—
Created
Updated
Closed

Current evaluation

Merged PR #1913 (commit 9e4e88629): snapcraft.internal.elf.ElfFile now parses ELF files with pyelftools instead of shelling out to readelf, handling weak refs outside DT_NEEDED; cut test build times roughly in half.

Resolution: closed resolved

Reason: The PR was approved and merged to main as commit 9e4e88629 ("elf: pyelftools to parse ELF files rather than readelf (#1913)"), which replaced readelf output parsing in snapcraft/internal/elf.py and added pyelftools as a build/snap dependency. A review-found regression with libpthread in .gnu.version_r but absent from DT_NEEDED was resolved by ignoring versions for libraries not in DT_NEEDED, and pyelftools remains a snapcraft dependency in the current tree.

Evaluated by: mr-cal-bot

No scores available.

Issue body

Update the `snapcraft.internal.elf.ElfFile` class to use pyelftools instead of shelling out to readelf. This is faster, and doesn't rely on parsing the output of a utility that is intended for humans.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Merged PR #1913 (commit 9e4e88629): snapcraft.internal.elf.ElfFile now parses ELF files with pyelftools instead of shelling out to readelf, handling weak refs outside DT_NEEDED; cut test build times roughly in half.
stealth/space-bunny-alpha — closed resolved PR #1913 merged as commit 9e4e88629: snapcraft.internal.elf.ElfFile now parses ELF files with pyelftools instead of shelling out to readelf, cutting ELF processing time roughly in half and dropping the readelf output parsing.
stealth/space-bunny-alpha — closed resolved Merged PR #1913 (commit 9e4e88629), replacing readelf subprocesses with pyelftools for ELF parsing; testing resolved a weak-reference parsing edge case.
qwen/qwen3.6-35b-a3b — — Merged replacing readelf with pyelftools for ELF parsing, cutting runtime by over half and removing shell-out dependencies. Resolved a weak reference edge case by ignoring versions for libraries not in DT_NEEDED. Updated build dependencies.
qwen3.6-35b-a3b-mtp-q6 — — Merged. Swapped readelf for pyelftools, halving execution time. Fixed weak symbol handling by ignoring versions for libraries not in DT_NEEDED. Added pyelftools to dependencies.

Update history

No update history recorded yet.

Related work

  • Related To: snapcraft#1989 (confidence 55%)

    Follow-up optimization 'elf: don't parse elf more than necessary' builds on the ElfFile rework introduced here.

  • Related To: snapcraft#1902 (confidence 45%)

    Prior commit 'many: use in-snap unsquashfs and readelf if running from snap' set up the readelf-based approach this PR replaced.

Related issues

Issue Project State Summary Similarity
#2663 elf: handle invalid elf files snapcraft merged PR #2663 merged as commit 89490853e: snapcraft/elf/elf_utils.py now catches elftools ELFError (and CorruptedElfFile) during dependency scanning and silently skips invalid ELF files, with a regression test for LP #1838098.
73%
#3841 elf: add elf file patcher snapcraft merged Merged PR #3841 in commit e03a971b3, adding a patchelf-based ELF file patcher ported from Snapcraft 6.x for CRAFT-1191.
73%
#3839 elf: add elf file handler class snapcraft merged PR #3839 was merged into main as commit 6830dc69c, porting the Snapcraft 6.x ElfFile handler into snapcraft/elf/_elf_file.py with helpers, ELF errors, and unit tests (CRAFT-1192).
72%
#3111 elf: fix parsing of notes after patchelf mangling snapcraft merged Merged in snapcraft#3111 by parsing ELF notes from sections instead of the note segment, handling binaries mangled by patchelf.
71%
#1854458 snapcraft comes with an old version of pyelftools, some builds fail due to this snapcraft (launchpad) closed Fixed ELF prime-time crashes from non-ASCII section names in snapcore/snapcraft#2830; maintainers confirmed the fix shipped as part of Snapcraft 3.10.
71%
#1744 elf: conversion from libraries snapcraft merged Merged as ec7ba948a: converted snapcraft/internal/libraries.py into ELF-focused elf.py with type hints and mypy fixes, fixing #1666. Reviewer syntax/lint concerns were handled by follow-up PR #1745 (flake8 upgrade).
70%
#72 Refactor ELF file handling debcraft closed ELF handling was rewritten for Debcraft’s .deb workflow in merged PR #75 (commit c841273), replacing Snapcraft-derived code with shared-library dependency support; symbol handling was deferred.
70%