[libcxx-commits] [clang] [libcxx] [libcxxabi] [Fuchsia][cmake] Allow using FatLTO when building runtimes (PR #112277)

Paul Kirth via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 14 09:39:01 PST 2024


https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/112277

>From 1dafa521d5a1e10e3f79f63a661b2e14acff5a4a Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Mon, 14 Oct 2024 15:06:38 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 libcxx/CMakeLists.txt        |  4 ++++
 libcxx/src/CMakeLists.txt    | 10 ++++++++++
 libcxxabi/src/CMakeLists.txt | 10 ++++++++++
 3 files changed, 24 insertions(+)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index f1942e963ccc31..5a68237f7336c5 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -102,6 +102,10 @@ option(LIBCXX_ENABLE_WIDE_CHARACTERS
    support the C functionality for wide characters. When wide characters are
    not supported, several parts of the library will be disabled, notably the
    wide character specializations of std::basic_string." ON)
+ option(LIBCXX_ENABLE_FATLTO
+   "Whether to compile libc++ with FatLTO enabled." ON)
+ option(LIBCXX_ENABLE_LTO
+   "Whether to compile libc++ with LTO enabled." ON)
 
 # To use time zone support in libc++ the platform needs to have the IANA
 # database installed. Libc++ will fail to build if this is enabled on a
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index b187677ff2db52..670db758f53173 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -173,6 +173,16 @@ if (APPLE AND LLVM_USE_SANITIZER)
   endif()
 endif()
 
+
+if(LIBCXX_ENABLE_LTO)
+  list(APPEND LIBCXX_COMPILE_FLAGS "-flto")
+  list(APPEND LIBCXX_LINK_FLAGS "-flto")
+endif()
+if(LIBCXX_ENABLE_FATLTO)
+  list(APPEND LIBCXX_COMPILE_FLAGS "-ffat-lto-objects")
+  list(APPEND LIBCXX_LINK_FLAGS "-ffat-lto-objects")
+endif()
+
 split_list(LIBCXX_COMPILE_FLAGS)
 split_list(LIBCXX_LINK_FLAGS)
 
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 480e528b819bb9..822ede39c6a525 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -143,6 +143,15 @@ if ( APPLE )
   endif()
 endif()
 
+if(LIBCXX_ENABLE_LTO)
+  list(APPEND LIBCXXABI_COMPILE_FLAGS "-flto")
+  list(APPEND LIBCXXABI_LINK_FLAGS "-flto")
+endif()
+if(LIBCXX_ENABLE_FATLTO)
+  list(APPEND LIBCXXABI_COMPILE_FLAGS "-ffat-lto-objects")
+  list(APPEND LIBCXXABI_LINK_FLAGS "-ffat-lto-objects")
+endif()
+
 split_list(LIBCXXABI_COMPILE_FLAGS)
 split_list(LIBCXXABI_LINK_FLAGS)
 
@@ -154,6 +163,7 @@ endif()
 
 include(WarningFlags)
 
+
 # Build the shared library.
 add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
 cxx_add_warning_flags(cxxabi_shared_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC})

>From 38851d29d9eaf5e3c597be3f9f57179f308ba335 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Mon, 14 Oct 2024 15:27:36 -0700
Subject: [PATCH 2/3] Remove newline from diff

Created using spr 1.3.4
---
 libcxxabi/src/CMakeLists.txt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 1a1e57aa0077b4..783f17583c62e0 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -163,7 +163,6 @@ endif()
 
 include(WarningFlags)
 
-
 # Build the shared library.
 add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
 cxx_add_warning_flags(cxxabi_shared_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC})

>From 535f2f2c17a3c80aa12c0106a468a8f2127241fc Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Wed, 16 Oct 2024 11:20:51 -0700
Subject: [PATCH 3/3] Avoid unecessary changes to libc++ cmake

Created using spr 1.3.4
---
 clang/cmake/caches/Fuchsia-stage2.cmake |  8 ++++++++
 libcxx/CMakeLists.txt                   |  4 ----
 libcxx/src/CMakeLists.txt               | 10 ----------
 libcxxabi/src/CMakeLists.txt            |  9 ---------
 4 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index 5af98c7b3b3fba..e62f29ecbe6f45 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -192,6 +192,10 @@ foreach(target aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
     set(RUNTIMES_${target}_LLVM_TOOLS_DIR "${CMAKE_BINARY_DIR}/bin" CACHE BOOL "")
     set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 
+    # Enable FatLTO for Linux and baremetal runtimes
+    set(RUNTIMES_${target}_LLVM_ENABLE_LTO ON CACHE BOOL "")
+    set(RUNTIMES_${target}_LLVM_ENABLE_FATLTO ON CACHE BOOL "")
+
     # Use .build-id link.
     list(APPEND RUNTIME_BUILD_ID_LINK "${target}")
   endif()
@@ -274,6 +278,10 @@ if(FUCHSIA_SDK)
     set(RUNTIMES_${target}+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
     set(RUNTIMES_${target}+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
 
+    # Enable FatLTO for Fuchsia runtimes
+    set(RUNTIMES_${target}_LLVM_ENABLE_LTO ON CACHE BOOL "")
+    set(RUNTIMES_${target}_LLVM_ENABLE_FATLTO ON CACHE BOOL "")
+
     # Use .build-id link.
     list(APPEND RUNTIME_BUILD_ID_LINK "${target}")
   endforeach()
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 61c0b411b44ee6..75c926f5432aea 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -102,10 +102,6 @@ option(LIBCXX_ENABLE_WIDE_CHARACTERS
    support the C functionality for wide characters. When wide characters are
    not supported, several parts of the library will be disabled, notably the
    wide character specializations of std::basic_string." ON)
- option(LIBCXX_ENABLE_FATLTO
-   "Whether to compile libc++ with FatLTO enabled." ON)
- option(LIBCXX_ENABLE_LTO
-   "Whether to compile libc++ with LTO enabled." ON)
 
 # To use time zone support in libc++ the platform needs to have the IANA
 # database installed. Libc++ will fail to build if this is enabled on a
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index ddd5142aed08ad..4af04f202db1f7 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -169,16 +169,6 @@ if (APPLE AND LLVM_USE_SANITIZER)
   endif()
 endif()
 
-
-if(LIBCXX_ENABLE_LTO)
-  list(APPEND LIBCXX_COMPILE_FLAGS "-flto")
-  list(APPEND LIBCXX_LINK_FLAGS "-flto")
-endif()
-if(LIBCXX_ENABLE_FATLTO)
-  list(APPEND LIBCXX_COMPILE_FLAGS "-ffat-lto-objects")
-  list(APPEND LIBCXX_LINK_FLAGS "-ffat-lto-objects")
-endif()
-
 split_list(LIBCXX_COMPILE_FLAGS)
 split_list(LIBCXX_LINK_FLAGS)
 
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 783f17583c62e0..84fe2784bec5ca 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -143,15 +143,6 @@ if ( APPLE )
   endif()
 endif()
 
-if(LIBCXX_ENABLE_LTO)
-  list(APPEND LIBCXXABI_COMPILE_FLAGS "-flto")
-  list(APPEND LIBCXXABI_LINK_FLAGS "-flto")
-endif()
-if(LIBCXX_ENABLE_FATLTO)
-  list(APPEND LIBCXXABI_COMPILE_FLAGS "-ffat-lto-objects")
-  list(APPEND LIBCXXABI_LINK_FLAGS "-ffat-lto-objects")
-endif()
-
 split_list(LIBCXXABI_COMPILE_FLAGS)
 split_list(LIBCXXABI_LINK_FLAGS)
 



More information about the libcxx-commits mailing list