[libc-commits] [libc] [libc][cmake] Use -Os for libc_opt_high_flag in MinSizeRel builds (PR #233920)
Prabhu Rajasekaran via libc-commits
libc-commits at lists.llvm.org
Tue Oct 20 10:50:14 PDT 2026
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/233920
>From 0547882bcd9dd98bb1a47bc12f1e8393e362e1f3 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Tue, 20 Oct 2026 10:35:24 -0700
Subject: [PATCH 1/2] [libc][cmake] Use -Os for libc_opt_high_flag in
MinSizeRel builds
Targets using ${libc_opt_high_flag} currently pass -O3 unconditionally, overriding -Os when CMAKE_BUILD_TYPE is MinSizeRel. Use -Os when CMAKE_BUILD_TYPE is MinSizeRel so size-optimized builds are respected.
---
libc/CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index b6c6b0aa546e2..21acd221beeff 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -579,6 +579,8 @@ endforeach()
if(MSVC AND NOT MSYS)
set(libc_opt_high_flag "/O2")
+elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
+ set(libc_opt_high_flag "-Os")
else()
set(libc_opt_high_flag "-O3")
endif()
>From c576a990cb86216ec3e2548d93b1cd06374cd896 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Tue, 20 Oct 2026 10:47:49 -0700
Subject: [PATCH 2/2] [libc][cmake] Do not set libc_opt_high_flag in MinSizeRel
builds
---
libc/CMakeLists.txt | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 21acd221beeff..6ef59016a4a4a 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -577,12 +577,12 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
endforeach()
-if(MSVC AND NOT MSYS)
- set(libc_opt_high_flag "/O2")
-elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
- set(libc_opt_high_flag "-Os")
-else()
- set(libc_opt_high_flag "-O3")
+if(NOT CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
+ if(MSVC AND NOT MSYS)
+ set(libc_opt_high_flag "/O2")
+ else()
+ set(libc_opt_high_flag "-O3")
+ endif()
endif()
add_subdirectory(include)
More information about the libc-commits
mailing list