Skip to content

fix(llvm): correct clang's default GCC triple for Azure Linux stage2#17043

Closed
rlmenge wants to merge 2 commits intotomls/base/mainfrom
rlmenge/tomls/clang-gcc-triple-no-bootstrap
Closed

fix(llvm): correct clang's default GCC triple for Azure Linux stage2#17043
rlmenge wants to merge 2 commits intotomls/base/mainfrom
rlmenge/tomls/clang-gcc-triple-no-bootstrap

Conversation

@rlmenge
Copy link
Copy Markdown
Contributor

@rlmenge rlmenge commented May 5, 2026

Merge Checklist

All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)

  • The toolchain has been rebuilt successfully (or no changes were made to it)
  • The toolchain/worker package manifests are up-to-date
  • Any updated packages successfully build (or no packages were changed)
  • Packages depending on static components modified in this PR (Golang, *-static subpackages, etc.) have had their Release tag incremented.
  • Package tests (%check section) have been verified with RUN_CHECK=y for existing SPEC files, or added to new SPEC files
  • All package sources are available
  • cgmanifest files are up-to-date and sorted (./cgmanifest.json, ./toolkit/scripts/toolchain/cgmanifest.json, .github/workflows/cgmanifest.json)
  • LICENSE-MAP files are up-to-date (./LICENSES-AND-NOTICES/SPECS/data/licenses.json, ./LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md, ./LICENSES-AND-NOTICES/SPECS/LICENSE-EXCEPTIONS.PHOTON)
  • All source files have up-to-date hashes in the *.signatures.json files
  • sudo make go-tidy-all and sudo make go-test-coverage pass
  • Documentation has been updated to match any changes to the build system
  • Ready to merge

Summary

The upstream Fedora clang spec writes a default config drop-in to /etc/clang/-clang.cfg containing '--gcc-triple=-redhat-linux'. Clang autoloads this drop-in when its compiled-in default target matches the basename.

In Azure Linux 4.0 stage2, GCC's runtime files (crtbegin.o, crtend.o, libgcc.a, etc.) ship under /usr/lib/gcc/x86_64-azurelinux-linux/ instead of /usr/lib/gcc/x86_64-redhat-linux/. As a result, clang can fail to find crtbeginS.o, -lgcc, and -lgcc_s when linking with ld.lld.

Add one LLVM component overlay to change the generated cfg_file_content macro from -redhat-linux to -azurelinux-linux, so the shipped clang default config points at the actual Azure Linux GCC runtime tree.

This is the clean fix, but rollout may require a bootstrap build or pre-seeding the stage2 buildroot with the fixed clang package. A full local LLVM rebuild from the no-bootstrap branch currently fails because the buildroot's already-installed clang still has the old bad config. The branch fixes the config that the new clang RPM would install, but the build depends on the existing broken clang before it can produce that RPM.

A local full build requires a temporary bootstrap step or a buildroot where clang's GCC triple is already corrected.

Refresh locks/llvm.lock and rerender specs/l/llvm/llvm.spec. This branch intentionally omits the temporary bootstrap workarounds used for local LLVM self-rebuild testing.

Verified with azldev comp render -p llvm -O json.

Change Log
  • correct clang's default GCC triple for Azure Linux stage2
Does this affect the toolchain?

NO

Associated issues
Test Methodology
  • koji: taskID=2246326

validated the change in two layers: render validation and clang runtime/link behavior in the stage2 mock chroot.

1. Render validation

Rendered LLVM successfully:

azldev comp render -p llvm -O json

Confirmed rendered spec contains:

%global cfg_file_content --gcc-triple=%{_target_cpu}-azurelinux-linux

Confirmed the no-bootstrap branch does not contain the temporary bootstrap workaround:

/tmp/azl-clang-bootstrap.cfg
--config=/tmp/azl-clang-bootstrap.cfg

2. Runtime/link validation

Reproduced the existing failure in the local stage2 mock buildroot. The currently installed clang package still has the bad config:

/etc/clang/x86_64-azurelinux-linux-gnu-clang.cfg:
--gcc-triple=x86_64-redhat-linux

With that existing config, clang fails to link a simple C program because it cannot locate GCC runtime files:

without override clang exit: 1
/usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: cannot find -lgcc_s: No such file or directory

Verified that forcing the Azure Linux GCC triple fixes simple C and C++ linking in the same mock chroot:

with --gcc-triple=x86_64-azurelinux-linux clang exit: 0
with --gcc-triple=x86_64-azurelinux-linux clang++ exit: 0

Also attempted a full local LLVM build:

azldev comp build -p llvm --preserve-buildenv on-failure

That build fails before producing new RPMs because the buildroot uses the currently installed clang package, whose config still points at x86_64-redhat-linux. This is the bootstrap issue this change is intended to fix for future clang packages.

Current Limitation

A full local LLVM rebuild from the no-bootstrap branch currently fails because the buildroot's already-installed clang still has the old bad config. The branch fixes the config that the new clang RPM would install, but the build depends on the existing broken clang before it can produce that RPM.

A local full build requires a temporary bootstrap step or a buildroot where clang's GCC triple is already corrected.

