Skip to content

Commit 046119b

Browse files
committed
fix(rocm-compilersupport): teach rocm-llvm clang to find the AZL GCC toolchain
AZL's azurelinux-rpm-config overlay changes %_vendor from "redhat" to "azurelinux", so GCC installs its runtime objects (crtbeginS.o, libgcc, libstdc++, etc.) under /usr/lib/gcc/<cpu>-azurelinux-linux/<ver>/. The upstream clang GCCInstallationDetector triple list in clang/lib/Driver/ToolChains/Gnu.cpp only knows about a fixed set of vendor strings ("redhat", "suse", "amazon", ...) and has no "azurelinux" entry, so any clang built without an AZL-aware config silently fails to find the GCC install and produces link errors like: ld.lld: error: cannot open crtbeginS.o: No such file or directory ld.lld: error: unable to find library -lstdc++ ld.lld: error: unable to find library -lgcc_s / -lgcc The system llvm / llvm20 packages already work around this by writing %{_target_platform}-clang.cfg files into /etc/clang containing "--gcc-triple=%{_target_cpu}-%{_vendor}-linux". The rocm-llvm clang shipped here lives at /usr/lib64/rocm/llvm/bin/ and does not read /etc/clang, so it needs its own per-binary config file. This was breaking the mivisionx build on x86_64 (and would similarly break every other ROCm consumer that drives the rocm-llvm clang directly, e.g. hipblaslt, hipcub, hipfft, rocfft, rocblas, miopen). A rebuild of rocm-compilersupport itself also fails for the same reason because the multi-stage %build uses its own freshly-built clang to compile each subsequent stage. Add three spec-search-replace overlays that drop clang.cfg / clang++.cfg with --gcc-triple=%{_target_cpu}-%{_vendor}-linux in three places: 1. Next to the stage-1 clang inside build-llvm/bin so stage 2+ of the in-package %build can compile and link. 2. Pre-staged inside build-llvm-2/bin before stage-2 %cmake_build runs so the LLVM "runtimes" sub-build (compiler-rt, libcxx, libcxxabi) can configure once stage-2 clang is produced. 3. Installed into %{bundle_prefix}/bin alongside the shipped clang so every downstream ROCm consumer sees the right toolchain triple. Clang automatically reads "<argv0>.cfg" from its own directory before any system config dir, so dropping the file is sufficient — no source patch and no version-specific maintenance. The cfg payload uses %_vendor / %_target_cpu so it transparently follows future arch and vendor changes. The existing "%{bundle_prefix}/bin/clang*" glob in %files -n rocm-clang already picks up the new files. This mirrors the existing approach in base/comps/llvm and base/comps/llvm20 rather than introducing a new mechanism.
1 parent 4bd4dd8 commit 046119b

4 files changed

Lines changed: 89 additions & 3 deletions

File tree

base/comps/rocm-compilersupport/rocm-compilersupport.comp.toml

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,76 @@ release = { calculation = "manual" }
2424
# 1. feat: introduce deterministic commit resolution via Azure Linux lock file
2525
# 2. fix(rocm-compilersupport): set manual release calculation
2626
# 3. fix(rocm-compilersupport): introduce azl_release counter
27-
azl_release = "3"
27+
# 4. fix(rocm-compilersupport): teach rocm-llvm clang to find the AZL GCC toolchain
28+
azl_release = "4"
2829

