← 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

Classic ELF patching still iterates every discovered file; DT_NEEDED/DT_SONAME filtering from PR #1959 was merged and then reverted, leaving the optimization open pending safer dlopen handling.

Suggested action: keep open

Reason: The issue provides a concrete filtering algorithm, and PR #1959 implemented it, but the later comment links commit 77770452be681b5b3703eba61b654c0ce2ef7664, which reverted that implementation. Current lifecycle code still enumerates all ELF files and invokes the patcher for each, while dlopen-related false negatives remain the unresolved safety concern.

Evaluated by: mr-cal-bot

Impact: 35 Quick Win: 11 Complexity: 58 Confidence: 88 Actionability: 72

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
stealth/space-bunny-alpha
Impact: 35
Quick Win: 11
Complexity: 58
Confidence: 88
Actionability: 72
keep open Classic ELF patching still iterates every discovered file; DT_NEEDED/DT_SONAME filtering from PR #1959 was merged and then reverted, leaving the optimization open pending safer dlopen handling.
stealth/space-bunny-alpha
Impact: 46
Quick Win: 10
Complexity: 66
Confidence: 93
Actionability: 67
keep open Classic snaps still patch every dynamic ELF; DT_NEEDED/DT_SONAME filtering from #1959 was reverted by #2081, leaving this optimization open pending safer dlopen handling.
qwen/qwen3.6-35b-a3b
Impact: 30
Quick Win: 14
Complexity: 40
Confidence: 60
Actionability: 80
needs triage Feature request to optimize patchelf usage by only patching ELF files that need DT_RPATH set, based on DT_SONAME and DT_NEEDED analysis. Untriaged, no maintainer response in 8.5 years.
qwen/qwen3.8-27b
Impact: 35
Quick Win: 14
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.

Update history

Date Change
created

Related work

  • Related To: snapcraft#1959 (confidence 100%)

    PR #1959 implemented DT_NEEDED/DT_SONAME-based filtering, but the implementation was subsequently reverted.

Related issues

Issue Project State Summary Similarity
#1959 elf: only patch elf files that aren't referenced by DT_NEEDED snapcraft merged Merged as 64f78f762, adding architecture-aware DT_NEEDED filtering to reduce patchelf usage; PR #2081 later partially reverted it and restored patching every ELF file.
84%
#3985 elf: patch elf files for classic mode snapcraft merged Merged PR #3985 as commit a723254b9, adding classic-mode ELF patching so enable-patchelf parts use base-snap libraries or staged libc components.
74%
#1666 Refactor to support elf patching snapcraft closed ELF patching support was refactored by merged PR #1744 in commit ec7ba948a, converting the ELF implementation into reusable libraries.
73%
#2081 elf: patch everything instead of a subset of elf files snapcraft merged Merged PR #2081 restored Snapcraft 2.39 behavior by patching every ELF file; commit 77770452b partially reverted 64f78f762a05.
71%