# upstream spec and pulls in python3-nanobind-devel which doesn't exist yet.
build.without = ["mlir"]

[[components.llvm.overlays]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We also build llvm15, 18, and 20; are they all impacted too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

20 for sure. Looks like 15 and 18 don't have the config file refrence so I am not sure. I will update the pr at least for llvm20.

[[components.llvm.overlays]]
description = "Use the Azure Linux GCC toolchain triple in clang's default config so clang can find gcc runtime files in stage2 builds"
type = "spec-search-replace"
regex = '%global cfg_file_content --gcc-triple=%{_target_cpu}-redhat-linux'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an opportunity to use the standard RPM macro %{_target_platform} in place of the whole thing? That's presumably what the upstream spec should have used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is unfortunately not a match thanks to the "gnu"

<mock-chroot> sh-5.3# rpm --eval '%{_target_platform}'
x86_64-azurelinux-linux-gnu

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good to know. How about at least using %{_vendor}?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

%vendor should work!

The upstream Fedora clang spec writes a default config drop-in to
/etc/clang/<triple>-clang.cfg containing '--gcc-triple=<cpu>-redhat-linux'.
Clang autoloads this drop-in when its compiled-in default target matches
the basename. In Azure Linux 4.0 stage2, GCC runtime files (crtbegin.o,
crtend.o, libgcc.a, etc.) ship under /usr/lib/gcc/x86_64-azurelinux-linux/
not /usr/lib/gcc/x86_64-redhat-linux/, so clang fails to find crtbeginS.o,
-lgcc, and -lgcc_s when invoking ld.lld. This breaks any package whose
build links via clang -- most visibly the kernel BPF selftests, which
abort with 'cannot open crtbeginS.o' while linking liburandom_read.so,
leading to the kernel build aborting on a strict 'cp .../bpftool' for
missing artifacts.

Add a spec-search-replace overlay to change the gcc_triple macro from
-redhat-linux to -azurelinux-linux so the shipped clang config points at
the actual Azure Linux GCC runtime tree.
@rlmenge rlmenge force-pushed the rlmenge/tomls/clang-gcc-triple-no-bootstrap branch 2 times, most recently from ae36f49 to f88da1b Compare May 6, 2026 22:38
Same issue as llvm (clang 21): the upstream Fedora spec hardcodes
--gcc-triple=<cpu>-redhat-linux in the clang config drop-in.  Apply the
identical spec-search-replace overlay to llvm20 so that clang-20 also
finds GCC runtime files under /usr/lib/gcc/x86_64-azurelinux-linux/.

Move the llvm20 component from inline components.toml to a dedicated
base/comps/llvm20/llvm20.comp.toml to house the overlay.
@rlmenge rlmenge force-pushed the rlmenge/tomls/clang-gcc-triple-no-bootstrap branch from f88da1b to 2ed0299 Compare May 6, 2026 22:39
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

📄❌ Rendered specs are out of date

FIX: — run this and commit the result:

azldev component render llvm llvm20

Or download the fix patch and apply it:

gh run download 25465127854 -R microsoft/azurelinux -n rendered-specs-patch
git apply rendered-specs.patch
Category Count
Content diffs 2
Extra files (untracked) 0
Missing files (deleted) 0

Content diffs

`specs/l/llvm/llvm.spec`
--- committed/specs/l/llvm/llvm.spec
+++ rendered/specs/l/llvm/llvm.spec
@@ -3515,7 +3515,7 @@
 %changelog
 ## START: Generated by rpmautospec
 * Fri May 01 2026 Rachel Menge <rachelmenge@microsoft.com> - 21.1.8-6
-- fix(llvm): correct clang's default GCC triple for Azure Linux stage2
+- fix(llvm): correct clang default GCC triple for Azure Linux stage2
 
 * Thu Apr 30 2026 Daniel McIlvaney <damcilva@microsoft.com> - 21.1.8-5
 - feat: introduce deterministic commit resolution via Azure Linux lock file
`specs/l/llvm20/llvm20.spec`
--- committed/specs/l/llvm20/llvm20.spec
+++ rendered/specs/l/llvm20/llvm20.spec
@@ -2,7 +2,7 @@
 ## (rpmautospec version 0.8.3)
 ## RPMAUTOSPEC: autorelease, autochangelog
 %define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
-    release_number = 3;
+    release_number = 4;
     base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
     print(release_number + base_release_number - 1);
 }%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
@@ -3514,6 +3514,9 @@
 
 %changelog
 ## START: Generated by rpmautospec
+* Wed May 06 2026 Rachel Menge <rachelmenge@microsoft.com> - 20.1.8-4
+- fix(llvm20): apply same GCC triple fix for llvm20
+
 * Thu Apr 30 2026 Daniel McIlvaney <damcilva@microsoft.com> - 20.1.8-3
 - feat: introduce deterministic commit resolution via Azure Linux lock file
 

@rlmenge
Copy link
Copy Markdown
Contributor Author

rlmenge commented May 8, 2026

Closing to use the bootsrtap version: #17100

@rlmenge rlmenge closed this May 8, 2026
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.

2 participants