2930
[[components.rocm-compilersupport.overlays]]
3031
description = "Switch hard-coded Release prefix to %{azl_release}-driven formula so AZL-only rebuilds bump cleanly without manual edits"
3132
type = "spec-search-replace"
3233
regex = '''Release: 15\.rocm%\{rocm_version\}%\{\?dist\}'''
3334
replacement = '''Release: %[15 + %{azl_release}].rocm%{rocm_version}%{?dist}'''
35+
36+
[[components.rocm-compilersupport.overlays]]
37+
# After the stage-1 LLVM is built, the spec uses its freshly-built clang to
38+
# compile every subsequent stage (stage-2 llvm, device-libs, comgr, hipcc).
39+
# That stage-1 clang has the same GCC-toolchain-detection problem as the
40+
# installed copy: upstream clang doesn't know the "azurelinux" vendor and so
41+
# fails to locate /usr/lib/gcc/<cpu>-azurelinux-linux/<ver>/crtbeginS.o etc.
42+
# Drop a clang.cfg/clang++.cfg next to the stage-1 binaries so every later
43+
# stage in this %build can find the toolchain.
44+
description = "Drop clang.cfg / clang++.cfg next to the in-tree stage-1 clang so later build stages can locate the Azure Linux GCC toolchain"
45+
type = "spec-search-replace"
46+
regex = '''build_stage1=\$p/build-llvm'''
47+
replacement = '''build_stage1=$p/build-llvm
48+
49+
# AZL: same --gcc-triple fix as for the installed binaries, but applied to
50+
# the stage-1 clang inside the build tree so stage 2+ can compile/link.
51+
echo "--gcc-triple=%{_target_cpu}-%{_vendor}-linux" > $build_stage1/bin/clang.cfg
52+
cp -p $build_stage1/bin/clang.cfg $build_stage1/bin/clang++.cfg'''
53+
54+
[[components.rocm-compilersupport.overlays]]
55+
# Stage 2 builds the LLVM "runtimes" project (compiler-rt, libcxx, libcxxabi)
56+
# as a sub-build that re-invokes CMake using the freshly-built stage-2 clang
57+
# at build-llvm-2/bin/. That sub-build re-runs the compiler/linker probes
58+
# and hits the same GCC-toolchain-detection failure as stage 1 unless its
59+
# clang has a config file alongside it. Drop the cfg files into the stage-2
60+
# bin directory before %cmake_build runs; they sit there until clang is
61+
# built and are picked up automatically on first invocation.
62+
description = "Drop clang.cfg / clang++.cfg into the stage-2 build tree so the LLVM runtimes sub-build can find the Azure Linux GCC toolchain"
63+
type = "spec-search-replace"
64+
regex = '''-DLLVM_ENABLE_RUNTIMES=%\{llvm_runtimes\}'''
65+
replacement = '''-DLLVM_ENABLE_RUNTIMES=%{llvm_runtimes}
66+
67+
# AZL: pre-stage the clang config file inside build-llvm-2/bin so the
68+
# LLVM runtimes sub-build (which invokes the just-built stage-2 clang to
69+
# configure compiler-rt/libcxx/libcxxabi) can locate the Azure Linux GCC
70+
# toolchain. The .cfg only needs to exist by the time clang is invoked.
71+
mkdir -p $PWD/build-llvm-2/bin
72+
echo "--gcc-triple=%{_target_cpu}-%{_vendor}-linux" > $PWD/build-llvm-2/bin/clang.cfg
73+
cp -p $PWD/build-llvm-2/bin/clang.cfg $PWD/build-llvm-2/bin/clang++.cfg'''
74+
75+
[[components.rocm-compilersupport.overlays]]
76+
# AZL changes %_vendor from "redhat" to "azurelinux" (see azurelinux-rpm-config),
77+
# so GCC installs its runtime objects under /usr/lib/gcc/<cpu>-azurelinux-linux/<ver>/.
78+
# Upstream clang's GCCInstallationDetector triple list does not include the
79+
# "azurelinux" vendor, so without help rocm-llvm's clang can't find crtbeginS.o /
80+
# libstdc++ / libgcc and link of any C++ test program (e.g. CMake compiler probe)
81+
# fails with "cannot open crtbeginS.o" and "unable to find library -lstdc++".
82+
#
83+
# The system llvm/llvm20 packages work around this by writing a per-triple
84+
# clang config file under /etc/clang. The rocm-llvm clang at
85+
# %{bundle_prefix}/bin/ does not read /etc/clang, so we drop clang.cfg and
86+
# clang++.cfg next to the binaries (clang reads "<argv0>.cfg" from its own
87+
# directory before any system dir). The cfg file forces --gcc-triple to the
88+
# AZL triple so the GCC toolchain is detected.
89+
description = "Drop clang.cfg / clang++.cfg next to rocm-llvm's clang so it can find the Azure Linux GCC toolchain (vendor=azurelinux, not redhat)"
90+
type = "spec-search-replace"
91+
regex = '''# Remove lld's libs'''
92+
replacement = '''# AZL: drop clang config files so rocm-llvm's clang can locate the Azure Linux
93+
# GCC toolchain at /usr/lib/gcc/%{_target_cpu}-%{_vendor}-linux/ (upstream clang
94+
# only knows the "redhat", "suse", "amazon", etc. vendor strings).
95+
mkdir -p %{buildroot}%{bundle_prefix}/bin
96+
echo "--gcc-triple=%{_target_cpu}-%{_vendor}-linux" > %{buildroot}%{bundle_prefix}/bin/clang.cfg
97+
cp -p %{buildroot}%{bundle_prefix}/bin/clang.cfg %{buildroot}%{bundle_prefix}/bin/clang++.cfg
98+
99+
# Remove lld's libs'''

