diff --git a/clang/include/clang/Interpreter/Value.h b/clang/include/clang/Interpreter/Value.h --- a/clang/include/clang/Interpreter/Value.h +++ b/clang/include/clang/Interpreter/Value.h @@ -52,18 +52,24 @@ class Interpreter; class QualType; -#if __has_attribute(visibility) && \ - (!(defined(_WIN32) || defined(__CYGWIN__)) || \ - (defined(__MINGW32__) && defined(__clang__))) +#if defined(_WIN32) +// REPL_EXTERNAL_VISIBILITY are symbols that we need to be able to locate +// at runtime. On Windows, this requires them to be exported from any of the +// modules loaded at runtime. Marking them as dllexport achieves this; both +// for DLLs (that normally export symbols as part of their interface) and for +// EXEs (that normally don't export anything). +// For a build with libclang-cpp.dll, this doesn't make any difference - the +// functions would have been exported anyway. But for cases when these are +// statically linked into an EXE, it makes sure that they're exported. +#define REPL_EXTERNAL_VISIBILITY __declspec(dllexport) +#elif __has_attribute(visibility) #if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) #define REPL_EXTERNAL_VISIBILITY __attribute__((visibility("default"))) #else #define REPL_EXTERNAL_VISIBILITY #endif #else -#if defined(_WIN32) -#define REPL_EXTERNAL_VISIBILITY __declspec(dllexport) -#endif +#define REPL_EXTERNAL_VISIBILITY #endif #define REPL_BUILTIN_TYPES \ diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt --- a/clang/tools/clang-shlib/CMakeLists.txt +++ b/clang/tools/clang-shlib/CMakeLists.txt @@ -53,3 +53,11 @@ if (NOT APPLE AND NOT MINGW) target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions) endif() +if (MINGW OR CYGWIN) + # The clang-cpp DLL is supposed to export all symbols (except for ones + # that are explicitly hidden). Normally, this is what happens anyway, but + # if there are symbols that are marked explicitly as dllexport, we'd only + # export them and nothing else. Therefore, add --export-all-symbols to + # make sure we export all symbols despite potential dllexports. + target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols) +endif()