Skip to content

Commit abbdd16

Browse files
authored
[llvm] minor fixes for clang-cl Windows DLL build (#144386)
## 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](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). ## Overview Specific changes made in this patch: - Remove `constexpr` fields that reference DLL exported symbols. These symbols cannot be resolved at compile time when building a Windows DLL using `clang-cl`, so they cannot be `constexpr`. Instead, they are made `const` and initialized in the implementation file rather than at declaration in the header. - Annotate symbols now defined out-of-line with `LLVM_ABI` so they are exported when building as a shared library. - Explicitly add default copy assignment operator for `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: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent 64155a3 commit abbdd16

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void Z3CrosscheckVisitor::finalizeVisitor(BugReporterContext &BRC,
9292
};
9393

9494
auto AttemptOnce = [&](const llvm::SMTSolverRef &Solver) -> Z3Result {
95-
constexpr auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
95+
auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
9696
unsigned InitialRLimit = GetUsedRLimit(Solver);
9797
double Start = getCurrentTime(/*Start=*/true).getWallTime();
9898
std::optional<bool> IsSAT = Solver->check();

llvm/include/llvm/BinaryFormat/Dwarf.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,32 +1191,32 @@ template <typename Enum> struct EnumTraits : public std::false_type {};
11911191

11921192
template <> struct EnumTraits<Attribute> : public std::true_type {
11931193
static constexpr char Type[3] = "AT";
1194-
static constexpr StringRef (*StringFn)(unsigned) = &AttributeString;
1194+
LLVM_ABI static StringRef (*const StringFn)(unsigned);
11951195
};
11961196

11971197
template <> struct EnumTraits<Form> : public std::true_type {
11981198
static constexpr char Type[5] = "FORM";
1199-
static constexpr StringRef (*StringFn)(unsigned) = &FormEncodingString;
1199+
LLVM_ABI static StringRef (*const StringFn)(unsigned);
12001200
};
12011201

12021202
template <> struct EnumTraits<Index> : public std::true_type {
12031203
static constexpr char Type[4] = "IDX";
1204-
static constexpr StringRef (*StringFn)(unsigned) = &IndexString;
1204+
LLVM_ABI static StringRef (*const StringFn)(unsigned);
12051205
};
12061206

12071207
template <> struct EnumTraits<Tag> : public std::true_type {
12081208
static constexpr char Type[4] = "TAG";
1209-
static constexpr StringRef (*StringFn)(unsigned) = &TagString;
1209+
LLVM_ABI static StringRef (*const StringFn)(unsigned);
12101210
};
12111211

12121212
template <> struct EnumTraits<LineNumberOps> : public std::true_type {
12131213
static constexpr char Type[4] = "LNS";
1214-
static constexpr StringRef (*StringFn)(unsigned) = &LNStandardString;
1214+
LLVM_ABI static StringRef (*const StringFn)(unsigned);
12151215
};
12161216

12171217
template <> struct EnumTraits<LocationAtom> : public std::true_type {
12181218
static constexpr char Type[3] = "OP";
1219-
static constexpr StringRef (*StringFn)(unsigned) = &OperationEncodingString;
1219+
LLVM_ABI static StringRef (*const StringFn)(unsigned);
12201220
};
12211221

12221222
inline uint64_t computeTombstoneAddress(uint8_t AddressByteSize) {

llvm/include/llvm/Object/ELF.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,10 @@ class ELFFile {
256256
public:
257257
LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
258258

259-
// Default ctor required to instantiate the template for DLL export.
259+
// Default ctor and copy assignment operator required to instantiate the
260+
// template for DLL export.
260261
ELFFile(const ELFFile &) = default;
262+
ELFFile &operator=(const ELFFile &) = default;
261263

262264
// This is a callback that can be passed to a number of functions.
263265
// It can be used to ignore non-critical errors (warnings), which is

llvm/lib/BinaryFormat/Dwarf.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,18 @@ StringRef llvm::dwarf::RLEString(unsigned RLE) {
911911
}
912912
}
913913

914+
StringRef (*const llvm::dwarf::EnumTraits<Tag>::StringFn)(unsigned) = TagString;
915+
StringRef (*const llvm::dwarf::EnumTraits<Attribute>::StringFn)(unsigned) =
916+
AttributeString;
917+
StringRef (*const llvm::dwarf::EnumTraits<Form>::StringFn)(unsigned) =
918+
FormEncodingString;
919+
StringRef (*const llvm::dwarf::EnumTraits<LocationAtom>::StringFn)(unsigned) =
920+
OperationEncodingString;
921+
StringRef (*const llvm::dwarf::EnumTraits<LineNumberOps>::StringFn)(unsigned) =
922+
LNStandardString;
923+
StringRef (*const llvm::dwarf::EnumTraits<Index>::StringFn)(unsigned) =
924+
IndexString;
925+
914926
constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
915927
constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
916928
constexpr char llvm::dwarf::EnumTraits<Index>::Type[];

0 commit comments

Comments
 (0)