[llvm] [llvm] annotate interfaces in AsmParser, BinaryFormat, Bitcode, and Bitstream libraries for DLL export (PR #141794)
Andrew Rogers via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 4 17:54:08 PDT 2025
================
@@ -120,7 +121,7 @@ namespace llvm {
extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
}
-extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
+LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
----------------
andrurogerz wrote:
> Should extern precede LLVM_ABI?
There is actually a problem with moving the `LLVM_ABI` annotation after the `extern` keyword. When we're building with gcc, `Compiler.h` currently defines `LLVM_ABI` as a C++ GNU visibility attribute: `[[gnu::visibility("default")]]`. When this attribute follows `extern` on a variable declaration, gcc produces `error: standard attributes in middle of decl-specifiers` errors.
I think there are two ways to proceed:
1. Leave things as-is and require `LLVM_ABI` before `extern`. This is counter to MSDN documentation for `__declspec(dllimport)` when building for Windows, but behaves correctly and does not generate any warnings.
2. Always define `LLVM_ABI` to `__attribute__(visibility(("default")))` on non-Windows platforms. This is how it is currently defined when compiling with Clang on non-Windows.
Option 2 is arguably the better choice because placement of `__attribute__` attributes is more flexible (compiler-dependent). I think it might also allow us to eliminate the `LLVM_ABI_FRIEND` macro in favor of `LLVM_ABI`. @compnerd do you have any thoughts?
https://github.com/llvm/llvm-project/pull/141794
More information about the llvm-commits
mailing list