[libc-commits] [libc] [llvm] [libc] Disable -march=native in CI to fix sccache poisoning (PR #196560)
via libc-commits
libc-commits at lists.llvm.org
Fri May 8 08:57:07 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Jeff Bailey (kaladron)
<details>
<summary>Changes</summary>
-march=native is incompatible with shared build caches because sccache treats it as a literal string. Object files compiled on one CPU model get silently served to runners with a different CPU, causing SIGILL crashes in the opt_host memory tests.
Made LIBC_COMPILE_OPTIONS_NATIVE a CMake cache variable so CI can override it. Both overlay and fullbuild workflows now pass -DLIBC_COMPILE_OPTIONS_NATIVE="" to disable -march=native. Local developer builds are unaffected and still default to -march=native.
Reverted the per-CPU cache key approach from #<!-- -->196477 in favour of this fix, which addresses the root cause.
Bumped sccache key versions (v2) in both workflows to invalidate the poisoned caches.
Assisted-by: Automated tooling, human reviewed.
---
Full diff: https://github.com/llvm/llvm-project/pull/196560.diff
3 Files Affected:
- (modified) .github/workflows/libc-fullbuild-tests.yml (+3-2)
- (modified) .github/workflows/libc-overlay-tests.yml (+2-26)
- (modified) libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake (+16-3)
``````````diff
diff --git a/.github/workflows/libc-fullbuild-tests.yml b/.github/workflows/libc-fullbuild-tests.yml
index 3a9d1436d5d48..4a7cfa119b74c 100644
--- a/.github/workflows/libc-fullbuild-tests.yml
+++ b/.github/workflows/libc-fullbuild-tests.yml
@@ -120,7 +120,7 @@ jobs:
uses: hendrikmuhs/ccache-action at 33522472633dbd32578e909b315f5ee43ba878ce # v1.2.22
with:
max-size: 1G
- key: libc_fullbuild_${{ matrix.c_compiler }}
+ key: libc_fullbuild_v2_${{ matrix.c_compiler }}
variant: sccache
- name: Set reusable strings
@@ -145,7 +145,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_C_COMPILER_LAUNCHER=sccache
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
- -DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }}"
+ -DCMAKE_INSTALL_PREFIX=${{ steps.strings.outputs.build-install-dir }}
+ -DLIBC_COMPILE_OPTIONS_NATIVE=''"
if [[ "${{ matrix.include_scudo }}" == "ON" || "${{ matrix.build_fuzzing_tests }}" == "ON" ]]; then
export RUNTIMES="$RUNTIMES;compiler-rt"
diff --git a/.github/workflows/libc-overlay-tests.yml b/.github/workflows/libc-overlay-tests.yml
index a020f0bfd5cd3..f63150983aa03 100644
--- a/.github/workflows/libc-overlay-tests.yml
+++ b/.github/workflows/libc-overlay-tests.yml
@@ -44,31 +44,6 @@ jobs:
- uses: actions/checkout at de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
-
- # The libc build uses -march=native for opt_host tests, which means
- # the generated object files are specific to the runner's CPU model.
- # sccache treats -march=native as a literal string in its cache key,
- # so without per-CPU cache keys, object files compiled on one CPU
- # model are silently served to runners with a different CPU, causing
- # illegal instruction crashes at runtime.
- - name: Detect CPU model
- id: cpu-info
- shell: bash
- run: |
- if [ "$RUNNER_OS" = "Linux" ]; then
- # x86 has 'model name', ARM has 'CPU implementer' + 'CPU part'.
- cpu_model=$(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | xargs | tr ' ' '-' || true)
- if [ -z "$cpu_model" ]; then
- impl=$(grep -m1 'CPU implementer' /proc/cpuinfo | cut -d: -f2 | xargs)
- part=$(grep -m1 'CPU part' /proc/cpuinfo | cut -d: -f2 | xargs)
- cpu_model="arm-${impl:-unknown}-${part:-unknown}"
- fi
- elif [ "$RUNNER_OS" = "macOS" ]; then
- cpu_model=$(sysctl -n machdep.cpu.brand_string | tr ' ' '-')
- else
- cpu_model="generic"
- fi
- echo "cpu-model=${cpu_model:-unknown}" >> "$GITHUB_OUTPUT"
# Libc's build is relatively small comparing with other components of LLVM.
# A fresh linux overlay takes about 180MiB of uncompressed disk space, which can
@@ -81,7 +56,7 @@ jobs:
uses: hendrikmuhs/ccache-action at 33522472633dbd32578e909b315f5ee43ba878ce # v1.2.22
with:
max-size: 1G
- key: libc_overlay_build_${{ matrix.os }}_${{ matrix.compiler.c_compiler }}_${{ steps.cpu-info.outputs.cpu-model }}
+ key: libc_overlay_build_v2_${{ matrix.os }}_${{ matrix.compiler.c_compiler }}
variant: sccache
# MPFR is required by some of the mathlib tests.
@@ -122,6 +97,7 @@ jobs:
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
-DCMAKE_POLICY_DEFAULT_CMP0141=NEW
-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded
+ -DLIBC_COMPILE_OPTIONS_NATIVE=""
-DLLVM_ENABLE_RUNTIMES=libc
-G Ninja
-S ${{ github.workspace }}/runtimes
diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index d76f3b16b30ec..4b8f1c3399ff5 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -7,16 +7,29 @@ set(ALL_CPU_FEATURES "")
if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX AVX2 AVX512F AVX512BW FMA)
- set(LIBC_COMPILE_OPTIONS_NATIVE -march=native)
+ set(_libc_native_default -march=native)
elseif(LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
set(ALL_CPU_FEATURES FullFP16 MOPS SVE SVE2)
- set(LIBC_COMPILE_OPTIONS_NATIVE -mcpu=native)
+ set(_libc_native_default -mcpu=native)
+else()
+ set(_libc_native_default "")
endif()
if(LIBC_CROSSBUILD)
- set(LIBC_COMPILE_OPTIONS_NATIVE ${LIBC_COMPILE_OPTIONS_DEFAULT})
+ set(_libc_native_default ${LIBC_COMPILE_OPTIONS_DEFAULT})
endif()
+# LIBC_COMPILE_OPTIONS_NATIVE controls the -march/-mcpu flag used for
+# host-optimised builds and CPU feature detection. It defaults to
+# -march=native (x86) or -mcpu=native (AArch64) for local developer builds.
+#
+# CI environments with shared build caches (e.g. sccache) should set this
+# to an empty string (-DLIBC_COMPILE_OPTIONS_NATIVE="") because the cache
+# treats -march=native as a literal string and will silently serve object
+# files compiled for a different CPU model.
+set(LIBC_COMPILE_OPTIONS_NATIVE "${_libc_native_default}" CACHE STRING
+ "Compile options for host-native builds. Set to empty to disable -march=native.")
+
# Making sure ALL_CPU_FEATURES is sorted.
list(SORT ALL_CPU_FEATURES)
``````````
</details>
https://github.com/llvm/llvm-project/pull/196560
More information about the libc-commits
mailing list