diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -322,9 +322,14 @@ add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() +# TODO: This special case predated the LIBUNWIND_HERMETIC_STATIC_LIBRARY +# option (by a few weeks -- D55537 vs D57107) and seems redundant with it in +# principle. The static library is always hermetic on Windows, unless both +# static and shared libraries are enabled. +# # Disable DLL annotations on Windows for static builds. if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED) - add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) + add_definitions(-D_LIBUNWIND_HERMETIC_STATIC_LIBRARY) endif() if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -164,7 +164,7 @@ append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility=hidden) append_flags_if_supported(UNWIND_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) target_compile_options(unwind_static PRIVATE ${UNWIND_STATIC_LIBRARY_FLAGS}) - target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) + target_compile_definitions(unwind_static PRIVATE _LIBUNWIND_HERMETIC_STATIC_LIBRARY) endif() list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static") diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h --- a/libunwind/src/assembly.h +++ b/libunwind/src/assembly.h @@ -70,12 +70,16 @@ #if defined(__APPLE__) #define SYMBOL_IS_FUNC(name) +#if defined(_LIBUNWIND_HERMETIC_STATIC_LIBRARY) +#define EXPORT_SYMBOL(name) .private_extern name +#else #define EXPORT_SYMBOL(name) +#endif #define HIDDEN_SYMBOL(name) .private_extern name #define WEAK_SYMBOL(name) .weak_reference name #define WEAK_ALIAS(name, aliasname) \ .globl SYMBOL_NAME(aliasname) SEPARATOR \ - WEAK_SYMBOL(aliasname) SEPARATOR \ + EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) #define NO_EXEC_STACK_DIRECTIVE @@ -87,17 +91,23 @@ #else #define SYMBOL_IS_FUNC(name) .type name,@function #endif +#if defined(_LIBUNWIND_HERMETIC_STATIC_LIBRARY) +#define EXPORT_SYMBOL(name) .hidden name +#else #define EXPORT_SYMBOL(name) +#endif #define HIDDEN_SYMBOL(name) .hidden name #define WEAK_SYMBOL(name) .weak name #if defined(__hexagon__) -#define WEAK_ALIAS(name, aliasname) \ - WEAK_SYMBOL(aliasname) SEPARATOR \ +#define WEAK_ALIAS(name, aliasname) \ + EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ + WEAK_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ .equiv SYMBOL_NAME(aliasname), SYMBOL_NAME(name) #else #define WEAK_ALIAS(name, aliasname) \ - WEAK_SYMBOL(aliasname) SEPARATOR \ + EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ + WEAK_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) #endif @@ -119,7 +129,7 @@ .section .drectve,"yn" SEPARATOR \ .ascii "-export:", #name, "\0" SEPARATOR \ .text -#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) +#if defined(_LIBUNWIND_HERMETIC_STATIC_LIBRARY) #define EXPORT_SYMBOL(name) #else #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name) diff --git a/libunwind/src/config.h b/libunwind/src/config.h --- a/libunwind/src/config.h +++ b/libunwind/src/config.h @@ -52,7 +52,9 @@ #endif #endif -#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) +#if defined(_LIBUNWIND_HERMETIC_STATIC_LIBRARY) + // For a hermetic static library, the global default visibility is hidden. The + // CMake file passes -fvisibility=hidden to control ELF/Mach-O visibility. #define _LIBUNWIND_EXPORT #define _LIBUNWIND_HIDDEN #else @@ -70,11 +72,15 @@ #define SYMBOL_NAME(name) XSTR(__USER_LABEL_PREFIX__) #name #if defined(__APPLE__) +#if defined(_LIBUNWIND_HERMETIC_STATIC_LIBRARY) +#define _LIBUNWIND_ALIAS_VISIBILITY(name) __asm__(".private_extern " name) +#else +#define _LIBUNWIND_ALIAS_VISIBILITY(name) +#endif #define _LIBUNWIND_WEAK_ALIAS(name, aliasname) \ __asm__(".globl " SYMBOL_NAME(aliasname)); \ __asm__(SYMBOL_NAME(aliasname) " = " SYMBOL_NAME(name)); \ - extern "C" _LIBUNWIND_EXPORT __typeof(name) aliasname \ - __attribute__((weak_import)); + _LIBUNWIND_ALIAS_VISIBILITY(SYMBOL_NAME(aliasname)); #elif defined(__ELF__) #define _LIBUNWIND_WEAK_ALIAS(name, aliasname) \ extern "C" _LIBUNWIND_EXPORT __typeof(name) aliasname \