fix(patchelf): use the build-for architecture's dynamic linker
Metadata
Current evaluation
PR #6455 was closed unmerged; its patchelf cross-compilation linker fix was not delivered, and #5836 remains open.
Resolution: closed stale
Reason: PR #6455 was closed without review, a merge, or a resolving commit. The underlying defect in issue #5836 remains open and unfixed.
Evaluated by: mr-cal-bot
No scores available.
Issue body
With the `enable-patchelf` build attribute, `patch_elf()` picked the dynamic linker and the library arch triplet with `platform.machine()`, which is the build host. When cross-compiling, for example on arm64 for armhf, binaries got the arm64 interpreter (`ld-linux-aarch64.so.1`), which doesn't exist on the target.
Changes:
- `elf_utils.get_dynamic_linker()` takes an optional `arch` argument, like `get_arch_triplet()` already does. The linker's standard path is also available from a new `get_dynamic_linker_path()` helper.
- `patch_elf()` uses the build-for architecture for the linker and for the arch triplet used to look up libraries.
- If the linker isn't staged and the build is cross-compiling, `patch_elf()` uses the linker's standard location in the base snap instead of checking the host. Cross toolchains like `gcc-arm-linux-gnueabihf` (used by the snap in the issue) install the target's linker under `/usr/<triplet>/`, so checking the host would fail even though the base snap provides the linker at runtime.
Native builds behave as before.
`test_post_prime_patchelf` only runs when `patchelf` is installed, and its mocked step info needed `arch_build_for` and `is_cross_compiling`, so I added them.
Fixes #5836
---
- [x] I've followed the [contribution guidelines](https://github.com/canonical/snapcraft/blob/main/CONTRIBUTING.md).
- [x] I've signed the [CLA](http://www.ubuntu.com/legal/contributors/).
- [x] I've successfully run `make lint && make test`.
- [ ] I've added or updated any relevant documentation.
- [ ] In documents I changed, I [added a meta description](https://canonical-starflow.readthedocs-hosted.com/how-to/add-a-page-meta-description/) if one was missing.
- [ ] I've updated the relevant release notes.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed stale | PR #6455 was closed unmerged; its patchelf cross-compilation linker fix was not delivered, and #5836 remains open. | |
| qwen/qwen3.8-27b | — | closed stale | Closed unmerged with 0 reviewers. Proposed using the build-for architecture's dynamic linker in patch_elf() for cross-compiles (fixes #5836), but the PR was never merged and issue #5836 remains open. | |
| stealth/space-bunny-alpha |
Impact:
57
Quick Win:
22
Complexity:
52
Confidence:
87
Actionability:
80
|
needs review | Updates patchelf to select target linkers and library triplets for cross-builds, with a base-snap fallback and test updates. The fix addresses #5836 and awaits maintainer review. |
Update history
| Date | Change |
|---|---|
| closed | |
| created |
Related work
-
Related To:
canonical/snapcraft#5836
(confidence 100%)
PR #6455 claimed to fix this cross-compilation linker issue but was closed unmerged.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1967 project_loader: improve the logic to install patchelf as a build tool | snapcraft | merged | Merged PR #1967 as commit 84aaac591, improving patchelf build-tool installation and excluding broken Xenial armhf/s390x packages. | |
| #2519 packaging: use local patchelf | snapcraft | merged | Merged as e39d2404c, adopting Patchelf 0.10 and relinking dynamic Go executables; later reverted by #2531 after architecture tests exposed unreliable binaries. | |
| #2530 Patchelf test branch | snapcraft | closed | Patchelf test-branch PR #2530 was closed unmerged after years without review or CI; PR #2531 shipped the alternative locally patched Patchelf 0.9 approach in 44be372e3. | |
| #1403 build: patch ELF files built from python | charmcraft | closed | ELF-patching build change was closed unmerged without review or CI and was never adopted. | |
| #3588 snap: patch patchelf on riscv64 (CRAFT-566) | snapcraft | merged | Merged PR #3588 via commit bf99dbdb2, conditionally patching PatchELF on riscv64 while leaving other architectures unchanged. | |
| #2531 snap: revert to patchelf 0.9 with local patches | snapcraft | merged | Merged PR #2531 as commit 44be372e3, reverting from Patchelf 0.10 to locally patched 0.9 after architecture tests exposed unreliable binaries. | |
| #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. | |
| #1888 elf: make patchelf a dependency | snapcraft | merged | Merged PR #1888 via commit 7c947f5ec, moving Patchelf out of project_loader build tools and into the deb and snap delivery mechanisms. | |
| #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. |