Skip to content

[llvm] fix extern cl::opt definitions for DLL export #145374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

andrurogerz
Copy link
Contributor

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch ensures a few cl::opt declarations are properly annotated with LLVM_ABI. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build.

Background

This effort is tracked in #109483. Additional context is provided in this discourse, and documentation for LLVM_ABI and related annotations is found in the LLVM repo here.

Overview

  • Remove local extern declarations of llvm::PrintPipelinePasses because it is already correctly declared with an LLVM_ABI annotation in llvm\Passes\PassBuilder.h. Leaving these declarations results in a gcc compile warning unless they are also annotated with LLVM_ABI.
  • Similarly, remove local extern declarations of ProfileSummaryCutoffHot and UseContextLessSummary from llvm/tools/llvm-profgen/ProfileGenerator.cpp since they are declared with LLVM_ABI in llvm\ProfileData\ProfileCommon.h.
  • Explicitly annotate the extern declaration of ProfileCorrelate in clang/lib/CodeGen/BackendUtil.cpp since it is not declared in a header. The definition of ProfileCorrelate in llvm\lib\Transforms\Instrumentation\InstrProfiling.cpp is already annotated with LLVM_ABI.

Validation

Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:

  • Windows with MSVC
  • Windows with Clang
  • Linux with GCC
  • Linux with Clang
  • Darwin with Clang

@andrurogerz andrurogerz force-pushed the llvmdll-extern-defs branch from e1aca7f to 8f95bca Compare June 23, 2025 19:04
@andrurogerz andrurogerz force-pushed the llvmdll-extern-defs branch from 31bd337 to 4350b92 Compare June 23, 2025 23:24
@andrurogerz andrurogerz marked this pull request as ready for review June 24, 2025 01:35
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. flang:driver PGO Profile Guided Optimizations flang Flang issues not falling into any other category labels Jun 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-pgo

Author: Andrew Rogers (andrurogerz)

Changes

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch ensures a few cl::opt declarations are properly annotated with LLVM_ABI. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build.

Background

This effort is tracked in #109483. Additional context is provided in this discourse, and documentation for LLVM_ABI and related annotations is found in the LLVM repo here.

Overview

  • Remove local extern declarations of llvm::PrintPipelinePasses because it is already correctly declared with an LLVM_ABI annotation in llvm\Passes\PassBuilder.h. Leaving these declarations results in a gcc compile warning unless they are also annotated with LLVM_ABI.
  • Similarly, remove local extern declarations of ProfileSummaryCutoffHot and UseContextLessSummary from llvm/tools/llvm-profgen/ProfileGenerator.cpp since they are declared with LLVM_ABI in llvm\ProfileData\ProfileCommon.h.
  • Explicitly annotate the extern declaration of ProfileCorrelate in clang/lib/CodeGen/BackendUtil.cpp since it is not declared in a header. The definition of ProfileCorrelate in llvm\lib\Transforms\Instrumentation\InstrProfiling.cpp is already annotated with LLVM_ABI.

Validation

Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:

  • Windows with MSVC
  • Windows with Clang
  • Linux with GCC
  • Linux with Clang
  • Darwin with Clang

Full diff: https://github.com/llvm/llvm-project/pull/145374.diff

3 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (+3-3)
  • (modified) flang/lib/Frontend/FrontendActions.cpp (-4)
  • (modified) llvm/tools/llvm-profgen/ProfileGenerator.cpp (-2)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 7e0a3cf5591ce..97bc063ad34e5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Program.h"
@@ -96,8 +97,6 @@ using namespace llvm;
 #include "llvm/Support/Extension.def"
 
 namespace llvm {
-extern cl::opt<bool> PrintPipelinePasses;
-
 // Experiment to move sanitizers earlier.
 static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
     "sanitizer-early-opt-ep", cl::Optional,
@@ -118,7 +117,8 @@ static cl::opt<PGOOptions::ColdFuncOpt> ClPGOColdFuncAttr(
                clEnumValN(PGOOptions::ColdFuncOpt::OptNone, "optnone",
                           "Mark cold functions with optnone.")));
 
-extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
+LLVM_ABI extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind>
+    ProfileCorrelate;
 } // namespace llvm
 namespace clang {
 extern llvm::cl::opt<bool> ClSanitizeGuardChecks;
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index d684eeb696755..bf15def3f3b2e 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -74,10 +74,6 @@
 #include <memory>
 #include <system_error>
 
-namespace llvm {
-extern cl::opt<bool> PrintPipelinePasses;
-} // namespace llvm
-
 using namespace Fortran::frontend;
 
 constexpr llvm::StringLiteral timingIdParse = "Parse";
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index b47c77c5f2ff3..db686c3b597eb 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -108,8 +108,6 @@ using namespace llvm;
 using namespace sampleprof;
 
 namespace llvm {
-extern cl::opt<int> ProfileSummaryCutoffHot;
-extern cl::opt<bool> UseContextLessSummary;
 
 namespace sampleprof {
 

@llvmbot
Copy link
Member

llvmbot commented Jun 24, 2025

@llvm/pr-subscribers-clang-codegen

Author: Andrew Rogers (andrurogerz)

Changes

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch ensures a few cl::opt declarations are properly annotated with LLVM_ABI. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build.

Background

This effort is tracked in #109483. Additional context is provided in this discourse, and documentation for LLVM_ABI and related annotations is found in the LLVM repo here.

Overview

  • Remove local extern declarations of llvm::PrintPipelinePasses because it is already correctly declared with an LLVM_ABI annotation in llvm\Passes\PassBuilder.h. Leaving these declarations results in a gcc compile warning unless they are also annotated with LLVM_ABI.
  • Similarly, remove local extern declarations of ProfileSummaryCutoffHot and UseContextLessSummary from llvm/tools/llvm-profgen/ProfileGenerator.cpp since they are declared with LLVM_ABI in llvm\ProfileData\ProfileCommon.h.
  • Explicitly annotate the extern declaration of ProfileCorrelate in clang/lib/CodeGen/BackendUtil.cpp since it is not declared in a header. The definition of ProfileCorrelate in llvm\lib\Transforms\Instrumentation\InstrProfiling.cpp is already annotated with LLVM_ABI.

Validation

Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:

  • Windows with MSVC
  • Windows with Clang
  • Linux with GCC
  • Linux with Clang
  • Darwin with Clang

Full diff: https://github.com/llvm/llvm-project/pull/145374.diff

3 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (+3-3)
  • (modified) flang/lib/Frontend/FrontendActions.cpp (-4)
  • (modified) llvm/tools/llvm-profgen/ProfileGenerator.cpp (-2)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 7e0a3cf5591ce..97bc063ad34e5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -43,6 +43,7 @@
 #include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Program.h"
@@ -96,8 +97,6 @@ using namespace llvm;
 #include "llvm/Support/Extension.def"
 
 namespace llvm {
-extern cl::opt<bool> PrintPipelinePasses;
-
 // Experiment to move sanitizers earlier.
 static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
     "sanitizer-early-opt-ep", cl::Optional,
@@ -118,7 +117,8 @@ static cl::opt<PGOOptions::ColdFuncOpt> ClPGOColdFuncAttr(
                clEnumValN(PGOOptions::ColdFuncOpt::OptNone, "optnone",
                           "Mark cold functions with optnone.")));
 
-extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
+LLVM_ABI extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind>
+    ProfileCorrelate;
 } // namespace llvm
 namespace clang {
 extern llvm::cl::opt<bool> ClSanitizeGuardChecks;
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index d684eeb696755..bf15def3f3b2e 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -74,10 +74,6 @@
 #include <memory>
 #include <system_error>
 
-namespace llvm {
-extern cl::opt<bool> PrintPipelinePasses;
-} // namespace llvm
-
 using namespace Fortran::frontend;
 
 constexpr llvm::StringLiteral timingIdParse = "Parse";
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index b47c77c5f2ff3..db686c3b597eb 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -108,8 +108,6 @@ using namespace llvm;
 using namespace sampleprof;
 
 namespace llvm {
-extern cl::opt<int> ProfileSummaryCutoffHot;
-extern cl::opt<bool> UseContextLessSummary;
 
 namespace sampleprof {
 

@andrurogerz
Copy link
Contributor Author

@compnerd, @vgvassilev another hopefully quick one, thanks!

@compnerd compnerd merged commit a451fff into llvm:main Jun 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants