[libc-commits] [clang] [libc] [libcxx] [libc][libcxx] Support for building libc++ against LLVM libc (PR #99287)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Thu Jul 18 10:45:22 PDT 2024
https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/99287
>From 7d7a7882b713e056f9194b2dd7d792fb9bb86bb5 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 17 Jul 2024 00:32:39 -0700
Subject: [PATCH 1/6] [libc][libcxx] Support for building libc++ against LLVM
libc
Provide an option to build libc++ against LLVM libc and set the CMake
compile and link options appropriately when the option is enabled.
---
clang/cmake/caches/Fuchsia-stage2.cmake | 2 ++
libc/cmake/modules/CheckCompilerFeatures.cmake | 3 +++
libc/include/CMakeLists.txt | 3 +++
libc/lib/CMakeLists.txt | 5 ++++-
libcxx/CMakeLists.txt | 1 +
libcxx/include/CMakeLists.txt | 3 +++
libcxx/src/CMakeLists.txt | 10 ++++++++++
7 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index b4561e6c87ba5..dc9b596b4ba8f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -338,6 +338,7 @@ foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+ set(RUNTIMES_${target}_LIBCXX_USE_LLVM_LIBC ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -388,6 +389,7 @@ foreach(target riscv32-unknown-elf)
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
+ set(RUNTIMES_${target}_LIBCXX_USE_LLVM_LIBC ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index a6d793d495c45..d64d9de97af3c 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -102,3 +102,6 @@ check_cxx_compiler_flag("-nostdlib++" LIBC_CC_SUPPORTS_NOSTDLIBPP)
# clang-3.0+
check_cxx_compiler_flag("-nostdlibinc" LIBC_CC_SUPPORTS_NOSTDLIBINC)
+
+# clang-3.0+
+check_cxx_compiler_flag("-nolibc" LIBC_CC_SUPPORTS_NOLIBC)
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 2cf7206f3a625..d521e205df8c3 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -664,6 +664,9 @@ get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADER
add_library(libc-headers INTERFACE)
add_dependencies(libc-headers ${all_install_header_targets})
target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
+if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
+ target_compile_options(libc-headers INTERFACE "-nostdlibinc")
+endif()
foreach(target IN LISTS all_install_header_targets)
get_target_property(header_file ${target} HEADER_FILE_PATH)
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index 37acf3950b460..7e18f35e7d60e 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -30,7 +30,10 @@ foreach(archive IN ZIP_LISTS
ARCHIVE_OUTPUT_NAME ${archive_0}
)
if(LLVM_LIBC_FULL_BUILD)
- target_link_libraries(${archive_1} PUBLIC libc-headers)
+ target_link_libraries(${archive_1} INTERFACE libc-headers)
+ if(LIBC_CC_SUPPORTS_NOLIBC)
+ target_link_options(${archive_1} INTERFACE "-nolibc")
+ endif()
if(TARGET libc-startup)
add_dependencies(${archive_1} libc-startup)
endif()
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 190a97db9462f..5a568e95b239e 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -293,6 +293,7 @@ option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
option(LIBCXX_ENABLE_MONOTONIC_CLOCK
"Build libc++ with support for a monotonic clock.
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
+option(LIBCXX_USE_LLVM_LIBC "Build libc++ against LLVM libc." OFF)
option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index cd64fe91449c2..31a819932d521 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1043,6 +1043,9 @@ add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})
add_library(cxx-headers INTERFACE)
target_link_libraries(cxx-headers INTERFACE libcxx-abi-headers)
+if (LIBCXX_USE_LLVM_LIBC)
+ target_link_libraries(cxx-headers INTERFACE libc-headers)
+endif()
add_dependencies(cxx-headers generate-cxx-headers)
# It's important that the arch directory be included first so that its header files
# which interpose on the default include dir be included instead of the default ones.
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 0ae58a10c879c..536a5a16ad7e1 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -229,6 +229,11 @@ if (LIBCXX_ENABLE_SHARED)
target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared)
endif()
+ # Link against LLVM libc.
+ if (LIBCXX_USE_LLVM_LIBC)
+ target_link_libraries(cxx_shared PUBLIC libc libm)
+ endif()
+
# Maybe re-export symbols from libc++abi
# In particular, we don't re-export the symbols if libc++abi is merged statically
# into libc++ because in that case there's no dylib to re-export from.
@@ -324,6 +329,11 @@ if (LIBCXX_ENABLE_STATIC)
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
endif()
+
+ # Link against LLVM libc.
+ if (LIBCXX_USE_LLVM_LIBC)
+ target_link_libraries(cxx_static PUBLIC libc libm)
+ endif()
endif()
# Add a meta-target for both libraries.
>From 76e5e026490f505303ed054abb9eb275eb571e58 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 17 Jul 2024 11:43:23 -0700
Subject: [PATCH 2/6] Introduce the LIBCXX_LIBC option
---
clang/cmake/caches/Fuchsia-stage2.cmake | 4 +--
libcxx/CMakeLists.txt | 15 +++++++-
libcxx/cmake/Modules/HandleLibC.cmake | 34 +++++++++++++++++++
libcxx/cmake/config-ix.cmake | 3 ++
libcxx/include/CMakeLists.txt | 5 +--
libcxx/include/__config_site.in | 1 +
libcxx/include/__locale_dir/locale_base_api.h | 2 ++
.../__locale_dir/locale_base_api/llvm_libc.h | 17 ++++++++++
libcxx/src/CMakeLists.txt | 15 ++------
9 files changed, 77 insertions(+), 19 deletions(-)
create mode 100644 libcxx/cmake/Modules/HandleLibC.cmake
create mode 100644 libcxx/include/__locale_dir/locale_base_api/llvm_libc.h
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index dc9b596b4ba8f..840ff46ef0a1f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -338,7 +338,7 @@ foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
- set(RUNTIMES_${target}_LIBCXX_USE_LLVM_LIBC ON CACHE BOOL "")
+ set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -389,7 +389,7 @@ foreach(target riscv32-unknown-elf)
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
- set(RUNTIMES_${target}_LIBCXX_USE_LLVM_LIBC ON CACHE BOOL "")
+ set(RUNTIMES_${target}_LIBCXX_LIBC "llvm-libc" CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 5a568e95b239e..463d69df121f8 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -226,6 +226,15 @@ set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros
set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site")
option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
+# C Library options -----------------------------------------------------------
+
+set(LIBCXX_DEFAULT_C_LIBRARY system)
+set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
+set(LIBCXX_LIBC "${LIBCXX_DEFAULT_C_LIBRARY}" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
+if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
+ message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
+endif()
+
# ABI Library options ---------------------------------------------------------
if (MSVC)
set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
@@ -293,7 +302,6 @@ option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
option(LIBCXX_ENABLE_MONOTONIC_CLOCK
"Build libc++ with support for a monotonic clock.
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
-option(LIBCXX_USE_LLVM_LIBC "Build libc++ against LLVM libc." OFF)
option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
@@ -510,6 +518,7 @@ endif()
# Setup Compiler Flags
#===============================================================================
+include(HandleLibC) # Setup the C library flags
include(HandleLibCXXABI) # Setup the ABI library flags
# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
@@ -785,6 +794,10 @@ config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTER
config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
+if (LIBCXX_LIBC STREQUAL "llvm-libc")
+ config_define(ON _LIBCPP_HAS_LLVM_LIBC)
+endif()
+
if (LIBCXX_ENABLE_ASSERTIONS)
message(DEPRECATION "LIBCXX_ENABLE_ASSERTIONS is deprecated and will be removed in LLVM 20. Please use LIBCXX_HARDENING_MODE instead.")
set(LIBCXX_HARDENING_MODE "extensive")
diff --git a/libcxx/cmake/Modules/HandleLibC.cmake b/libcxx/cmake/Modules/HandleLibC.cmake
new file mode 100644
index 0000000000000..f2f23bce30d8a
--- /dev/null
+++ b/libcxx/cmake/Modules/HandleLibC.cmake
@@ -0,0 +1,34 @@
+#===============================================================================
+# Define targets for linking against the selected C library
+#
+# After including this file, the following targets are defined:
+# - libcxx-libc-headers: An interface target that allows getting access to the
+# headers of the selected C library.
+# - libcxx-libc-shared: A target representing the selected shared C library.
+# - libcxx-libm-shared: A target representing the selected shared C math library.
+# - libcxx-libc-static: A target representing the selected static C library.
+# - libcxx-libm-static: A target representing the selected static C math library.
+#===============================================================================
+
+# Link against a system-provided libc
+if (LIBCXX_LIBC STREQUAL "system")
+ add_library(libcxx-libc-headers INTERFACE)
+
+ add_library(libcxx-libc-static INTERFACE)
+ add_library(libcxx-libm-static INTERFACE)
+
+ add_library(libcxx-libc-shared INTERFACE)
+ add_library(libcxx-libm-shared INTERFACE)
+
+# Link against the in-tree LLVM libc
+elseif (LIBCXX_LIBC STREQUAL "llvm-libc")
+ add_library(libcxx-libc-headers INTERFACE)
+ target_link_libraries(libcxx-libc-headers INTERFACE libc-headers)
+
+ add_library(libcxx-libc-static ALIAS libc)
+ add_library(libcxx-libm-static ALIAS libm)
+
+ # TODO: There's no support for building LLVM libc as a shared library yet.
+ add_library(libcxx-libc-shared INTERFACE)
+ add_library(libcxx-libm-shared INTERFACE)
+endif()
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 7406fba482e69..998819604de28 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -27,6 +27,9 @@ if (NOT LIBCXX_USE_COMPILER_RT)
endif()
endif()
+check_cxx_compiler_flag(-nostdlibinc CXX_SUPPORTS_NOSTDLIBINC_FLAG)
+check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
+
# libc++ is using -nostdlib++ at the link step when available,
# otherwise -nodefaultlibs is used. We want all our checks to also
# use one of these options, otherwise we may end up with an inconsistency between
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 31a819932d521..77ca67b967519 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1042,10 +1042,7 @@ list(APPEND _all_includes "${LIBCXX_GENERATED_INCLUDE_DIR}/libcxx.imp")
add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})
add_library(cxx-headers INTERFACE)
-target_link_libraries(cxx-headers INTERFACE libcxx-abi-headers)
-if (LIBCXX_USE_LLVM_LIBC)
- target_link_libraries(cxx-headers INTERFACE libc-headers)
-endif()
+target_link_libraries(cxx-headers INTERFACE libcxx-libc-headers libcxx-abi-headers)
add_dependencies(cxx-headers generate-cxx-headers)
# It's important that the arch directory be included first so that its header files
# which interpose on the default include dir be included instead of the default ones.
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index 67022146c9082..8d13d754da5e0 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -16,6 +16,7 @@
#cmakedefine _LIBCPP_HAS_NO_THREADS
#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
#cmakedefine _LIBCPP_HAS_MUSL_LIBC
+#cmakedefine _LIBCPP_HAS_LLVM_LIBC
#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index 8c000c558c527..e583b7bd81e0b 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -25,6 +25,8 @@
# include <__locale_dir/locale_base_api/fuchsia.h>
#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
# include <__locale_dir/locale_base_api/musl.h>
+#elif defined(_LIBCPP_HAS_LLVM_LIBC)
+# include <__locale_dir/locale_base_api/llvm_libc.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
# include <xlocale.h>
#endif
diff --git a/libcxx/include/__locale_dir/locale_base_api/llvm_libc.h b/libcxx/include/__locale_dir/locale_base_api/llvm_libc.h
new file mode 100644
index 0000000000000..fc2f19f18bcfc
--- /dev/null
+++ b/libcxx/include/__locale_dir/locale_base_api/llvm_libc.h
@@ -0,0 +1,17 @@
+// -*- C++ -*-
+//===-----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_LLVM_LIBC_H
+#define _LIBCPP___LOCALE_LOCALE_BASE_API_LLVM_LIBC_H
+
+#include <__support/xlocale/__nop_locale_mgmt.h>
+#include <__support/xlocale/__strtonum_fallback.h>
+#include <cstdlib>
+
+#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_LLVM_LIBC_H
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 536a5a16ad7e1..79616cad39e2e 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -200,7 +200,8 @@ if (LIBCXX_ENABLE_SHARED)
add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_shared PUBLIC cxx-headers
- PRIVATE ${LIBCXX_LIBRARIES})
+ PRIVATE ${LIBCXX_LIBRARIES}
+ PRIVATE libcxx-libc-shared libcxx-libm-shared)
set_target_properties(cxx_shared
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
@@ -229,11 +230,6 @@ if (LIBCXX_ENABLE_SHARED)
target_link_libraries(cxx_shared PUBLIC libcxx-abi-shared)
endif()
- # Link against LLVM libc.
- if (LIBCXX_USE_LLVM_LIBC)
- target_link_libraries(cxx_shared PUBLIC libc libm)
- endif()
-
# Maybe re-export symbols from libc++abi
# In particular, we don't re-export the symbols if libc++abi is merged statically
# into libc++ because in that case there's no dylib to re-export from.
@@ -299,7 +295,7 @@ if (LIBCXX_ENABLE_STATIC)
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_static PUBLIC cxx-headers
PRIVATE ${LIBCXX_LIBRARIES}
- PRIVATE libcxx-abi-static)
+ PRIVATE libcxx-libc-static libcxx-libm-static libcxx-abi-static)
set_target_properties(cxx_static
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
@@ -329,11 +325,6 @@ if (LIBCXX_ENABLE_STATIC)
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
endif()
-
- # Link against LLVM libc.
- if (LIBCXX_USE_LLVM_LIBC)
- target_link_libraries(cxx_static PUBLIC libc libm)
- endif()
endif()
# Add a meta-target for both libraries.
>From c6ca8cfda76105847b18a3a2fe18481971c6ab1f Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Thu, 18 Jul 2024 10:36:27 -0700
Subject: [PATCH 3/6] Review feedback
---
.../__locale_dir/locale_base_api/llvm_libc.h | 17 -----------------
1 file changed, 17 deletions(-)
delete mode 100644 libcxx/include/__locale_dir/locale_base_api/llvm_libc.h
diff --git a/libcxx/include/__locale_dir/locale_base_api/llvm_libc.h b/libcxx/include/__locale_dir/locale_base_api/llvm_libc.h
deleted file mode 100644
index fc2f19f18bcfc..0000000000000
--- a/libcxx/include/__locale_dir/locale_base_api/llvm_libc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// -*- C++ -*-
-//===-----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_LLVM_LIBC_H
-#define _LIBCPP___LOCALE_LOCALE_BASE_API_LLVM_LIBC_H
-
-#include <__support/xlocale/__nop_locale_mgmt.h>
-#include <__support/xlocale/__strtonum_fallback.h>
-#include <cstdlib>
-
-#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_LLVM_LIBC_H
>From 1418ea8280112f775e55c8446aa01609e9a52e4a Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Thu, 18 Jul 2024 10:38:56 -0700
Subject: [PATCH 4/6] Review feedback
---
libc/include/CMakeLists.txt | 3 ---
libc/lib/CMakeLists.txt | 3 ---
libcxx/CMakeLists.txt | 7 +------
libcxx/cmake/Modules/HandleLibC.cmake | 21 ++++++++++++-------
libcxx/include/__config_site.in | 1 -
libcxx/include/__locale_dir/locale_base_api.h | 2 --
libcxx/src/CMakeLists.txt | 4 ++--
7 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index d521e205df8c3..2cf7206f3a625 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -664,9 +664,6 @@ get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADER
add_library(libc-headers INTERFACE)
add_dependencies(libc-headers ${all_install_header_targets})
target_include_directories(libc-headers SYSTEM INTERFACE ${LIBC_INCLUDE_DIR})
-if(LIBC_CC_SUPPORTS_NOSTDLIBINC)
- target_compile_options(libc-headers INTERFACE "-nostdlibinc")
-endif()
foreach(target IN LISTS all_install_header_targets)
get_target_property(header_file ${target} HEADER_FILE_PATH)
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index 7e18f35e7d60e..dd26227ea21eb 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -31,9 +31,6 @@ foreach(archive IN ZIP_LISTS
)
if(LLVM_LIBC_FULL_BUILD)
target_link_libraries(${archive_1} INTERFACE libc-headers)
- if(LIBC_CC_SUPPORTS_NOLIBC)
- target_link_options(${archive_1} INTERFACE "-nolibc")
- endif()
if(TARGET libc-startup)
add_dependencies(${archive_1} libc-startup)
endif()
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 463d69df121f8..9982c0940423d 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -228,9 +228,8 @@ option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
# C Library options -----------------------------------------------------------
-set(LIBCXX_DEFAULT_C_LIBRARY system)
set(LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc)
-set(LIBCXX_LIBC "${LIBCXX_DEFAULT_C_LIBRARY}" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
+set(LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
if (NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES)
message(FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
endif()
@@ -794,10 +793,6 @@ config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTER
config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE)
config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
-if (LIBCXX_LIBC STREQUAL "llvm-libc")
- config_define(ON _LIBCPP_HAS_LLVM_LIBC)
-endif()
-
if (LIBCXX_ENABLE_ASSERTIONS)
message(DEPRECATION "LIBCXX_ENABLE_ASSERTIONS is deprecated and will be removed in LLVM 20. Please use LIBCXX_HARDENING_MODE instead.")
set(LIBCXX_HARDENING_MODE "extensive")
diff --git a/libcxx/cmake/Modules/HandleLibC.cmake b/libcxx/cmake/Modules/HandleLibC.cmake
index f2f23bce30d8a..1b0564ae6fcc6 100644
--- a/libcxx/cmake/Modules/HandleLibC.cmake
+++ b/libcxx/cmake/Modules/HandleLibC.cmake
@@ -5,9 +5,7 @@
# - libcxx-libc-headers: An interface target that allows getting access to the
# headers of the selected C library.
# - libcxx-libc-shared: A target representing the selected shared C library.
-# - libcxx-libm-shared: A target representing the selected shared C math library.
# - libcxx-libc-static: A target representing the selected static C library.
-# - libcxx-libm-static: A target representing the selected static C math library.
#===============================================================================
# Link against a system-provided libc
@@ -15,20 +13,27 @@ if (LIBCXX_LIBC STREQUAL "system")
add_library(libcxx-libc-headers INTERFACE)
add_library(libcxx-libc-static INTERFACE)
- add_library(libcxx-libm-static INTERFACE)
-
add_library(libcxx-libc-shared INTERFACE)
- add_library(libcxx-libm-shared INTERFACE)
# Link against the in-tree LLVM libc
elseif (LIBCXX_LIBC STREQUAL "llvm-libc")
add_library(libcxx-libc-headers INTERFACE)
target_link_libraries(libcxx-libc-headers INTERFACE libc-headers)
+ if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
+ target_compile_options(libcxx-libc-headers INTERFACE "-nostdlibinc")
+ endif()
- add_library(libcxx-libc-static ALIAS libc)
- add_library(libcxx-libm-static ALIAS libm)
+ add_library(libcxx-libc-static INTERFACE)
+ if (TARGET libc)
+ target_link_libraries(libcxx-libc-static INTERFACE libc)
+ endif()
+ if (TARGET libm)
+ target_link_libraries(libcxx-libc-static INTERFACE libm)
+ endif()
+ if (CXX_SUPPORTS_NOLIBC_FLAG)
+ target_link_options(libcxx-libc-static INTERFACE "-nolibc")
+ endif()
# TODO: There's no support for building LLVM libc as a shared library yet.
add_library(libcxx-libc-shared INTERFACE)
- add_library(libcxx-libm-shared INTERFACE)
endif()
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index 8d13d754da5e0..67022146c9082 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -16,7 +16,6 @@
#cmakedefine _LIBCPP_HAS_NO_THREADS
#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
#cmakedefine _LIBCPP_HAS_MUSL_LIBC
-#cmakedefine _LIBCPP_HAS_LLVM_LIBC
#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index e583b7bd81e0b..8c000c558c527 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -25,8 +25,6 @@
# include <__locale_dir/locale_base_api/fuchsia.h>
#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
# include <__locale_dir/locale_base_api/musl.h>
-#elif defined(_LIBCPP_HAS_LLVM_LIBC)
-# include <__locale_dir/locale_base_api/llvm_libc.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
# include <xlocale.h>
#endif
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 79616cad39e2e..059808020ca9b 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -201,7 +201,7 @@ if (LIBCXX_ENABLE_SHARED)
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_shared PUBLIC cxx-headers
PRIVATE ${LIBCXX_LIBRARIES}
- PRIVATE libcxx-libc-shared libcxx-libm-shared)
+ PRIVATE libcxx-libc-shared)
set_target_properties(cxx_shared
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
@@ -295,7 +295,7 @@ if (LIBCXX_ENABLE_STATIC)
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_static PUBLIC cxx-headers
PRIVATE ${LIBCXX_LIBRARIES}
- PRIVATE libcxx-libc-static libcxx-libm-static libcxx-abi-static)
+ PRIVATE libcxx-libc-static libcxx-abi-static)
set_target_properties(cxx_static
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
>From a27eaa4a91405f74d33a3b2744f437265738dd61 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Thu, 18 Jul 2024 10:39:50 -0700
Subject: [PATCH 5/6] Remove unnecessary changes
---
libc/cmake/modules/CheckCompilerFeatures.cmake | 3 ---
libc/lib/CMakeLists.txt | 2 +-
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index d64d9de97af3c..a6d793d495c45 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -102,6 +102,3 @@ check_cxx_compiler_flag("-nostdlib++" LIBC_CC_SUPPORTS_NOSTDLIBPP)
# clang-3.0+
check_cxx_compiler_flag("-nostdlibinc" LIBC_CC_SUPPORTS_NOSTDLIBINC)
-
-# clang-3.0+
-check_cxx_compiler_flag("-nolibc" LIBC_CC_SUPPORTS_NOLIBC)
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index dd26227ea21eb..37acf3950b460 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -30,7 +30,7 @@ foreach(archive IN ZIP_LISTS
ARCHIVE_OUTPUT_NAME ${archive_0}
)
if(LLVM_LIBC_FULL_BUILD)
- target_link_libraries(${archive_1} INTERFACE libc-headers)
+ target_link_libraries(${archive_1} PUBLIC libc-headers)
if(TARGET libc-startup)
add_dependencies(${archive_1} libc-startup)
endif()
>From 177799707f9a2e745c7ec5ebf6a99a7b5dca8cb2 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Thu, 18 Jul 2024 10:45:04 -0700
Subject: [PATCH 6/6] Change dependency visibility
---
libcxx/src/CMakeLists.txt | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 059808020ca9b..4d0eb1a47197c 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -200,8 +200,8 @@ if (LIBCXX_ENABLE_SHARED)
add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_shared PUBLIC cxx-headers
- PRIVATE ${LIBCXX_LIBRARIES}
- PRIVATE libcxx-libc-shared)
+ PUBLIC libcxx-libc-shared
+ PRIVATE ${LIBCXX_LIBRARIES})
set_target_properties(cxx_shared
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
@@ -294,8 +294,9 @@ if (LIBCXX_ENABLE_STATIC)
add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_static PUBLIC cxx-headers
+ PUBLIC libcxx-libc-static
PRIVATE ${LIBCXX_LIBRARIES}
- PRIVATE libcxx-libc-static libcxx-abi-static)
+ PRIVATE libcxx-abi-static)
set_target_properties(cxx_static
PROPERTIES
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
More information about the libc-commits
mailing list