Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions libcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,6 @@ 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_SUPPORTED_C_LIBRARIES system llvm-libc)
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_LIBC}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}.")
endif()

# ABI Library options ---------------------------------------------------------
if (MSVC)
set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime")
Expand Down
39 changes: 0 additions & 39 deletions libcxx/cmake/Modules/HandleLibC.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,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-libc-headers libcxx-abi-headers)
target_link_libraries(cxx-headers INTERFACE runtimes-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.
Expand Down
4 changes: 2 additions & 2 deletions libcxx/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ include(FindLibcCommonUtils)
# Build the shared library.
add_library(cxx_shared SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_shared PUBLIC cxx-headers libcxx-libc-shared
target_link_libraries(cxx_shared PUBLIC cxx-headers runtimes-libc-shared
PRIVATE ${LIBCXX_LIBRARIES}
PRIVATE llvm-libc-common-utilities)
set_target_properties(cxx_shared
Expand Down Expand Up @@ -266,7 +266,7 @@ set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
# Build the static library.
add_library(cxx_static STATIC ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(cxx_static PUBLIC cxx-headers libcxx-libc-static
target_link_libraries(cxx_static PUBLIC cxx-headers runtimes-libc-static
PRIVATE ${LIBCXX_LIBRARIES}
PRIVATE libcxx-abi-static
PRIVATE llvm-libc-common-utilities)
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ add_library_flags("${LIBCXXABI_ADDITIONAL_LIBRARIES}")
# Configure compiler. Must happen after setting the target flags.
include(config-ix)

include(HandleLibC) # Setup the C library flags

if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
# cmake 3.14 and above remove system include paths that are explicitly
Expand Down
39 changes: 39 additions & 0 deletions libcxxabi/cmake/Modules/HandleLibC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#===============================================================================
# Define targets for linking against the selected C library
#
# After including this file, the following targets are defined:
# - libcxxabi-libc-headers: An interface target that allows getting access to the
# headers of the selected C library.
# - libcxxabi-libc-shared: A target representing the selected shared C library.
# - libcxxabi-libc-static: A target representing the selected static C library.
#===============================================================================

# Link against a system-provided libc
if (LIBCXXABI_LIBC STREQUAL "system")
add_library(libcxxabi-libc-headers INTERFACE)

add_library(libcxxabi-libc-static INTERFACE)
add_library(libcxxabi-libc-shared INTERFACE)

# Link against the in-tree LLVM libc
elseif (LIBCXXABI_LIBC STREQUAL "llvm-libc")
add_library(libcxxabi-libc-headers INTERFACE)
target_link_libraries(libcxxabi-libc-headers INTERFACE libc-headers)
if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
target_compile_options(libcxxabi-libc-headers INTERFACE "-nostdlibinc")
endif()

add_library(libcxxabi-libc-static INTERFACE)
if (TARGET libc)
target_link_libraries(libcxxabi-libc-static INTERFACE libc)
endif()
if (TARGET libm)
target_link_libraries(libcxxabi-libc-static INTERFACE libm)
endif()
if (CXX_SUPPORTS_NOLIBC_FLAG)
target_link_options(libcxxabi-libc-static INTERFACE "-nolibc")
endif()

# TODO: There's no support for building LLVM libc as a shared library yet.
add_library(libcxxabi-libc-shared INTERFACE)
endif()
14 changes: 8 additions & 6 deletions libcxxabi/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared)
endif()
endif()
target_link_libraries(cxxabi_shared_objects PRIVATE cxx-headers ${LIBCXXABI_LIBRARIES})
target_link_libraries(cxxabi_shared_objects
PUBLIC cxxabi-headers
PRIVATE cxx-headers runtimes-libc-headers ${LIBCXXABI_LIBRARIES})
if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG)
target_link_libraries(cxxabi_shared_objects PRIVATE ${LIBCXXABI_BUILTINS_LIBRARY})
endif()
target_link_libraries(cxxabi_shared_objects PUBLIC cxxabi-headers)
set_target_properties(cxxabi_shared_objects
PROPERTIES
CXX_EXTENSIONS OFF
Expand Down Expand Up @@ -215,7 +216,7 @@ if (ZOS)
endif ()

target_link_libraries(cxxabi_shared
PUBLIC cxxabi_shared_objects
PUBLIC cxxabi_shared_objects runtimes-libc-shared
PRIVATE ${LIBCXXABI_LIBRARIES})

if (LIBCXXABI_ENABLE_SHARED)
Expand Down Expand Up @@ -274,8 +275,9 @@ if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC
target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements
target_sources(cxxabi_static_objects PUBLIC $<TARGET_OBJECTS:unwind_static_objects>)
endif()
target_link_libraries(cxxabi_static_objects PRIVATE cxx-headers ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
target_link_libraries(cxxabi_static_objects PUBLIC cxxabi-headers)
target_link_libraries(cxxabi_static_objects
PUBLIC cxxabi-headers
PRIVATE cxx-headers runtimes-libc-headers ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
set_target_properties(cxxabi_static_objects
PROPERTIES
CXX_EXTENSIONS OFF
Expand Down Expand Up @@ -311,7 +313,7 @@ endif()

add_library(cxxabi_static STATIC)
if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
target_link_libraries(cxxabi_static PUBLIC unwind_static)
target_link_libraries(cxxabi_static PUBLIC unwind_static runtimes-libc-static)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises an interesting question: right now, we link a static libc (let's call it libc.a) into libunwind.a, and libc.so into libunwind.so. Similarly, libc++abi.so gets libc.so and libc++abi.a gets libc.a, and same for libc++.

However, it would in theory make sense to allow e.g. libc++.so to use libc.a. This is a bit like we allow linking libc++.so against libc++abi.a if desired.

I'm not saying this patch has to fix that shortcoming since it's a pre-existing condition in libc++, but that should be on our radar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this is eventually going to come up but there's additional complexity we'll need to figure out: libc.a that's intended for static linking could be compiled as -fPIE but libc.a that's intended for linking into shared libraries (such as libc++abi.so or libc++.so) must be compiled as -fPIC.

endif()
set_target_properties(cxxabi_static
PROPERTIES
Expand Down
2 changes: 2 additions & 0 deletions libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ include(HandleLibunwindFlags)
# Configure compiler.
include(config-ix)

include(HandleLibC) # Setup the C library flags

if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt")
endif()
Expand Down
39 changes: 39 additions & 0 deletions libunwind/cmake/Modules/HandleLibC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#===============================================================================
# Define targets for linking against the selected C library
#
# After including this file, the following targets are defined:
# - libunwind-libc-headers: An interface target that allows getting access to the
# headers of the selected C library.
# - libunwind-libc-shared: A target representing the selected shared C library.
# - libunwind-libc-static: A target representing the selected static C library.
#===============================================================================

# Link against a system-provided libc
if (LIBUNWIND_LIBC STREQUAL "system")
add_library(libunwind-libc-headers INTERFACE)

add_library(libunwind-libc-static INTERFACE)
add_library(libunwind-libc-shared INTERFACE)

# Link against the in-tree LLVM libc
elseif (LIBUNWIND_LIBC STREQUAL "llvm-libc")
add_library(libunwind-libc-headers INTERFACE)
target_link_libraries(libunwind-libc-headers INTERFACE libc-headers)
if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
target_compile_options(libunwind-libc-headers INTERFACE "-nostdlibinc")
endif()

add_library(libunwind-libc-static INTERFACE)
if (TARGET libc)
target_link_libraries(libunwind-libc-static INTERFACE libc)
endif()
if (TARGET libm)
target_link_libraries(libunwind-libc-static INTERFACE libm)
endif()
if (CXX_SUPPORTS_NOLIBC_FLAG)
target_link_options(libunwind-libc-static INTERFACE "-nolibc")
endif()

# TODO: There's no support for building LLVM libc as a shared library yet.
add_library(libunwind-libc-shared INTERFACE)
endif()
14 changes: 8 additions & 6 deletions libunwind/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
else()
target_compile_options(unwind_shared_objects PRIVATE -fno-rtti)
endif()
target_link_libraries(unwind_shared_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
target_link_libraries(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
target_link_libraries(unwind_shared_objects
PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}"
PRIVATE unwind-headers runtimes-libc-headers ${LIBUNWIND_LIBRARIES})
set_target_properties(unwind_shared_objects
PROPERTIES
CXX_EXTENSIONS OFF
Expand All @@ -175,7 +176,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
endif()

add_library(unwind_shared SHARED)
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects runtimes-libc-shared)
set_target_properties(unwind_shared
PROPERTIES
EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_SHARED}>,FALSE,TRUE>"
Expand All @@ -201,9 +202,10 @@ if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
else()
target_compile_options(unwind_static_objects PRIVATE -fno-rtti)
endif()
target_link_libraries(unwind_static_objects PRIVATE unwind-headers ${LIBUNWIND_LIBRARIES})
target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}")
target_link_libraries(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}")
target_link_libraries(unwind_static_objects
PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}"
PRIVATE unwind-headers runtimes-libc-headers ${LIBUNWIND_LIBRARIES})
set_target_properties(unwind_static_objects
PROPERTIES
CXX_EXTENSIONS OFF
Expand All @@ -222,7 +224,7 @@ if(LIBUNWIND_HIDE_SYMBOLS)
endif()

add_library(unwind_static STATIC)
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
target_link_libraries(unwind_static PUBLIC unwind_static_objects runtimes-libc-static)
set_target_properties(unwind_static
PROPERTIES
EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_STATIC}>,FALSE,TRUE>"
Expand Down
46 changes: 46 additions & 0 deletions runtimes/cmake/Modules/HandleLibC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#===============================================================================
# Define targets for linking against the selected C library
#
# After including this file, the following targets are defined:
# - runtimes-libc-headers: An interface target that allows getting access to the
# headers of the selected C library.
# - runtimes-libc-shared: A target representing the selected shared C library.
# - runtimes-libc-static: A target representing the selected static C library.
#===============================================================================

set(RUNTIMES_SUPPORTED_C_LIBRARIES system llvm-libc)
set(RUNTIMES_USE_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${RUNTIMES_SUPPORTED_C_LIBRARIES}.")
if (NOT "${RUNTIMES_USE_LIBC}" IN_LIST RUNTIMES_SUPPORTED_C_LIBRARIES)
message(FATAL_ERROR "Unsupported C library: '${RUNTIMES_CXX_ABI}'. Supported values are ${RUNTIMES_SUPPORTED_C_LIBRARIES}.")
endif()

# Link against a system-provided libc
if (RUNTIMES_USE_LIBC STREQUAL "system")
add_library(runtimes-libc-headers INTERFACE)

add_library(runtimes-libc-static INTERFACE)
add_library(runtimes-libc-shared INTERFACE)

# Link against the in-tree LLVM libc
elseif (RUNTIMES_USE_LIBC STREQUAL "llvm-libc")
add_library(runtimes-libc-headers INTERFACE)
target_link_libraries(runtimes-libc-headers INTERFACE libc-headers)
check_cxx_compiler_flag(-nostdlibinc CXX_SUPPORTS_NOSTDLIBINC_FLAG)
if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
target_compile_options(runtimes-libc-headers INTERFACE "-nostdlibinc")
endif()

add_library(runtimes-libc-static INTERFACE)
if (TARGET libc)
target_link_libraries(runtimes-libc-static INTERFACE libc)
endif()
if (TARGET libm)
target_link_libraries(runtimes-libc-static INTERFACE libm)
endif()
if (CXX_SUPPORTS_NOLIBC_FLAG)
target_link_options(runtimes-libc-static INTERFACE "-nolibc")
endif()

# TODO: There's no support for building LLVM libc as a shared library yet.
add_library(runtimes-libc-shared INTERFACE)
endif()
Loading