pkg/pillar: fix arm64→amd64 cross-compilation for Alpine 3.22 / GCC 14#5755
pkg/pillar: fix arm64→amd64 cross-compilation for Alpine 3.22 / GCC 14#5755rene merged 1 commit intolf-edge:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5755 +/- ##
==========================================
+ Coverage 19.52% 28.34% +8.81%
==========================================
Files 19 18 -1
Lines 3021 2417 -604
==========================================
+ Hits 590 685 +95
+ Misses 2310 1588 -722
- Partials 121 144 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@zedi-pramodh , please, put the DHCP change into a separated commit, it makes easy to revert in case of issues with the Alpine's version. |
|
Just please double check (manually inside EVE node, not just by asking the AI) that the dhcpcd version is at least 10.1.0 |
[pillar] root@c2c8906f-4230-4fd6-99c7-4456fcebc6d4:/$ dhcpcd --version |
Alpine 3.22 ships GCC 14, which changed how the cross-compiler forwards
its configured sysroot to the linker. Two separate issues required fixes:
**1. CGO_LDFLAGS: explicit --sysroot for the cross-compilation path**
The cross-compiler (x86_64-alpine-linux-musl-gcc) was built with
--with-sysroot=/usr/x86_64-alpine-linux-musl. In GCC ≤13 this sysroot
was implicitly forwarded to ld.bfd when gcc acted as the linker driver.
In GCC 14 this implicit forwarding was removed. As a result, ld.bfd
searched the host arm64 container paths (/lib, /usr/lib) instead of the
cross sysroot, failing to find crt1.o and all amd64 target libraries.
Fix: set CGO_LDFLAGS="--sysroot=/usr/${EVE_TARGET_ARCH}-alpine-linux-musl"
in the build-cross-target stage so Go passes the flag to every external
linker invocation.
Also move CGO_CFLAGS="-Dfstat64=fstat -Dstat64=stat" to each parent
stage explicitly (build-native without --sysroot, build-cross-target with
--sysroot) and remove it from the generic build stage, which inherits the
correct value from whichever parent it uses.
**2. dhcpcd: replace from-source build with Alpine package**
The dhcpcd configure script runs a compiler probe (AC_TRY_RUN) that
requires the cross-compiler to produce a working executable. With GCC 14
and the broken sysroot the probe fails with:
"x86_64-alpine-linux-musl-gcc does not create executables"
Alpine 3.21+ includes dhcpcd 10.x in its main repository, satisfying all
the version requirements documented in the Dockerfile (IPv6 fixes in
commits 5f6f61c and 2b4fe4c). Building from source is therefore no longer
necessary.
Fix: add a new dhcpcd-bin FROM stage using ${EVE_ALPINE_IMAGE} without
--platform (so Docker BuildKit resolves to the target platform and pulls
the correct binary architecture), and copy from there instead of from the
build stage.
Signed-off-by: Pramodh Pallapothu <pramodh@zededa.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rene
left a comment
There was a problem hiding this comment.
Since dhcp version is confirmed to work, it LGTM.
|
@zedi-pramodh please, rebase your PR. |
|
@zedi-pramodh please rebase and fix linter comments |
50a3cdc to
4aacb2d
Compare
|
Rebased to master and pushed. |
@rucoder are you taking about Yetus issues, I do not think I modified that part of code in this commit. |
Alpine 3.22 ships GCC 14, which changed how the cross-compiler forwards its configured sysroot to the linker. Two separate issues required fixes:
1. CGO_LDFLAGS: explicit --sysroot for the cross-compilation path
The cross-compiler (x86_64-alpine-linux-musl-gcc) was built with --with-sysroot=/usr/x86_64-alpine-linux-musl. In GCC ≤13 this sysroot was implicitly forwarded to ld.bfd when gcc acted as the linker driver. In GCC 14 this implicit forwarding was removed. As a result, ld.bfd searched the host arm64 container paths (/lib, /usr/lib) instead of the cross sysroot, failing to find crt1.o and all amd64 target libraries.
Fix: set CGO_LDFLAGS="--sysroot=/usr/${EVE_TARGET_ARCH}-alpine-linux-musl" in the build-cross-target stage so Go passes the flag to every external linker invocation.
Also move CGO_CFLAGS="-Dfstat64=fstat -Dstat64=stat" to each parent stage explicitly (build-native without --sysroot, build-cross-target with --sysroot) and remove it from the generic build stage, which inherits the correct value from whichever parent it uses.
2. dhcpcd: replace from-source build with Alpine package
The dhcpcd configure script runs a compiler probe (AC_TRY_RUN) that requires the cross-compiler to produce a working executable. With GCC 14 and the broken sysroot the probe fails with:
"x86_64-alpine-linux-musl-gcc does not create executables"
Alpine 3.21+ includes dhcpcd 10.x in its main repository, satisfying all the version requirements documented in the Dockerfile (IPv6 fixes in commits 5f6f61c and 2b4fe4c). Building from source is therefore no longer necessary.
Fix: add a new dhcpcd-bin FROM stage using ${EVE_ALPINE_IMAGE} without --platform (so Docker BuildKit resolves to the target platform and pulls the correct binary architecture), and copy from there instead of from the build stage.
How to test and validate this PR
Should be able to cross compile pkg/pillar with this fix ie arm64->amd64 and vice versa.
Changelog notes
None
Checklist
I've provided a proper description
I've added the proper documentation
I've tested my PR on amd64 device
I've tested my PR on arm64 device
I've written the test verification instructions
I've set the proper labels to this PR
I've checked the boxes above, or I've provided a good reason why I didn't
check them.
Please, check the boxes above after submitting the PR in interactive mode.