Skip to content

pkg/pillar: fix arm64→amd64 cross-compilation for Alpine 3.22 / GCC 14#5755

Merged
rene merged 1 commit intolf-edge:masterfrom
zedi-pramodh:fix-cross-compilation
Apr 21, 2026
Merged

pkg/pillar: fix arm64→amd64 cross-compilation for Alpine 3.22 / GCC 14#5755
rene merged 1 commit intolf-edge:masterfrom
zedi-pramodh:fix-cross-compilation

Conversation

@zedi-pramodh
Copy link
Copy Markdown

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.

@zedi-pramodh zedi-pramodh requested a review from rucoder April 6, 2026 23:15
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 28.34%. Comparing base (2281599) to head (50a3cdc).
⚠️ Report is 518 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rene
Copy link
Copy Markdown
Contributor

rene commented Apr 7, 2026

@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.

@milan-zededa
Copy link
Copy Markdown
Contributor

Just please double check (manually inside EVE node, not just by asking the AI) that the dhcpcd version is at least 10.1.0
Then we can safely merge this.

@zedi-pramodh
Copy link
Copy Markdown
Author

Just please double check (manually inside EVE node, not just by asking the AI) that the dhcpcd version is at least 10.1.0
Then we can safely merge this.

[pillar] root@c2c8906f-4230-4fd6-99c7-4456fcebc6d4:/$ dhcpcd --version
dhcpcd 10.2.3
Copyright (c) 2006-2025 Roy Marples
Compiled in features: INET ARP ARPing IPv4LL INET6 DHCPv6 AUTH PRIVSEP

@eriknordmark eriknordmark requested a review from rene April 16, 2026 21:21
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>
Copy link
Copy Markdown
Contributor

@rene rene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since dhcp version is confirmed to work, it LGTM.

@rene
Copy link
Copy Markdown
Contributor

rene commented Apr 20, 2026

@zedi-pramodh please, rebase your PR.

@rucoder
Copy link
Copy Markdown
Contributor

rucoder commented Apr 20, 2026

@zedi-pramodh please rebase and fix linter comments

@zedi-pramodh zedi-pramodh force-pushed the fix-cross-compilation branch from 50a3cdc to 4aacb2d Compare April 20, 2026 18:10
@zedi-pramodh
Copy link
Copy Markdown
Author

Rebased to master and pushed.

@zedi-pramodh
Copy link
Copy Markdown
Author

@zedi-pramodh please rebase and fix linter comments

@rucoder are you taking about Yetus issues, I do not think I modified that part of code in this commit.

@rene rene merged commit b8491f7 into lf-edge:master Apr 21, 2026
34 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants