-
Notifications
You must be signed in to change notification settings - Fork 14k
[llvm] minor fixes for clang-cl Windows DLL build #144386
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
Conversation
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Andrew Rogers (andrurogerz) ChangesPurposeThis patch makes a minor changes to LLVM and Clang so that LLVM can be built as a Windows DLL with BackgroundThe Windows DLL effort is tracked in #109483. Additional context is provided in this discourse, and documentation for OverviewSpecific changes made in this patch:
ValidationLocal builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:
Full diff: https://github.com/llvm/llvm-project/pull/144386.diff 4 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp b/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
index 836fc375809ad..f965bfb590d80 100644
--- a/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
@@ -92,7 +92,7 @@ void Z3CrosscheckVisitor::finalizeVisitor(BugReporterContext &BRC,
};
auto AttemptOnce = [&](const llvm::SMTSolverRef &Solver) -> Z3Result {
- constexpr auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
+ auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
unsigned InitialRLimit = GetUsedRLimit(Solver);
double Start = getCurrentTime(/*Start=*/true).getWallTime();
std::optional<bool> IsSAT = Solver->check();
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 2ead62025efa7..231b7ac17d75f 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -1191,32 +1191,32 @@ template <typename Enum> struct EnumTraits : public std::false_type {};
template <> struct EnumTraits<Attribute> : public std::true_type {
static constexpr char Type[3] = "AT";
- static constexpr StringRef (*StringFn)(unsigned) = &AttributeString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<Form> : public std::true_type {
static constexpr char Type[5] = "FORM";
- static constexpr StringRef (*StringFn)(unsigned) = &FormEncodingString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<Index> : public std::true_type {
static constexpr char Type[4] = "IDX";
- static constexpr StringRef (*StringFn)(unsigned) = &IndexString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<Tag> : public std::true_type {
static constexpr char Type[4] = "TAG";
- static constexpr StringRef (*StringFn)(unsigned) = &TagString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<LineNumberOps> : public std::true_type {
static constexpr char Type[4] = "LNS";
- static constexpr StringRef (*StringFn)(unsigned) = &LNStandardString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<LocationAtom> : public std::true_type {
static constexpr char Type[3] = "OP";
- static constexpr StringRef (*StringFn)(unsigned) = &OperationEncodingString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
inline uint64_t computeTombstoneAddress(uint8_t AddressByteSize) {
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index a0dc522e13cab..8d7545144dfd9 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -256,8 +256,10 @@ class ELFFile {
public:
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
- // Default ctor required to instantiate the template for DLL export.
+ // Default ctor and copy assignment operator required to instantiate the
+ // template for DLL export.
ELFFile(const ELFFile &) = default;
+ ELFFile &operator=(const ELFFile &) = default;
// This is a callback that can be passed to a number of functions.
// It can be used to ignore non-critical errors (warnings), which is
diff --git a/llvm/lib/BinaryFormat/Dwarf.cpp b/llvm/lib/BinaryFormat/Dwarf.cpp
index b9b10a541b263..0d17dc175fed9 100644
--- a/llvm/lib/BinaryFormat/Dwarf.cpp
+++ b/llvm/lib/BinaryFormat/Dwarf.cpp
@@ -911,6 +911,18 @@ StringRef llvm::dwarf::RLEString(unsigned RLE) {
}
}
+StringRef (*const llvm::dwarf::EnumTraits<Tag>::StringFn)(unsigned) = TagString;
+StringRef (*const llvm::dwarf::EnumTraits<Attribute>::StringFn)(unsigned) =
+ AttributeString;
+StringRef (*const llvm::dwarf::EnumTraits<Form>::StringFn)(unsigned) =
+ FormEncodingString;
+StringRef (*const llvm::dwarf::EnumTraits<LocationAtom>::StringFn)(unsigned) =
+ OperationEncodingString;
+StringRef (*const llvm::dwarf::EnumTraits<LineNumberOps>::StringFn)(unsigned) =
+ LNStandardString;
+StringRef (*const llvm::dwarf::EnumTraits<Index>::StringFn)(unsigned) =
+ IndexString;
+
constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
constexpr char llvm::dwarf::EnumTraits<Index>::Type[];
|
@llvm/pr-subscribers-debuginfo Author: Andrew Rogers (andrurogerz) ChangesPurposeThis patch makes a minor changes to LLVM and Clang so that LLVM can be built as a Windows DLL with BackgroundThe Windows DLL effort is tracked in #109483. Additional context is provided in this discourse, and documentation for OverviewSpecific changes made in this patch:
ValidationLocal builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:
Full diff: https://github.com/llvm/llvm-project/pull/144386.diff 4 Files Affected:
diff --git a/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp b/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
index 836fc375809ad..f965bfb590d80 100644
--- a/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
@@ -92,7 +92,7 @@ void Z3CrosscheckVisitor::finalizeVisitor(BugReporterContext &BRC,
};
auto AttemptOnce = [&](const llvm::SMTSolverRef &Solver) -> Z3Result {
- constexpr auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
+ auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
unsigned InitialRLimit = GetUsedRLimit(Solver);
double Start = getCurrentTime(/*Start=*/true).getWallTime();
std::optional<bool> IsSAT = Solver->check();
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 2ead62025efa7..231b7ac17d75f 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -1191,32 +1191,32 @@ template <typename Enum> struct EnumTraits : public std::false_type {};
template <> struct EnumTraits<Attribute> : public std::true_type {
static constexpr char Type[3] = "AT";
- static constexpr StringRef (*StringFn)(unsigned) = &AttributeString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<Form> : public std::true_type {
static constexpr char Type[5] = "FORM";
- static constexpr StringRef (*StringFn)(unsigned) = &FormEncodingString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<Index> : public std::true_type {
static constexpr char Type[4] = "IDX";
- static constexpr StringRef (*StringFn)(unsigned) = &IndexString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<Tag> : public std::true_type {
static constexpr char Type[4] = "TAG";
- static constexpr StringRef (*StringFn)(unsigned) = &TagString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<LineNumberOps> : public std::true_type {
static constexpr char Type[4] = "LNS";
- static constexpr StringRef (*StringFn)(unsigned) = &LNStandardString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
template <> struct EnumTraits<LocationAtom> : public std::true_type {
static constexpr char Type[3] = "OP";
- static constexpr StringRef (*StringFn)(unsigned) = &OperationEncodingString;
+ LLVM_ABI static StringRef (*const StringFn)(unsigned);
};
inline uint64_t computeTombstoneAddress(uint8_t AddressByteSize) {
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index a0dc522e13cab..8d7545144dfd9 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -256,8 +256,10 @@ class ELFFile {
public:
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
- // Default ctor required to instantiate the template for DLL export.
+ // Default ctor and copy assignment operator required to instantiate the
+ // template for DLL export.
ELFFile(const ELFFile &) = default;
+ ELFFile &operator=(const ELFFile &) = default;
// This is a callback that can be passed to a number of functions.
// It can be used to ignore non-critical errors (warnings), which is
diff --git a/llvm/lib/BinaryFormat/Dwarf.cpp b/llvm/lib/BinaryFormat/Dwarf.cpp
index b9b10a541b263..0d17dc175fed9 100644
--- a/llvm/lib/BinaryFormat/Dwarf.cpp
+++ b/llvm/lib/BinaryFormat/Dwarf.cpp
@@ -911,6 +911,18 @@ StringRef llvm::dwarf::RLEString(unsigned RLE) {
}
}
+StringRef (*const llvm::dwarf::EnumTraits<Tag>::StringFn)(unsigned) = TagString;
+StringRef (*const llvm::dwarf::EnumTraits<Attribute>::StringFn)(unsigned) =
+ AttributeString;
+StringRef (*const llvm::dwarf::EnumTraits<Form>::StringFn)(unsigned) =
+ FormEncodingString;
+StringRef (*const llvm::dwarf::EnumTraits<LocationAtom>::StringFn)(unsigned) =
+ OperationEncodingString;
+StringRef (*const llvm::dwarf::EnumTraits<LineNumberOps>::StringFn)(unsigned) =
+ LNStandardString;
+StringRef (*const llvm::dwarf::EnumTraits<Index>::StringFn)(unsigned) =
+ IndexString;
+
constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
constexpr char llvm::dwarf::EnumTraits<Index>::Type[];
|
@compnerd, @vgvassilev these are some minor patches required to build LLVM as a Windows DLL with clang-cl. Mind having a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work with cl
? If so, we should file an issue to track the appropriate functionality support in clang-cl.
Yes, Windows DLL builds fine without these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is odd to me that this works with cl
, I think that the clang semantics are technically correct. But, when in Rome ....
Yes, agreed. And in case it wasn't clear, this is |
Purpose
This patch makes a minor changes to LLVM and Clang so that LLVM can be built as a Windows DLL with
clang-cl
. These changes were not required for building a Windows DLL with MSVC.Background
The Windows DLL 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
Specific changes made in this patch:
constexpr
fields that reference DLL exported symbols. These symbols cannot be resolved at compile time when building a Windows DLL usingclang-cl
, so they cannot beconstexpr
. Instead, they are madeconst
and initialized in the implementation file rather than at declaration in the header.LLVM_ABI
so they are exported when building as a shared library.ELFFile
to resolve a compiler warning.Validation
Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: