Skip to content

Commit fa7ce8e

Browse files
committed
[runtimes] Fix the build of merged ABI/unwinder libraries
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
1 parent e601b2a commit fa7ce8e

File tree

9 files changed

+135
-7
lines changed

9 files changed

+135
-7
lines changed

libcxx/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
237237

238238
cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
239239
"Statically link the ABI library to static library" ON
240-
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF)
240+
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY" OFF)
241241

242242
cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
243243
"Statically link the ABI library to shared library" ON
244-
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" OFF)
244+
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY" OFF)
245245

246246
# Generate and install a linker script inplace of libc++.so. The linker script
247247
# will link libc++ to the correct ABI library. This option is on by default
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Build a libc++ shared library, but merge libc++abi and libunwind into it.
2+
set(LIBCXX_ENABLE_SHARED ON CACHE BOOL "")
3+
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
4+
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
5+
set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
6+
7+
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
8+
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
9+
set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
10+
set(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY ON CACHE BOOL "")
11+
12+
set(LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")

libcxx/src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ if (LIBCXX_ENABLE_SHARED)
223223
# dependencies are recorded when creating a linker script.
224224
# TODO: Look into modifying the linker script creation to recursively consider interface libraries
225225
if (LIBCXXABI_USE_LLVM_UNWINDER)
226-
if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
227-
target_link_libraries(cxx_shared PUBLIC unwind_shared)
228-
elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
226+
if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)
229227
# libunwind is already included in libc++abi
228+
elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
229+
target_link_libraries(cxx_shared PUBLIC unwind_shared)
230230
else()
231231
target_link_libraries(cxx_shared PUBLIC unwind)
232232
endif()

libcxx/utils/ci/buildkite-pipeline.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,20 @@ steps:
351351
limit: 2
352352
timeout_in_minutes: 120
353353

354+
- label: "Shared library with merged ABI and unwinder libraries"
355+
command: "libcxx/utils/ci/run-buildbot generic-merged"
356+
artifact_paths:
357+
- "**/test-results.xml"
358+
- "**/*.abilist"
359+
agents:
360+
queue: "libcxx-builders"
361+
os: "linux"
362+
retry:
363+
automatic:
364+
- exit_status: -1 # Agent was lost
365+
limit: 2
366+
timeout_in_minutes: 120
367+
354368
- label: "Assertions enabled"
355369
command: "libcxx/utils/ci/run-buildbot generic-assertions"
356370
artifact_paths:

libcxx/utils/ci/run-buildbot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ generic-static)
267267
-DLIBUNWIND_TEST_CONFIG="llvm-libunwind-static.cfg.in"
268268
check-runtimes
269269
;;
270+
generic-merged)
271+
clean
272+
generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-merged.cmake" \
273+
-DLIBCXX_TEST_CONFIG="llvm-libc++-shared.cfg.in" \
274+
-DLIBCXXABI_TEST_CONFIG="llvm-libc++abi-merged.cfg.in" \
275+
-DLIBUNWIND_TEST_CONFIG="llvm-libunwind-merged.cfg.in"
276+
check-runtimes
277+
;;
270278
generic-clang-13)
271279
export CC=clang-13
272280
export CXX=clang++-13

libcxxabi/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY
115115

116116
cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
117117
"Statically link the LLVM unwinder to static library" ON
118-
"LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF)
118+
"LIBCXXABI_ENABLE_STATIC_UNWINDER" OFF)
119119
cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
120120
"Statically link the LLVM unwinder to shared library" ON
121-
"LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF)
121+
"LIBCXXABI_ENABLE_STATIC_UNWINDER" OFF)
122122

123123
option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
124124
# The default terminate handler attempts to demangle uncaught exceptions, which

