Skip to content

Commit

Permalink
[runtimes] Fix the build of merged ABI/unwinder libraries
Browse files Browse the repository at this point in the history
Also, add a CI job that tests this configuration. The exact configuration
is that we build a shared libc++ and merge objects for the ABI library
and the unwinder library into it.

Differential Revision: https://reviews.llvm.org/D125903
  • Loading branch information
ldionne committed May 19, 2022
1 parent e601b2a commit fa7ce8e
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libcxx/CMakeLists.txt
Expand Up @@ -237,11 +237,11 @@ option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY

cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
"Statically link the ABI library to static library" ON
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF)
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY" OFF)

cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
"Statically link the ABI library to shared library" ON
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF)
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY" OFF)

# Generate and install a linker script inplace of libc++.so. The linker script
# will link libc++ to the correct ABI library. This option is on by default
Expand Down
12 changes: 12 additions & 0 deletions libcxx/cmake/caches/Generic-merged.cmake
@@ -0,0 +1,12 @@
# Build a libc++ shared library, but merge libc++abi and libunwind into it.
set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "")
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")

set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
set(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY ON CACHE BOOL "")

set(LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
6 changes: 3 additions & 3 deletions libcxx/src/CMakeLists.txt
Expand Up @@ -223,10 +223,10 @@ if (LIBCXX_ENABLE_SHARED)
# dependencies are recorded when creating a linker script.
# TODO: Look into modifying the linker script creation to recursively consider interface libraries
if (LIBCXXABI_USE_LLVM_UNWINDER)
if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
target_link_libraries(cxx_shared PUBLIC unwind_shared)
elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)
# libunwind is already included in libc++abi
elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
target_link_libraries(cxx_shared PUBLIC unwind_shared)
else()
target_link_libraries(cxx_shared PUBLIC unwind)
endif()
Expand Down
14 changes: 14 additions & 0 deletions libcxx/utils/ci/buildkite-pipeline.yml
Expand Up @@ -351,6 +351,20 @@ steps:
limit: 2
timeout_in_minutes: 120

- label: "Shared library with merged ABI and unwinder libraries"
command: "libcxx/utils/ci/run-buildbot generic-merged"
artifact_paths:
- "**/test-results.xml"
- "**/*.abilist"
agents:
queue: "libcxx-builders"
os: "linux"
retry:
automatic:
- exit_status: -1 # Agent was lost
limit: 2
timeout_in_minutes: 120

- label: "Assertions enabled"
command: "libcxx/utils/ci/run-buildbot generic-assertions"
artifact_paths:
Expand Down
8 changes: 8 additions & 0 deletions libcxx/utils/ci/run-buildbot
Expand Up @@ -267,6 +267,14 @@ generic-static)
-DLIBUNWIND_TEST_CONFIG="llvm-libunwind-static.cfg.in"
check-runtimes
;;
generic-merged)
clean
generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-merged.cmake" \
-DLIBCXX_TEST_CONFIG="llvm-libc++-shared.cfg.in" \
-DLIBCXXABI_TEST_CONFIG="llvm-libc++abi-merged.cfg.in" \
-DLIBUNWIND_TEST_CONFIG="llvm-libunwind-merged.cfg.in"
check-runtimes
;;
generic-clang-13)
export CC=clang-13
export CXX=clang++-13
Expand Down
4 changes: 2 additions & 2 deletions libcxxabi/CMakeLists.txt
Expand Up @@ -115,10 +115,10 @@ cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY

cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
"Statically link the LLVM unwinder to static library" ON
"LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF)
"LIBCXXABI_ENABLE_STATIC_UNWINDER" OFF)
cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
"Statically link the LLVM unwinder to shared library" ON
"LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF)
"LIBCXXABI_ENABLE_STATIC_UNWINDER" OFF)

option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
# The default terminate handler attempts to demangle uncaught exceptions, which
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/src/CMakeLists.txt
Expand Up @@ -155,6 +155,7 @@ endif()
add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
if (LIBCXXABI_USE_LLVM_UNWINDER)
if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)
target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements
target_sources(cxxabi_shared_objects PUBLIC $<TARGET_OBJECTS:unwind_shared_objects>)
else()
target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared)
Expand Down Expand Up @@ -228,6 +229,7 @@ endif()
# Build the static library.
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
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})
Expand Down
27 changes: 27 additions & 0 deletions libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in
@@ -0,0 +1,27 @@
# Testing configuration for libc++abi when merged into a libc++ shared library.

lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')

config.substitutions.append(('%{flags}',
'-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
))
config.substitutions.append(('%{compile_flags}',
'-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} -DLIBCXXABI_NO_TIMER -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
'-I %{libcxx}/test/support -I %{libcxx}/src'
))
config.substitutions.append(('%{link_flags}',
'-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -pthread'
))
config.substitutions.append(('%{exec}',
'%{executor} --execdir %T -- '
))

import os, site
site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
libcxx.test.newconfig.configure(
libcxx.test.params.DEFAULT_PARAMETERS,
libcxx.test.features.DEFAULT_FEATURES,
config,
lit_config
)
65 changes: 65 additions & 0 deletions libunwind/test/configs/llvm-libunwind-merged.cfg.in
@@ -0,0 +1,65 @@
@AUTO_GEN_COMMENT@

@SERIALIZED_LIT_PARAMS@

#
# Configuration file for running the libunwind tests against a libc++ shared library
# into which the unwinder was merged.
#

import os, site
site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
import libcxx.test.format

# Basic configuration of the test suite
config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
config.recursiveExpansionLimit = 10
config.test_exec_root = '@CMAKE_BINARY_DIR@'
config.target_info = "@LIBUNWIND_TARGET_INFO@"

compile_flags = []
link_flags = []
if @LIBUNWIND_USES_ARM_EHABI@:
config.available_features.add('libunwind-arm-ehabi')

if not @LIBUNWIND_ENABLE_THREADS@:
compile_flags.append('-D_LIBUNWIND_HAS_NO_THREADS')
config.available_features.add('libunwind-no-threads')

if @LIBUNWIND_ENABLE_CET@:
compile_flags.append('-fcf-protection=full')

if '@CMAKE_SYSTEM_NAME@' == 'Linux':
link_flags.append('-Wl,--export-dynamic')

# Stack unwinding tests need unwinding tables and these are not generated by default on all targets.
compile_flags.append('-funwind-tables')

config.substitutions.append(('%{executor}', '@LIBUNWIND_EXECUTOR@'))

config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@'
config.substitutions.append(('%{flags}',
'-isysroot {}'.format(local_sysroot) if local_sysroot else ''
))
config.substitutions.append(('%{compile_flags}',
'-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
))
config.substitutions.append(('%{link_flags}',
'-L {0} -Wl,-rpath,{0} -lc++ -ldl {1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
))
config.substitutions.append(('%{exec}',
'%{executor} --execdir %T -- ' if '@LIBUNWIND_EXECUTOR@' else ''
))

import os, site
site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
libcxx.test.newconfig.configure(
libcxx.test.params.DEFAULT_PARAMETERS,
libcxx.test.features.DEFAULT_FEATURES,
config,
lit_config
)

0 comments on commit fa7ce8e

Please sign in to comment.