diff options
| author | Petr Hosek <phosek@chromium.org> | 2019-01-29 23:01:08 +0000 |
|---|---|---|
| committer | Petr Hosek <phosek@chromium.org> | 2019-01-29 23:01:08 +0000 |
| commit | 3cfc55cf9c09b46e5ca47aaa6bbd628d64f86d14 (patch) | |
| tree | 1c1dd00296aaacba846de784c344fdeb10239722 | |
| parent | aecce85da62ae5db322c2d03bcf873077a7cff4d (diff) | |
| download | bcm5719-llvm-3cfc55cf9c09b46e5ca47aaa6bbd628d64f86d14.tar.gz bcm5719-llvm-3cfc55cf9c09b46e5ca47aaa6bbd628d64f86d14.zip | |
[libunwind] Support building hermetic static library
This is useful when the static libunwind library is being linked into
shared libraries that may be used in with other shared libraries that
use different unwinder. We want to avoid avoid exporting libunwind
symbols in those cases. This achieved by a new CMake option which can be
enabled by libunwind vendors as needed.
The same CMake option has already been added to libc++ and libc++abi in
D55404 and D56026.
Differential Revision: https://reviews.llvm.org/D57107
llvm-svn: 352559
| -rw-r--r-- | libcxxabi/src/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | libunwind/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | libunwind/src/CMakeLists.txt | 41 |
3 files changed, 42 insertions, 8 deletions
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt index 77722e6b140..246cfd88df6 100644 --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -218,7 +218,11 @@ endif() if (LIBCXXABI_ENABLE_STATIC) if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) if (TARGET unwind_static OR HAVE_LIBUNWIND) - list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_objects>) + if(LIBUNWIND_HERMETIC_STATIC_LIBRARY) + list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_static_objects>) + else() + list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_objects>) + endif() endif() endif() add_library(cxxabi_static STATIC ${cxxabi_static_sources}) diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt index 46e7ce146e7..41b990f81c4 100644 --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -168,6 +168,9 @@ elseif(LIBUNWIND_BUILD_32_BITS) message(FATAL_ERROR "LIBUNWIND_BUILD_32_BITS=ON is not supported on this platform.") endif() +option(LIBUNWIND_HERMETIC_STATIC_LIBRARY + "Do not export any symbols from the static library." OFF) + #=============================================================================== # Configure System #=============================================================================== diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index f7523f88b6a..080e8c5ad58 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -105,17 +105,44 @@ set_property(SOURCE ${LIBUNWIND_CXX_SOURCES} set_property(SOURCE ${LIBUNWIND_C_SOURCES} APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}") +macro(unwind_object_library name) + cmake_parse_arguments(ARGS "" "" "DEFINES;FLAGS" ${ARGN}) + # Add a object library that contains the compiled source files. -add_library(unwind_objects OBJECT ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) + add_library(${name} OBJECT ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) + + if(ARGS_DEFINES) + target_compile_definitions(${name} PRIVATE ${ARGS_DEFINES}) + endif() + + set_target_properties(${name} + PROPERTIES + COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" + POSITION_INDEPENDENT_CODE ON) -set_target_properties(unwind_objects - PROPERTIES - COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" - POSITION_INDEPENDENT_CODE ON) + if(ARGS_FLAGS) + target_compile_options(${name} PRIVATE ${ARGS_FLAGS}) + endif() +endmacro() + +if(LIBUNWIND_HERMETIC_STATIC_LIBRARY) + append_flags_if_supported(UNWIND_STATIC_OBJECTS_FLAGS -fvisibility=hidden) + append_flags_if_supported(UNWIND_STATIC_OBJECTS_FLAGS -fvisibility-global-new-delete-hidden) + unwind_object_library(unwind_static_objects + DEFINES _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS + FLAGS ${UNWIND_STATIC_OBJECTS_FLAGS}) + unwind_object_library(unwind_shared_objects) + set(unwind_static_sources $<TARGET_OBJECTS:unwind_static_objects>) + set(unwind_shared_sources $<TARGET_OBJECTS:unwind_shared_objects>) +else() + unwind_object_library(unwind_objects) + set(unwind_static_sources $<TARGET_OBJECTS:unwind_objects>) + set(unwind_shared_sources $<TARGET_OBJECTS:unwind_objects>) +endif() # Build the shared library. if (LIBUNWIND_ENABLE_SHARED) - add_library(unwind_shared SHARED $<TARGET_OBJECTS:unwind_objects>) + add_library(unwind_shared SHARED ${unwind_shared_sources}) if(COMMAND llvm_setup_rpath) llvm_setup_rpath(unwind_shared) endif() @@ -134,7 +161,7 @@ endif() # Build the static library. if (LIBUNWIND_ENABLE_STATIC) - add_library(unwind_static STATIC $<TARGET_OBJECTS:unwind_objects>) + add_library(unwind_static STATIC ${unwind_static_sources}) target_link_libraries(unwind_static ${libraries}) set_target_properties(unwind_static PROPERTIES |