libcxxabi/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ endif()
155155
add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
156156
if (LIBCXXABI_USE_LLVM_UNWINDER)
157157
if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)
158+
target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements
158159
target_sources(cxxabi_shared_objects PUBLIC $<TARGET_OBJECTS:unwind_shared_objects>)
159160
else()
160161
target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared)
@@ -228,6 +229,7 @@ endif()
228229
# Build the static library.
229230
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
230231
if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
232+
target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements
231233
target_sources(cxxabi_static_objects PUBLIC $<TARGET_OBJECTS:unwind_static_objects>)
232234
endif()
233235
target_link_libraries(cxxabi_static_objects PRIVATE cxx-headers ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Testing configuration for libc++abi when merged into a libc++ shared library.
2+
3+
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
4+
5+
config.substitutions.append(('%{flags}',
6+
'-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else ''
7+
))
8+
config.substitutions.append(('%{compile_flags}',
9+
'-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} -DLIBCXXABI_NO_TIMER -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
10+
'-I %{libcxx}/test/support -I %{libcxx}/src'
11+
))
12+
config.substitutions.append(('%{link_flags}',
13+
'-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -pthread'
14+
))
15+
config.substitutions.append(('%{exec}',
16+
'%{executor} --execdir %T -- '
17+
))
18+
19+
import os, site
20+
site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils'))
21+
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
22+
libcxx.test.newconfig.configure(
23+
libcxx.test.params.DEFAULT_PARAMETERS,
24+
libcxx.test.features.DEFAULT_FEATURES,
25+
config,
26+
lit_config
27+
)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@AUTO_GEN_COMMENT@
2+
3+
@SERIALIZED_LIT_PARAMS@
4+
5+
#
6+
# Configuration file for running the libunwind tests against a libc++ shared library
7+
# into which the unwinder was merged.
8+
#
9+
10+
import os, site
11+
site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
12+
import libcxx.test.format
13+
14+
# Basic configuration of the test suite
15+
config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
16+
config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
17+
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
18+
config.recursiveExpansionLimit = 10
19+
config.test_exec_root = '@CMAKE_BINARY_DIR@'
20+
config.target_info = "@LIBUNWIND_TARGET_INFO@"
21+
22+
compile_flags = []
23+
link_flags = []
24+
if @LIBUNWIND_USES_ARM_EHABI@:
25+
config.available_features.add('libunwind-arm-ehabi')
26+
27+
if not @LIBUNWIND_ENABLE_THREADS@:
28+
compile_flags.append('-D_LIBUNWIND_HAS_NO_THREADS')
29+
config.available_features.add('libunwind-no-threads')
30+
31+
if @LIBUNWIND_ENABLE_CET@:
32+
compile_flags.append('-fcf-protection=full')
33+
34+
if '@CMAKE_SYSTEM_NAME@' == 'Linux':
35+
link_flags.append('-Wl,--export-dynamic')
36+
37+
# Stack unwinding tests need unwinding tables and these are not generated by default on all targets.
38+
compile_flags.append('-funwind-tables')
39+
40+
config.substitutions.append(('%{executor}', '@LIBUNWIND_EXECUTOR@'))
41+
42+
config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
43+
local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@'
44+
config.substitutions.append(('%{flags}',
45+
'-isysroot {}'.format(local_sysroot) if local_sysroot else ''
46+
))
47+
config.substitutions.append(('%{compile_flags}',
48+
'-nostdinc++ -I {}/include {}'.format('@LIBUNWIND_SOURCE_DIR@', ' '.join(compile_flags))
49+
))
50+
config.substitutions.append(('%{link_flags}',
51+
'-L {0} -Wl,-rpath,{0} -lc++ -ldl {1}'.format('@LIBUNWIND_LIBRARY_DIR@', ' '.join(link_flags))
52+
))
53+
config.substitutions.append(('%{exec}',
54+
'%{executor} --execdir %T -- ' if '@LIBUNWIND_EXECUTOR@' else ''
55+
))
56+
57+
import os, site
58+
site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
59+
import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
60+
libcxx.test.newconfig.configure(
61+
libcxx.test.params.DEFAULT_PARAMETERS,
62+
libcxx.test.features.DEFAULT_FEATURES,
63+
config,
64+
lit_config
65+
)

0 commit comments

Comments
 (0)