[llvm] Initial changes for llvm shared library build using explicit visibility annotations (PR #96630)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 04:54:59 PDT 2024


mstorsjo wrote:

This patch breaks mingw builds.

Currently, it's very possible to build for mingw targets with `-DLLVM_LINK_LLVM_DYLIB=ON`; mingw toolchains default to exporting all symbols if there are no ones marked dllexport, and ELF-style attributes like `__attribute__((visibility("hidden")))` and options like `-fvisibility=hidden` works for excluding individual symbols or translation units from the automatic export.

I don't mind switching to the new approach of explicit dllexport/import of things, once it is working and complete, but I don't want to regress building with `-DLLVM_LINK_LLVM_DYLIB=ON` in the meantime.

With a patch like this, building for mingw targets keeps working like it used to:
```diff
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -174,7 +174,7 @@
 #define LLVM_ABI
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
-#elif defined(_WIN32)
+#elif defined(_WIN32) && !defined(__MINGW32__)
 #if defined(LLVM_EXPORTS)
 #define LLVM_ABI __declspec(dllexport)
 #define LLVM_TEMPLATE_ABI
@@ -184,7 +184,7 @@
 #define LLVM_TEMPLATE_ABI __declspec(dllimport)
 #define LLVM_EXPORT_TEMPLATE
 #endif
-#elif defined(__ELF__)
+#elif defined(__ELF__) || defined(__MINGW32__)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_EXPORT_TEMPLATE
```

If you want to test that this keeps working, I tried setting up a simple build file for GitHub Actions: https://github.com/mstorsjo/llvm-project/commit/gha-build-windows If you push a branch with this commit, to your own fork, it should test building with MSVC, clang-cl and llvm-mingw (with and without dylibs enabled).

https://github.com/llvm/llvm-project/pull/96630


More information about the llvm-commits mailing list