← Back to issue list

elf: only patch elf files that aren't referenced by DT_NEEDED

View original Github issue

Metadata

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

Current evaluation

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.

Suggested action:

No scores available.

Issue body

- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)? - [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)? - [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)? - [x] Have you successfully run `./runtests.sh static`? - [x] Have you successfully run `./runtests.sh unit`? ----- This probably needs a bit more testing, but I thought I'd push the PR now to get some CI feedback. This is based on an idea I mentioned at the Snapcraft Summit to minimise the number of files we run patchelf on, as described in [bug 1747097](https://bugs.launchpad.net/snapcraft/+bug/1747097). In brief, when the dynamic linker is searching for DT_NEEDED dependencies of a library, it can use the rpath of the executable or library that pulled in the library. So for classic snaps, it should only be necessary to patch the rpath of executables or shared library plugins. As a simple heuristic, any elf file whose soname is listed in the DT_NEEDED of some other elf file doesn't need patching. I also updated ElfFile to extract architecture information from elf files. This way we don't e.g. treat an ARM library as satisfying a dependency of an AMD64 executable. LP: #1747097

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b 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.
qwen3.6-35b-a3b-mtp-q6 Merged. Optimizes patchelf usage by skipping ELF files referenced in DT_NEEDED dependencies and adds architecture extraction to ElfFile. Conflicts were resolved by @kyrofa before final approval and merge, addressing LP #1747097.
qwen3.6-35b-a3b-mtp-q6 Merged. Optimizes patchelf to only patch ELF files not referenced by DT_NEEDED, adding architecture extraction to ElfFile. Conflicts were resolved by @kyrofa before final merge.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#1747097 patch fewer elf files snapcraft (launchpad) open 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.
75%
#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.
74%
#1873 elf: cleaner patchelf experience snapcraft merged Merged improvements to patchelf handling. The change uses the system patchelf by default, copies files to prevent hard-link conflicts, and provides fallback instructions. Approved by two reviewers and passed CI checks before merging.
74%
#1798 elf: strip the .note.go.buildid to make room for patching elf snapcraft merged Merged. Strips the .note.go.buildid section from ELF binaries to resolve patchelf compatibility issues and fix build failures. Approved after passing CI checks. Introduces a newer patchelf build-snap dependency to ensure correct header patching.
71%
#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.
71%