[llvm] ec37e0b - Re-apply "Only define LLVM_EXTERNAL_VISIBILITY when building libLLVM dylib"

Ben Langmuir via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 16 09:26:07 PST 2021


Author: Ben Langmuir
Date: 2021-12-16T09:25:41-08:00
New Revision: ec37e0bbafab75fa64f1ddb4cdeceb5400491ef8

URL: https://github.com/llvm/llvm-project/commit/ec37e0bbafab75fa64f1ddb4cdeceb5400491ef8
DIFF: https://github.com/llvm/llvm-project/commit/ec37e0bbafab75fa64f1ddb4cdeceb5400491ef8.diff

LOG: 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

Added: 
    

Modified: 
    llvm/CMakeLists.txt
    llvm/include/llvm/Config/llvm-config.h.cmake
    llvm/include/llvm/Support/Compiler.h

Removed: 
    


################################################################################
diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 9e2d2365b653f..06aca534bd748 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 4493bb65d4442..a5edc2084a8a5 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 c5318137ed3d0..b31ba6bc7fc20 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


        


More information about the llvm-commits mailing list