← Back to issue list

patch fewer elf files

View original Launchpad issue

Metadata

Project
snapcraft (launchpad)
Number
#1747097
Type
issue
State
open
Author
~jamesh
Labels
Created
Updated
Closed

Current evaluation

Optimization proposal to reduce patchelf usage on ELF files in classic snaps by only patching executables and dlopen targets via DT_SONAME/DT_NEEDED analysis. Open since 2017 with zero comments, labels, or maintainer interaction.

Suggested action: needs triage

Reason: No labels, no comments, no assignee, and zero maintainer interaction over 8+ years. The underlying ELF patching mechanism still exists in the codebase (DT_SONAME and DT_NEEDED are still referenced in snapcraft/elf/), so the optimization idea remains technically valid but has never been assessed, labelled, or prioritized by a maintainer.

Impact: 35 Quick Win: 14.0 Staleness: 95 Complexity: 60 Confidence: 75 Support Request: 10

Issue body

This bug is recording an idea that came up during the Snapcraft Summit but we didn't have time to implement. At the moment, Snapcraft runs patchelf on every ELF file in classic snaps in order to alter DT_RPATH. It would be nice to patch fewer files because it can inflate the size of the executables, and takes time to perform. According to this article: http://blog.qt.io/blog/2011/10/28/rpath-and-runpath/ ... the search order for loading libraries is: Unless loading object has RUNPATH: RPATH of the loading object, then the RPATH of its loader (unless it has a RUNPATH), ..., until the end of the chain, which is either the executable or an object loaded by dlopen Unless executable has RUNPATH: RPATH of the executable LD_LIBRARY_PATH RUNPATH of the loading object ld.so.cache default dirs So we only need to make sure executables and objects opened with dlopen have DT_RPATH set: any libraries loaded by those executables will inherit their RPATH(s). That begs the question of how to identify these files. The following algorithm should be a good approximation of this: 1. identify the set of all ELF files in the snap. 2. for each ELF file in the set, extract DT_SONAME and all libs listed in DT_NEEDED 3. create a set of all libraries included in some ELF file's DT_NEEDED 4. remove any ELF file from the first set whose DT_SONAME appears in the DT_NEEDED set 5. the remaining ELF files need patching It isn't particularly bad if this algorithm identifies false positives: it would just result in more patching. A false negative would be a library that is loaded by the dynamic linker normally in one place, and via dlopen elsewhere. And that is only a problem if the dlopen() occurs in an executable that hasn't already loaded the library.

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.8-27b
Impact: 35
Quick Win: 14.0
Staleness: 95
Complexity: 60
Confidence: 75
Support Request: 10
needs triage Optimization proposal to reduce patchelf usage on ELF files in classic snaps by only patching executables and dlopen targets via DT_SONAME/DT_NEEDED analysis. Open since 2017 with zero comments, labels, or maintainer interaction.
qwen/qwen3.6-35b-a3b
Staleness: 95
Complexity: 45
Confidence: 90
Support Request: 10
close stale Optimization idea to reduce patchelf usage on ELF files in classic snaps by only patching executables and dlopen targets. Unaddressed for over eight years with no maintainer interaction.
qwen/qwen3.6-35b-a3b
Staleness: 98
Complexity: 65
Confidence: 90
Support Request: 10
close stale Unimplemented optimization proposal to reduce patchelf usage on ELF files in classic snaps. No maintainer engagement or activity for over eight years.
qwen3.6-35b-a3b-mtp-q6
Staleness: 95
Complexity: 40
Confidence: 90
Support Request: 10
close stale Proposal to optimize Snapcraft by patching only specific ELF files instead of all of them to reduce executable size and build time. Unaddressed for over 8 years with no maintainer feedback.
qwen3.6-35b-moe-q4
Staleness: 98
Complexity: 55
Confidence: 90
Support Request: 5
close stale Proposal to optimize Snapcraft ELF patching by only targeting executables and dlopen targets to reduce build time and binary size. Untriaged, inactive for over 8 years.

Update history

No update history recorded yet.

Related work

  • Related To: snapcraft (launchpad)#2045895 (confidence 40%)

    Both deal with patchelf/rpath handling in snap builds, but 2045895 reports a missing snap libdir rpath bug rather than an optimization to reduce the number of patched files.

Related issues

Issue Project State Summary Similarity
#1959 elf: only patch elf files that aren't referenced by DT_NEEDED snapcraft merged Merged after conflict resolution. Optimizes patchelf usage by only patching ELF files not listed in DT_NEEDED dependencies, reducing unnecessary modifications. Adds architecture extraction to ElfFile to prevent cross-architecture mismatches. Resolves LP #1747097.
75%
#3985 elf: patch elf files for classic mode snapcraft merged Merged into main. Patches ELF binaries for classic mode to use the base snap interpreter and libraries, or bundled components if libc is staged, when enable-patchelf is enabled. Approved, passed CI, and merged.
74%
#2006 many: use packaging logic to get patchelf snapcraft merged Merged following reviewer approval and CI checks. Refactored patchelf retrieval to use shared packaging logic, aligning its version across snap and deb packages. Modified four files with a net reduction of 24 lines.
71%
#3841 elf: add elf file patcher snapcraft merged Merged an ELF file patcher using patchelf, ported from Snapcraft 6.x. Approved by one reviewer, passed CI checks, and increased test coverage by 0.26%. Resolves CRAFT-1191.
71%