[libc-commits] [libc] [libc][cmake] Respect the configured optimization level for the Linux thread and TLS objects (PR #234371)

Prabhu Rajasekaran via libc-commits libc-commits at lists.llvm.org
Wed Oct 21 13:58:50 PDT 2026


https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/234371

The `-O3` override on the Linux `thread` object dates from the old approach of reading the thread arguments off the new thread's stack, which #225384 removed; the `tls` objects copied the same pattern in #225418. Neither needs it anymore, so drop the overrides and use the optimization level configured by CMake.

Stacked on #234363.


>From 8968a68414d09e491a88f8e9322662245059d276 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 21 Oct 2026 13:43:34 -0700
Subject: [PATCH 1/3] [libc][cmake] Respect the configured optimization level
 for math and stdfix tests

Follow up to #126322 and #233964: the math and stdfix tests still force ${libc_opt_high_flag}. Drop the overrides so the tests use the optimization level configured by CMake like the rest of the library.
---
 libc/test/src/math/CMakeLists.txt            |  6 ------
 libc/test/src/math/exhaustive/CMakeLists.txt | 16 ----------------
 libc/test/src/math/smoke/CMakeLists.txt      |  8 --------
 libc/test/src/stdfix/CMakeLists.txt          | 16 ----------------
 4 files changed, 46 deletions(-)

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 764dd56d95b138..6dfe1cf5aeccaf 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2029,8 +2029,6 @@ add_fp_unittest(
   DEPENDS
     libc.src.math.sqrtf
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
@@ -2045,8 +2043,6 @@ add_fp_unittest(
   DEPENDS
     libc.src.math.sqrt
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
@@ -2061,8 +2057,6 @@ add_fp_unittest(
   DEPENDS
     libc.src.math.sqrtl
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index bc5873bb31f92b..d31dd4e71f4be6 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -337,8 +337,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     fmabf16_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.math.fmabf16
@@ -420,8 +418,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     hypotbf16_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.math.hypotbf16
@@ -438,8 +434,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     hypotf_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.math.hypotf
@@ -456,8 +450,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     hypotf16_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.math.hypotf16
@@ -773,8 +765,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     bfloat16_add_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.__support.FPUtil.bfloat16
@@ -791,8 +781,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     bfloat16_div_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.__support.FPUtil.bfloat16
@@ -809,8 +797,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     bfloat16_mul_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.__support.FPUtil.bfloat16
@@ -827,8 +813,6 @@ add_fp_unittest(
     libc_math_exhaustive_tests
   SRCS
     bfloat16_sub_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     .exhaustive_test
     libc.src.__support.FPUtil.bfloat16
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index ca299171fc6b8f..b0d37f169b6fa2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3699,8 +3699,6 @@ add_fp_unittest(
     SqrtTest.h
   DEPENDS
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
@@ -3713,8 +3711,6 @@ add_fp_unittest(
     SqrtTest.h
   DEPENDS
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
@@ -3727,8 +3723,6 @@ add_fp_unittest(
     SqrtTest.h
   DEPENDS
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
@@ -3745,8 +3739,6 @@ add_fp_unittest(
     libc.src.math.sqrtf128
     libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.generic.sqrt
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index f669c237481775..70b7cb519c9116 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -13,8 +13,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
       AbsTest.h
     SRCS
       abs${suffix}_test.cpp
-    COMPILE_OPTIONS
-      ${libc_opt_high_flag}
     DEPENDS
       libc.src.stdfix.abs${suffix}
       libc.src.__support.fixed_point.fx_bits
@@ -30,8 +28,6 @@ foreach(suffix IN ITEMS uhr ur ulr uhk uk)
       SqrtTest.h
     SRCS
       sqrt${suffix}_test.cpp
-    COMPILE_OPTIONS
-      ${libc_opt_high_flag}
     DEPENDS
       libc.src.stdfix.sqrt${suffix}
       libc.src.__support.CPP.bit
@@ -51,8 +47,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
       RoundTest.h
     SRCS
       round${suffix}_test.cpp
-    COMPILE_OPTIONS
-      ${libc_opt_high_flag}
     DEPENDS
       libc.src.stdfix.round${suffix}
       libc.src.__support.fixed_point.fx_bits
@@ -66,8 +60,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
       FxBitsTest.h
     SRCS
       ${suffix}bits_test.cpp
-    COMPILE_OPTIONS
-      ${libc_opt_high_flag}
     DEPENDS
       libc.src.stdfix.${suffix}bits
       libc.src.__support.CPP.bit
@@ -172,8 +164,6 @@ add_libc_test(
     ISqrtTest.h
   SRCS
     uhksqrtus_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     libc.src.stdfix.uhksqrtus
     libc.src.__support.CPP.bit
@@ -191,8 +181,6 @@ add_libc_test(
     ISqrtTest.h
   SRCS
     uksqrtui_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     libc.src.stdfix.uksqrtui
     libc.src.__support.CPP.bit
@@ -210,8 +198,6 @@ add_libc_test(
     ExpTest.h
   SRCS
     exphk_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     libc.src.stdfix.exphk
     libc.src.math.exp
@@ -228,8 +214,6 @@ add_libc_test(
     ExpTest.h
   SRCS
     expk_test.cpp
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
   DEPENDS
     libc.src.stdfix.expk
     libc.src.math.exp

>From 3832b27aa4c577aeddf2bab149a1333d22846a65 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 21 Oct 2026 13:57:46 -0700
Subject: [PATCH 2/3] [libc][cmake] Respect the configured optimization level
 for hash_test and the MPFR wrappers

Same cleanup as the math and stdfix tests: drop the remaining optimization overrides on the test side so they use the optimization level configured by CMake.
---
 libc/test/src/__support/CMakeLists.txt | 2 --
 libc/utils/MPFRWrapper/CMakeLists.txt  | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 765eec6b421780..0b5b559cf92995 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -286,8 +286,6 @@ add_libc_test(
     libc.src.stdlib.rand
     libc.src.stdlib.srand
     libc.src.string.memset
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_libc_test(
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 53ad5ef4aa48cd..ad5cbe5eabf713 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -7,7 +7,7 @@ if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
   _get_common_test_compile_options(compile_options "" "")
   # mpfr/gmp headers do not work with -ffreestanding flag.
   list(REMOVE_ITEM compile_options "-ffreestanding")
-  target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
+  target_compile_options(libcMPCommon PRIVATE ${compile_options})
   add_dependencies(
     libcMPCommon
     libc.hdr.stdint_proxy
@@ -38,7 +38,7 @@ if(LIBC_TESTS_CAN_USE_MPFR)
   _get_common_test_compile_options(compile_options "" "")
   # mpfr/gmp headers do not work with -ffreestanding flag.
   list(REMOVE_ITEM compile_options "-ffreestanding")
-  target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
+  target_compile_options(libcMPFRWrapper PRIVATE ${compile_options})
   add_dependencies(
     libcMPFRWrapper
     libcMPCommon

>From aa397ebfd9bcf0caf6449c8032362e9e434f9ada Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 21 Oct 2026 13:58:34 -0700
Subject: [PATCH 3/3] [libc][cmake] Respect the configured optimization level
 for the Linux thread and TLS objects

The -O3 override on the Linux thread object dates from the old approach of
reading the thread arguments off the new thread's stack, which #225384
removed; the TLS objects copied the same pattern in #225418. Neither needs
it anymore, so drop the overrides and use the optimization level configured
by CMake.
---
 libc/src/__support/threads/linux/CMakeLists.txt         | 2 --
 libc/src/__support/threads/linux/aarch64/CMakeLists.txt | 1 -
 libc/src/__support/threads/linux/riscv/CMakeLists.txt   | 1 -
 libc/src/__support/threads/linux/x86_64/CMakeLists.txt  | 1 -
 4 files changed, 5 deletions(-)

diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index a8bcbae5b08dd7..2e539d4895835b 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -90,8 +90,6 @@ add_object_library(
     libc.src.__support.OSUtil.linux.syscall_wrappers.write
     libc.src.__support.threads.thread_common
     libc.src.__support.threads.thread_attributes
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
 )
 
 add_header_library(
diff --git a/libc/src/__support/threads/linux/aarch64/CMakeLists.txt b/libc/src/__support/threads/linux/aarch64/CMakeLists.txt
index e6e92d814cc0a8..a2320f8d015c38 100644
--- a/libc/src/__support/threads/linux/aarch64/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/aarch64/CMakeLists.txt
@@ -13,7 +13,6 @@ add_object_library(
     libc.src.__support.threads.linux.tcb
     libc.src.string.memory_utils.inline_memcpy
   COMPILE_OPTIONS
-    ${libc_opt_high_flag}
     -fno-stack-protector
     -fno-omit-frame-pointer
     -ffreestanding
diff --git a/libc/src/__support/threads/linux/riscv/CMakeLists.txt b/libc/src/__support/threads/linux/riscv/CMakeLists.txt
index e6e92d814cc0a8..a2320f8d015c38 100644
--- a/libc/src/__support/threads/linux/riscv/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/riscv/CMakeLists.txt
@@ -13,7 +13,6 @@ add_object_library(
     libc.src.__support.threads.linux.tcb
     libc.src.string.memory_utils.inline_memcpy
   COMPILE_OPTIONS
-    ${libc_opt_high_flag}
     -fno-stack-protector
     -fno-omit-frame-pointer
     -ffreestanding
diff --git a/libc/src/__support/threads/linux/x86_64/CMakeLists.txt b/libc/src/__support/threads/linux/x86_64/CMakeLists.txt
index 0b49ca2c7e6e33..cfd58503320086 100644
--- a/libc/src/__support/threads/linux/x86_64/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/x86_64/CMakeLists.txt
@@ -14,7 +14,6 @@ add_object_library(
     libc.src.__support.threads.linux.tcb
     libc.src.string.memory_utils.inline_memcpy
   COMPILE_OPTIONS
-    ${libc_opt_high_flag}
     -fno-stack-protector
     -fno-omit-frame-pointer
     -ffreestanding



More information about the libc-commits mailing list