From ec37e0bbafab75fa64f1ddb4cdeceb5400491ef8 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Fri, 10 Dec 2021 11:49:04 -0800 Subject: [PATCH] Re-apply "Only define LLVM_EXTERNAL_VISIBILITY when building libLLVM dylib" With a fix for BUILD_SHARED_LIBS. Original commit message: When building LLVM static libraries, we should not make symbols more visible than CMAKE_CXX_VISIBILITY_PRESET, since the goal may be to have a purely hidden llvm embedded in another library. Instead, we only define LLVM_EXTERNAL_VISIBILITY for the dynamic library build (when LLVM_BUILD_LLVM_DYLIB=YES or BUILD_SHARED_LIBS=YES). Original Review: https://reviews.llvm.org/D113610 Differential Revision: https://reviews.llvm.org/D115825 --- llvm/CMakeLists.txt | 3 +++ llvm/include/llvm/Config/llvm-config.h.cmake | 6 ++++++ llvm/include/llvm/Support/Compiler.h | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 9e2d2365b653..06aca534bd74 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -788,6 +788,9 @@ foreach(t ${LLVM_TARGETS_TO_BUILD}) endif() endforeach(t) +# Provide an LLVM_ namespaced alias for use in #cmakedefine. +set(LLVM_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) + # Produce the target definition files, which provide a way for clients to easily # include various classes of targets. configure_file( diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 4493bb65d444..a5edc2084a8a 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -103,4 +103,10 @@ /* Define if the xar_open() function is supported on this platform. */ #cmakedefine LLVM_HAVE_LIBXAR ${LLVM_HAVE_LIBXAR} +/* Define if building libLLVM shared library */ +#cmakedefine LLVM_BUILD_LLVM_DYLIB + +/* Define if building LLVM with BUILD_SHARED_LIBS */ +#cmakedefine LLVM_BUILD_SHARED_LIBS + #endif diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index c5318137ed3d..b31ba6bc7fc2 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -126,7 +126,11 @@ #if __has_attribute(visibility) && !defined(__MINGW32__) && \ !defined(__CYGWIN__) && !defined(_WIN32) #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden"))) -#define LLVM_EXTERNAL_VISIBILITY __attribute__ ((visibility("default"))) +#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) +#define LLVM_EXTERNAL_VISIBILITY __attribute__((visibility("default"))) +#else +#define LLVM_EXTERNAL_VISIBILITY +#endif #else #define LLVM_LIBRARY_VISIBILITY #define LLVM_EXTERNAL_VISIBILITY