locks/rocm-compilersupport.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
version = 1
33
import-commit = '878261eeebbede5f9f220522155fb1ccd8110df8'
44
upstream-commit = '878261eeebbede5f9f220522155fb1ccd8110df8'
5-
input-fingerprint = 'sha256:ba5c7c12d93828b38f2bfed2431fba93ff016e2b23620b706ca356cc6b2a3115'
5+
input-fingerprint = 'sha256:17106d9425e94416d13ba712c4186e855ff7ea5c6ac1cc14aea2bdfb7fbbb521'
66
resolution-input-hash = 'sha256:466421704711c4fd3c71f0b2ed715a0e61d49e3e26f3a2637fee755795849c8e'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Macros file automatically generated by azldev.
22
# Do not edit manually; changes will be overwritten.
3-
%azl_release 3
3+
%azl_release 4

specs/r/rocm-compilersupport/rocm-compilersupport.spec

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ popd
463463

464464
build_stage1=$p/build-llvm
465465

466+
# AZL: same --gcc-triple fix as for the installed binaries, but applied to
467+
# the stage-1 clang inside the build tree so stage 2+ can compile/link.
468+
echo "--gcc-triple=%{_target_cpu}-%{_vendor}-linux" > $build_stage1/bin/clang.cfg
469+
cp -p $build_stage1/bin/clang.cfg $build_stage1/bin/clang++.cfg
470+
466471
%global llvmrocm_stage1_config \\\
467472
-DCMAKE_AR=$build_stage1/bin/llvm-ar \\\
468473
-DCMAKE_C_COMPILER=$build_stage1/bin/clang \\\
@@ -501,6 +506,14 @@ export LD_LIBRARY_PATH=$PWD/build-llvm-2/lib
501506
-DLLVM_TOOL_LIBCXX_BUILD=ON \
502507
-DLLVM_ENABLE_PROJECTS=%{llvm_projects} \
503508
-DLLVM_ENABLE_RUNTIMES=%{llvm_runtimes}
509+
510+
# AZL: pre-stage the clang config file inside build-llvm-2/bin so the
511+
# LLVM runtimes sub-build (which invokes the just-built stage-2 clang to
512+
# configure compiler-rt/libcxx/libcxxabi) can locate the Azure Linux GCC
513+
# toolchain. The .cfg only needs to exist by the time clang is invoked.
514+
mkdir -p $PWD/build-llvm-2/bin
515+
echo "--gcc-triple=%{_target_cpu}-%{_vendor}-linux" > $PWD/build-llvm-2/bin/clang.cfg
516+
cp -p $PWD/build-llvm-2/bin/clang.cfg $PWD/build-llvm-2/bin/clang++.cfg
504517

505518
%cmake_build -j ${JOBS}
506519
popd
@@ -706,6 +719,13 @@ find %{buildroot}%{bundle_prefix}/lib -type f -name '*.so*' -exec strip {} \;
706719
find %{buildroot}%{_libdir} -type f -name '*.so*' -exec strip {} \;
707720
%endif
708721

722+
# AZL: drop clang config files so rocm-llvm's clang can locate the Azure Linux
723+
# GCC toolchain at /usr/lib/gcc/%{_target_cpu}-%{_vendor}-linux/ (upstream clang
724+
# only knows the "redhat", "suse", "amazon", etc. vendor strings).
725+
mkdir -p %{buildroot}%{bundle_prefix}/bin
726+
echo "--gcc-triple=%{_target_cpu}-%{_vendor}-linux" > %{buildroot}%{bundle_prefix}/bin/clang.cfg
727+
cp -p %{buildroot}%{bundle_prefix}/bin/clang.cfg %{buildroot}%{bundle_prefix}/bin/clang++.cfg
728+
709729
# Remove lld's libs
710730
rm -rf %{buildroot}%{bundle_prefix}/include/lld
711731
rm -rf %{buildroot}%{bundle_prefix}/lib/cmake/lld

0 commit comments

Comments
 (0)