[libc-commits] [libc] [libc] Disable LlvmLibcTimespecGet.Monotonic for baremetal targets (PR #152290)

William Huynh via libc-commits libc-commits at lists.llvm.org
Mon Aug 11 03:29:15 PDT 2025


https://github.com/saturn691 updated https://github.com/llvm/llvm-project/pull/152290

>From 1f992387be26345467960916a74cf36630d93cf7 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Wed, 6 Aug 2025 11:52:21 +0100
Subject: [PATCH 1/3] [libc] Disable LlvmLibcTimespecGet.Monotonic for
 baremetal targets

---
 libc/test/src/time/CMakeLists.txt        | 6 ++++++
 libc/test/src/time/timespec_get_test.cpp | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index be7aa6f0f058a..11ca7056e89bc 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -202,6 +202,10 @@ add_libc_unittest(
     libc.src.errno.errno
 )
 
+if(LIBC_TARGET_OS_IS_BAREMETAL)
+  list(APPEND options "-DLIBC_TARGET_OS_IS_BAREMETAL")
+endif()
+
 add_libc_test(
   timespec_get_test
   SUITE
@@ -211,6 +215,8 @@ add_libc_test(
   DEPENDS
     libc.src.time.timespec_get
     libc.hdr.types.struct_timespec
+  COMPILE_OPTIONS
+    ${options}
 )
 
 add_libc_test(
diff --git a/libc/test/src/time/timespec_get_test.cpp b/libc/test/src/time/timespec_get_test.cpp
index 327bfefe934c1..97585016f1dd7 100644
--- a/libc/test/src/time/timespec_get_test.cpp
+++ b/libc/test/src/time/timespec_get_test.cpp
@@ -24,6 +24,8 @@ TEST(LlvmLibcTimespecGet, Utc) {
 #endif
 }
 
+// Baremetal implementation currently only supports TIME_UTC
+#ifndef LIBC_TARGET_OS_IS_BAREMETAL
 TEST(LlvmLibcTimespecGet, Monotonic) {
   timespec ts1, ts2;
   int result;
@@ -37,6 +39,7 @@ TEST(LlvmLibcTimespecGet, Monotonic) {
     ASSERT_GE(ts2.tv_nsec, ts1.tv_nsec);
   }
 }
+#endif
 
 TEST(LlvmLibcTimespecGet, Unknown) {
   timespec ts;

>From 2de8d4baea4021268c2e7aacc2fe825042b4b165 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Mon, 11 Aug 2025 11:09:02 +0100
Subject: [PATCH 2/3] Apply suggestions from @lntue

---
 .../modules/LLVMLibCCompileOptionRules.cmake  | 59 ++++++++++++++++++-
 libc/cmake/modules/LLVMLibCTestRules.cmake    |  4 +-
 libc/test/src/time/CMakeLists.txt             |  6 --
 3 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index d85c3930474ab..db5398ff6ed6d 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -115,11 +115,68 @@ function(_get_compile_options_from_config output_var)
   set(${output_var} ${config_options} PARENT_SCOPE)
 endfunction(_get_compile_options_from_config)
 
+function(_get_compile_options_from_arch output_var)
+  set(config_options "")
+
+  if(LIBC_TARGET_ARCHITECTURE_IS_ARM)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_ARM")
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_AARCH64")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_X86_64)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_X86_64")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_X86)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_X86")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_RISCV64")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_RISCV32)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_RISCV32")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_AMDGPU")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_NVPTX")  
+  endif()
+  if (LIBC_TARGET_ARCHITECTURE_IS_SPIRV)
+    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_SPIRV")  
+  endif()
+
+  if (LIBC_TARGET_OS_IS_BAREMETAL)
+    list(APPEND config_options "-DLIBC_TARGET_OS_IS_BAREMETAL")  
+  endif()
+  if (LIBC_TARGET_OS_IS_LINUX)
+    list(APPEND config_options "-DLIBC_TARGET_OS_IS_LINUX")  
+  endif()
+  if (LIBC_TARGET_OS_IS_DARWIN)
+    list(APPEND config_options "-DLIBC_TARGET_OS_IS_DARWIN")  
+  endif()
+  if (LIBC_TARGET_OS_IS_WINDOWS)
+    list(APPEND config_options "-DLIBC_TARGET_OS_IS_WINDOWS")  
+  endif()
+  if (LIBC_TARGET_OS_IS_GPU)
+    list(APPEND config_options "-DLIBC_TARGET_OS_IS_GPU")  
+  endif()
+  if (LIBC_TARGET_OS_IS_UEFI)
+    list(APPEND config_options "-DLIBC_TARGET_OS_IS_UEFI")  
+  endif()
+
+  set(${output_var} ${config_options} PARENT_SCOPE)
+endfunction(_get_compile_options_from_arch)
+
 function(_get_common_compile_options output_var flags)
   _get_compile_options_from_flags(compile_flags ${flags})
   _get_compile_options_from_config(config_flags)
