From 18ef564c8bb060bc586de28789d5b212942f355f Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 26 May 2016 02:12:20 +0000 Subject: [PATCH] libc++abi: build with -fvisibility=hidden Enable building libc++abi with hidden visibility by default. The ABI mandated interfaces (and a few extra) are already set up to be externally visible. This allows us to ensure that any implementation details are not leaked. llvm-svn: 270816 --- libcxxabi/CMakeLists.txt | 2 ++ libcxxabi/cmake/config-ix.cmake | 1 + libcxxabi/include/__cxxabi_config.h | 3 +++ libcxxabi/src/cxa_default_handlers.cpp | 5 ++++- libcxxabi/src/cxa_handlers.cpp | 4 ++-- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 37cc56095f6b..85aa893e04b4 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -250,6 +250,8 @@ append_if(LIBCXXABI_CXX_FLAGS LIBCXXABI_HAS_EHSC_FLAG -EHsc) append_if(LIBCXXABI_C_FLAGS LIBCXXABI_HAS_FUNWIND_TABLES -funwind-tables) +append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden) + # Assert string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) if (LIBCXXABI_ENABLE_ASSERTIONS) diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake index 1d40b2a9e67e..e9e43723c589 100644 --- a/libcxxabi/cmake/config-ix.cmake +++ b/libcxxabi/cmake/config-ix.cmake @@ -8,6 +8,7 @@ check_cxx_compiler_flag(-fPIC LIBCXXABI_HAS_FPIC_FLAG) check_cxx_compiler_flag(-fno-exceptions LIBCXXABI_HAS_NO_EXCEPTIONS_FLAG) check_cxx_compiler_flag(-fno-rtti LIBCXXABI_HAS_NO_RTTI_FLAG) check_cxx_compiler_flag(-fstrict-aliasing LIBCXXABI_HAS_FSTRICT_ALIASING_FLAG) +check_cxx_compiler_flag(-fvisibility=hidden LIBCXXABI_HAS_FVISIBILITY_HIDDEN_FLAG) check_cxx_compiler_flag(-nodefaultlibs LIBCXXABI_HAS_NODEFAULTLIBS_FLAG) check_cxx_compiler_flag(-nostdinc++ LIBCXXABI_HAS_NOSTDINCXX_FLAG) check_cxx_compiler_flag(-Wall LIBCXXABI_HAS_WALL_FLAG) diff --git a/libcxxabi/include/__cxxabi_config.h b/libcxxabi/include/__cxxabi_config.h index 68e325ffef6b..61555f1a9279 100644 --- a/libcxxabi/include/__cxxabi_config.h +++ b/libcxxabi/include/__cxxabi_config.h @@ -24,15 +24,18 @@ #if defined(_LIBCXXABI_DLL) #if defined(cxxabi_EXPORTS) #define _LIBCXXABI_HIDDEN + #define _LIBCXXABI_DATA_VIS __declspec(dllexport) #define _LIBCXXABI_FUNC_VIS __declspec(dllexport) #define _LIBCXXABI_TYPE_VIS __declspec(dllexport) #else #define _LIBCXXABI_HIDDEN + #define _LIBCXXABI_DATA_VIS __declspec(dllimport) #define _LIBCXXABI_FUNC_VIS __declspec(dllimport) #define _LIBCXXABI_TYPE_VIS __declspec(dllimport) #endif #else #define _LIBCXXABI_HIDDEN __attribute__((__visibility__("hidden"))) + #define _LIBCXXABI_DATA_VIS __attribute__((__visibility__("default"))) #define _LIBCXXABI_FUNC_VIS __attribute__((__visibility__("default"))) #if __has_attribute(__type_visibility__) #define _LIBCXXABI_TYPE_VIS __attribute__((__type_visibility__("default"))) diff --git a/libcxxabi/src/cxa_default_handlers.cpp b/libcxxabi/src/cxa_default_handlers.cpp index d34341aa3287..09350e7721a0 100644 --- a/libcxxabi/src/cxa_default_handlers.cpp +++ b/libcxxabi/src/cxa_default_handlers.cpp @@ -88,7 +88,10 @@ static void default_unexpected_handler() // // Global variables that hold the pointers to the current handler // -std::terminate_handler __cxa_terminate_handler = default_terminate_handler; +_LIBCXXABI_DATA_VIS +std::terminate_handler __cxa_terminate_handler = default_terminate_handler; + +_LIBCXXABI_DATA_VIS std::unexpected_handler __cxa_unexpected_handler = default_unexpected_handler; // In the future these will become: diff --git a/libcxxabi/src/cxa_handlers.cpp b/libcxxabi/src/cxa_handlers.cpp index 9c1c30291a69..c231b5a3ecb7 100644 --- a/libcxxabi/src/cxa_handlers.cpp +++ b/libcxxabi/src/cxa_handlers.cpp @@ -102,9 +102,9 @@ terminate() _NOEXCEPT __terminate(get_terminate()); } -extern "C" new_handler __cxa_new_handler = 0; -// In the future these will become: +// In the future this will become: // std::atomic __cxa_new_handler(0); +extern "C" _LIBCXXABI_DATA_VIS new_handler __cxa_new_handler = 0; new_handler set_new_handler(new_handler handler) _NOEXCEPT