[libc-commits] [libc] 313cc46 - [libc][cmake] Don't assume CPU features in cross builds (#198308)

via libc-commits libc-commits at lists.llvm.org
Tue May 19 05:08:25 PDT 2026


Author: dcandler
Date: 2026-05-19T13:08:19+01:00
New Revision: 313cc46e5893e6299ee1460e8dcc4f0ff5da015a

URL: https://github.com/llvm/llvm-project/commit/313cc46e5893e6299ee1460e8dcc4f0ff5da015a
DIFF: https://github.com/llvm/llvm-project/commit/313cc46e5893e6299ee1460e8dcc4f0ff5da015a.diff

LOG: [libc][cmake] Don't assume CPU features in cross builds (#198308)

Assuming all CPU features are available during cross builds will be
incorrect in some cases, such as armv8.0-a where FullFP16 is not
available and therefore FP16 instructions will not be understood.

Looking at the file history, the feature detection code previously
relied on try_run instead of try_compile, which might explain why it
couldn't be used in cross builds as cross built binaries wouldn't be
executable. But now the tests are compile only, they can work for cross
builds too, which would be better than assuming features.

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index 4b8f1c3399ff5..4207c2b6b3cba 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -63,25 +63,19 @@ function(_intersection output_var list1 list2)
 endfunction()
 
 set(AVAILABLE_CPU_FEATURES "")
-if(LIBC_CROSSBUILD)
-  # If we are doing a cross build, we will just assume that all CPU features
-  # are available.
-  set(AVAILABLE_CPU_FEATURES ${ALL_CPU_FEATURES})
-else()
-  # Try compile a C file to check if flag is supported.
-  set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  foreach(feature IN LISTS ALL_CPU_FEATURES)
-    try_compile(
-      has_feature
-      ${CMAKE_CURRENT_BINARY_DIR}/cpu_features
-      SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/cpu_features/check_${feature}.cpp
-      COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${LIBC_COMPILE_OPTIONS_NATIVE}
-    )
-    if(has_feature)
-      list(APPEND AVAILABLE_CPU_FEATURES ${feature})
-    endif()
-  endforeach()
-endif()
+# Try to compile a C file to check if a flag is supported.
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+foreach(feature IN LISTS ALL_CPU_FEATURES)
+  try_compile(
+    has_feature
+    ${CMAKE_CURRENT_BINARY_DIR}/cpu_features
+    SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/cpu_features/check_${feature}.cpp
+    COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${LIBC_COMPILE_OPTIONS_NATIVE}
+  )
+  if(has_feature)
+    list(APPEND AVAILABLE_CPU_FEATURES ${feature})
+  endif()
+endforeach()
 
 set(LIBC_CPU_FEATURES ${AVAILABLE_CPU_FEATURES} CACHE STRING "Host supported CPU features")
 


        


More information about the libc-commits mailing list