elf: fix parsing of notes after patchelf mangling
Metadata
Current evaluation
Merged in snapcraft#3111 by parsing ELF notes from sections instead of the note segment, handling binaries mangled by patchelf.
Resolution: closed resolved
Reason: Merged PR #3111 replaced unreliable note-segment iteration with per-section parsing after patchelf relocation and added developer logs for ELF parsing.
Evaluated by: mr-cal-bot
No scores available.
Issue body
We cannot rely on iterating on the notes via the note segment.
Patchelf may move note sections into other segments, and worse
yet, possibly leave the note segment standing with invalid data.
Here we instead iterate over each section and (more) reliably
gather the note information.
There is some improvement that should be done on the patchelf
side, as `readelf` complains on these binaries, and other issues
have surfaced in the past (e.g. mesa in classic snaps). However,
this will hopefully address snapcraft build-time issues with not
only our patched files for classic snaps, but externally patched
binaries that are being packaged.
Add a couple of developer logs to indicate when we are parsing
an ELF, so future investigations are easier when something explodes.
Signed-off-by: Chris Patterson <chris.patterson@canonical.com>
- [ ] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [ ] Have you successfully run `./runtests.sh static`?
- [ ] Have you successfully run `./runtests.sh tests/unit`?
-----
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged in snapcraft#3111 by parsing ELF notes from sections instead of the note segment, handling binaries mangled by patchelf. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged fix for ELF note parsing after patchelf mangling by iterating over sections instead of the note segment; addresses SNAPCRAFT-1K4 and SNAPCRAFT-1ET. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #3111 (3247432e4), switching ELF note discovery from the note segment to sections so notes remain readable after patchelf moves or invalidates segments. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged fix for ELF note parsing after patchelf modifications. Iterates over sections instead of the note segment to reliably extract note data, resolving snapcraft build-time failures with patched binaries. Fixes SNAPCRAFT-1K4 and SNAPCRAFT-1ET. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for ELF note parsing after patchelf modifications. Iterates over sections instead of the note segment to reliably extract data. Resolves snapcraft build-time failures with patched binaries and adds debug logging. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #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. | |
| #1798 elf: strip the .note.go.buildid to make room for patching elf | snapcraft | merged | Merged #1798 in fa8b7b174, stripping Go ELF .note.go.buildid sections before patching and requiring newer patchelf header-layout support. | |
| #3840 elf: add handling and patching helpers | snapcraft | merged | Merged in snapcore/snapcraft#3840 via commit 8a9914510, adding helpers to enumerate ELF binaries and locate architecture-specific dynamic linkers. | |
| #3589 snap: correct patch apply for patchelf | snapcraft | merged | Merged PR #3589 fixed PatchELF patch application in the snap build via commit d9484faf9 (merge a636d26b5). | |
| #3277 pluginhandler: support using patchelf on strict snaps | snapcraft | merged | Merged PR #3277 as fd8e95c3d, adding per-part enable-patchelf support to patch ELF rpaths and interpreters in strictly confined snaps. | |
| #1935 elf: contemplate more patching scenarios | snapcraft | merged | Merged PR #1935 as 048adc4a3, adding ELF patching for classic snaps built on bionic targeting core16 and for hooks built with Snapcraft. | |
| #1805205 Ensure elf patching works correctly with golang created ELF files | snapcraft (launchpad) | closed | Fixed Go ELF patching in snapcore/snapcraft PR #2519 by updating the PatchELF handling used for Go-created binaries. | |
| #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. | |
| #1913 elf: pyelftools to parse ELF files rather than readelf | snapcraft | merged | 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. | |
| #1669 patchelf with ld-linux from the future | snapcraft | closed | Resolved by commit bdaf0b7f1, which added Snapcraft handling for PatchELF and ELF files when the built glibc/linker does not match the base. |