EXPERIMENT: build: Add musl linker flags to reduce OpenHCL size - #4317
EXPERIMENT: build: Add musl linker flags to reduce OpenHCL size#4317Steven Malis (smalis-msft) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR experiments with reducing OpenHCL binary size for musl targets by switching to the Rust toolchain’s bundled lld and enabling linker optimizations (notably ICF and lld -O2), accepting some debuggability tradeoffs.
Changes:
- Add musl-target rustflags to link with lld and enable
--icf=all+ lld-O2in.cargo/config.toml. - Update the Underhill musl gcc wrapper scripts to direct GCC to the Rust toolchain’s
gcc-lddirectory so-fuse-ld=lldworks without a distrolldinstall.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| build_support/underhill_cross/x86_64-underhill-musl-gcc | Points GCC at the Rust toolchain’s gcc-ld location so lld can be found when -fuse-ld=lld is used. |
| build_support/underhill_cross/aarch64-underhill-musl-gcc | Same as above for aarch64 musl. |
| .cargo/config.toml | Enables lld + size-reduction flags for all musl builds via Cargo rustflags. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Satisfy the -fuse-ld=lld in .cargo/config.toml using the lld bundled with the | ||
| # Rust toolchain, so no distro lld package is needed. gcc-ld only ever exists | ||
| # for the host triple; if it is missing, gcc falls back to searching PATH. | ||
| gcc_ld_dir="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/gcc-ld" | ||
|
|
||
| MUSL_ARCH=x86_64 MUSL_SYSROOT="$X86_64_SYSROOT" exec "$REALGCC" "$@" -B"$gcc_ld_dir" -specs "$script_dir/musl-gcc.specs" |
| # Satisfy the -fuse-ld=lld in .cargo/config.toml using the lld bundled with the | ||
| # Rust toolchain, so no distro lld package is needed. gcc-ld only ever exists | ||
| # for the host triple; if it is missing, gcc falls back to searching PATH. | ||
| gcc_ld_dir="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/gcc-ld" | ||
|
|
||
| MUSL_ARCH=aarch64 MUSL_SYSROOT="$AARCH64_SYSROOT" exec "$REALGCC" "$@" -B"$gcc_ld_dir" -specs "$script_dir/musl-gcc.specs" |
There was a problem hiding this comment.
🔵 Needs a closer look
The new musl GCC wrapper logic depends on rustc output but currently lacks validation/error handling, which can cause confusing build failures when rustc/toolchain paths are unavailable or unparsable.
Review details
Suppressed comments (2)
build_support/underhill_cross/x86_64-underhill-musl-gcc:22
gcc_ld_diris derived fromrustcoutput without validating thatrustcis available or that the computedgcc-lddirectory exists. Ifrustcis missing/misconfigured (orsedreturns an empty host triple), the wrapper will pass-Bwith a missing argument or an invalid path, producing a confusing GCC error instead of a clear failure mode.
gcc_ld_dir="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/gcc-ld"
MUSL_ARCH=x86_64 MUSL_SYSROOT="$X86_64_SYSROOT" exec "$REALGCC" "$@" -B"$gcc_ld_dir" -specs "$script_dir/musl-gcc.specs"
build_support/underhill_cross/aarch64-underhill-musl-gcc:22
gcc_ld_diris computed fromrustcoutput without checking forrustcavailability or verifying that the resultinggcc-lddirectory exists. Ifrustcisn't on PATH (or the host triple can't be parsed), this wrapper can end up invoking GCC with an invalid-Bargument and fail with a non-obvious error.
gcc_ld_dir="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/gcc-ld"
MUSL_ARCH=aarch64 MUSL_SYSROOT="$AARCH64_SYSROOT" exec "$REALGCC" "$@" -B"$gcc_ld_dir" -specs "$script_dir/musl-gcc.specs"
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
Use rustup's provided lld and turn on some linker optimizations to shrink OpenHCL. Note that this does come with some debuggability downsides.