Skip to content

Commit 592e935

Browse files
committed
[clang-repl] Fix REPL_EXTERNAL_VISIBILITY and building libclang-cpp.dll for MinGW configurations
This fixes two issues that are observed after 5111286: For builds with GCC with LLVM_LINK_LLVM_DYLIB=ON, we previously got build errors, as libclang-cpp.dll suddenly only contained the functions that were marked dllexport via REPL_EXTERNAL_VISIBILITY, instead of all symbols as expected. For MinGW builds with Clang, building previously succeeded (as it used either the __attribute__((visibility("default"))) annotation or nothing at all), and the functions were exported from libclang-cpp.dll if that was built, but the unit test failed (as neither of those cases made the functions exported from an EXE). Don't use the visibility attributes on MinGW targets for these purposes; setting default visibility only makes a difference if building with e.g. -fvisibility=hidden, but it doesn't make the symbols exported from an EXE. Differential Revision: https://reviews.llvm.org/D151620
1 parent 9efa4cd commit 592e935

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

clang/include/clang/Interpreter/Value.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,24 @@ class ASTContext;
5252
class Interpreter;
5353
class QualType;
5454

55-
#if __has_attribute(visibility) && \
56-
(!(defined(_WIN32) || defined(__CYGWIN__)) || \
57-
(defined(__MINGW32__) && defined(__clang__)))
55+
#if defined(_WIN32)
56+
// REPL_EXTERNAL_VISIBILITY are symbols that we need to be able to locate
57+
// at runtime. On Windows, this requires them to be exported from any of the
58+
// modules loaded at runtime. Marking them as dllexport achieves this; both
59+
// for DLLs (that normally export symbols as part of their interface) and for
60+
// EXEs (that normally don't export anything).
61+
// For a build with libclang-cpp.dll, this doesn't make any difference - the
62+
// functions would have been exported anyway. But for cases when these are
63+
// statically linked into an EXE, it makes sure that they're exported.
64+
#define REPL_EXTERNAL_VISIBILITY __declspec(dllexport)
65+
#elif __has_attribute(visibility)
5866
#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
5967
#define REPL_EXTERNAL_VISIBILITY __attribute__((visibility("default")))
6068
#else
6169
#define REPL_EXTERNAL_VISIBILITY
6270
#endif
6371
#else
64-
#if defined(_WIN32)
65-
#define REPL_EXTERNAL_VISIBILITY __declspec(dllexport)
66-
#endif
72+
#define REPL_EXTERNAL_VISIBILITY
6773
#endif
6874

6975
#define REPL_BUILTIN_TYPES \

clang/tools/clang-shlib/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ add_clang_library(clang-cpp
5353
if (NOT APPLE AND NOT MINGW)
5454
target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
5555
endif()
56+
if (MINGW OR CYGWIN)
57+
# The clang-cpp DLL is supposed to export all symbols (except for ones
58+
# that are explicitly hidden). Normally, this is what happens anyway, but
59+
# if there are symbols that are marked explicitly as dllexport, we'd only
60+
# export them and nothing else. Therefore, add --export-all-symbols to
61+
# make sure we export all symbols despite potential dllexports.
62+
target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols)
63+
endif()

0 commit comments

Comments
 (0)