+  _get_compile_options_from_arch(arch_flags)
 
-  set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${compile_flags} ${config_flags})
+  set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${compile_flags} ${config_flags} ${arch_flags})
 
   if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
     list(APPEND compile_options "-fpie")
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 267c32e956945..30b1fd10a1774 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -1,6 +1,7 @@
 function(_get_common_test_compile_options output_var c_test flags)
   _get_compile_options_from_flags(compile_flags ${flags})
   _get_compile_options_from_config(config_flags)
+  _get_compile_options_from_arch(arch_flags)
 
   # Remove -fno-math-errno if it was added.
   if(LIBC_ADD_FNO_MATH_ERRNO)
@@ -16,7 +17,8 @@ function(_get_common_test_compile_options output_var c_test flags)
       ${LIBC_COMPILE_OPTIONS_DEFAULT}
       ${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}
       ${compile_flags}
-      ${config_flags})
+      ${config_flags}
+      ${arch_flags})
 
   if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
     list(APPEND compile_options "-fpie")
diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index 11ca7056e89bc..be7aa6f0f058a 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -202,10 +202,6 @@ add_libc_unittest(
     libc.src.errno.errno
 )
 
-if(LIBC_TARGET_OS_IS_BAREMETAL)
-  list(APPEND options "-DLIBC_TARGET_OS_IS_BAREMETAL")
-endif()
-
 add_libc_test(
   timespec_get_test
   SUITE
@@ -215,8 +211,6 @@ add_libc_test(
   DEPENDS
     libc.src.time.timespec_get
     libc.hdr.types.struct_timespec
-  COMPILE_OPTIONS
-    ${options}
 )
 
 add_libc_test(

>From 10a9a2297b6b630553f79ee8a135a52dfe4c0619 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Mon, 11 Aug 2025 11:29:04 +0100
Subject: [PATCH 3/3] Fix CI

---
 .../modules/LLVMLibCCompileOptionRules.cmake  | 43 ++-----------------
 1 file changed, 3 insertions(+), 40 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index db5398ff6ed6d..2eb0f066e19e0 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -116,51 +116,14 @@ function(_get_compile_options_from_config output_var)
 endfunction(_get_compile_options_from_config)
 
 function(_get_compile_options_from_arch output_var)
+  # Set options that are not found in src/__support/macros/properties/architectures.h
+  # and src/__support/macros/properties/os.h
+  # TODO: we probably want to unify these at some point for consistency
   set(config_options "")
 
-  if(LIBC_TARGET_ARCHITECTURE_IS_ARM)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_ARM")
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_AARCH64)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_AARCH64")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_X86_64)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_X86_64")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_X86)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_X86")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_RISCV64")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_RISCV32)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_RISCV32")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_AMDGPU")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_NVPTX")  
-  endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_SPIRV)
-    list(APPEND config_options "-DLIBC_TARGET_ARCHITECTURE_IS_SPIRV")  
-  endif()
-
   if (LIBC_TARGET_OS_IS_BAREMETAL)
     list(APPEND config_options "-DLIBC_TARGET_OS_IS_BAREMETAL")  
   endif()
-  if (LIBC_TARGET_OS_IS_LINUX)
-    list(APPEND config_options "-DLIBC_TARGET_OS_IS_LINUX")  
-  endif()
-  if (LIBC_TARGET_OS_IS_DARWIN)
-    list(APPEND config_options "-DLIBC_TARGET_OS_IS_DARWIN")  
-  endif()
-  if (LIBC_TARGET_OS_IS_WINDOWS)
-    list(APPEND config_options "-DLIBC_TARGET_OS_IS_WINDOWS")  
-  endif()
   if (LIBC_TARGET_OS_IS_GPU)
     list(APPEND config_options "-DLIBC_TARGET_OS_IS_GPU")  
   endif()



More information about the libc-commits mailing list