Skip to content

Commit b0a5cdc

Browse files
authored
Merge pull request #11117 from andrurogerz/swiftlang/stable/21.x
[llvm] support Windows DLL build of LLVM
2 parents 1fc62bf + 32ffe48 commit b0a5cdc

File tree

19 files changed

+218
-122
lines changed

19 files changed

+218
-122
lines changed

libcxxabi/src/demangle/DemangleConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,8 @@
115115
#define DEMANGLE_NAMESPACE_BEGIN namespace { namespace itanium_demangle {
116116
#define DEMANGLE_NAMESPACE_END } }
117117

118+
// The DEMANGLE_ABI macro resolves to nothing when building libc++abi. Only
119+
// the llvm copy defines DEMANGLE_ABI as a visibility attribute.
120+
#define DEMANGLE_ABI
121+
118122
#endif // LIBCXXABI_DEMANGLE_DEMANGLE_CONFIG_H

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
30493049
Node *parse(bool ParseParams = true);
30503050
};
30513051

3052-
const char* parse_discriminator(const char* first, const char* last);
3052+
DEMANGLE_ABI const char *parse_discriminator(const char *first,
3053+
const char *last);
30533054

30543055
// <name> ::= <nested-name> // N
30553056
// ::= <local-name> # See Scope Encoding below // Z

llvm/include/llvm/Analysis/IR2Vec.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,28 @@ class Vocabulary {
164164

165165
public:
166166
Vocabulary() = default;
167-
Vocabulary(VocabVector &&Vocab);
167+
LLVM_ABI Vocabulary(VocabVector &&Vocab);
168168

169-
bool isValid() const;
170-
unsigned getDimension() const;
171-
size_t size() const;
169+
LLVM_ABI bool isValid() const;
170+
LLVM_ABI unsigned getDimension() const;
171+
LLVM_ABI size_t size() const;
172172

173173
/// Helper function to get vocabulary key for a given Opcode
174-
static StringRef getVocabKeyForOpcode(unsigned Opcode);
174+
LLVM_ABI static StringRef getVocabKeyForOpcode(unsigned Opcode);
175175

176176
/// Helper function to get vocabulary key for a given TypeID
177-
static StringRef getVocabKeyForTypeID(Type::TypeID TypeID);
177+
LLVM_ABI static StringRef getVocabKeyForTypeID(Type::TypeID TypeID);
178178

179179
/// Helper function to get vocabulary key for a given OperandKind
180-
static StringRef getVocabKeyForOperandKind(OperandKind Kind);
180+
LLVM_ABI static StringRef getVocabKeyForOperandKind(OperandKind Kind);
181181

182182
/// Helper function to classify an operand into OperandKind
183-
static OperandKind getOperandKind(const Value *Op);
183+
LLVM_ABI static OperandKind getOperandKind(const Value *Op);
184184

185185
/// Accessors to get the embedding for a given entity.
186-
const ir2vec::Embedding &operator[](unsigned Opcode) const;
187-
const ir2vec::Embedding &operator[](Type::TypeID TypeId) const;
188-
const ir2vec::Embedding &operator[](const Value *Arg) const;
186+
LLVM_ABI const ir2vec::Embedding &operator[](unsigned Opcode) const;
187+
LLVM_ABI const ir2vec::Embedding &operator[](Type::TypeID TypeId) const;
188+
LLVM_ABI const ir2vec::Embedding &operator[](const Value *Arg) const;
189189

190190
/// Const Iterator type aliases
191191
using const_iterator = VocabVector::const_iterator;
@@ -212,13 +212,13 @@ class Vocabulary {
212212
/// Returns the string key for a given index position in the vocabulary.
213213
/// This is useful for debugging or printing the vocabulary. Do not use this
214214
/// for embedding generation as string based lookups are inefficient.
215-
static StringRef getStringKey(unsigned Pos);
215+
LLVM_ABI static StringRef getStringKey(unsigned Pos);
216216

217217
/// Create a dummy vocabulary for testing purposes.
218-
static VocabVector createDummyVocabForTest(unsigned Dim = 1);
218+
LLVM_ABI static VocabVector createDummyVocabForTest(unsigned Dim = 1);
219219

220-
bool invalidate(Module &M, const PreservedAnalyses &PA,
221-
ModuleAnalysisManager::Invalidator &Inv) const;
220+
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
221+
ModuleAnalysisManager::Invalidator &Inv) const;
222222
};
223223

224224
/// Embedder provides the interface to generate embeddings (vector

llvm/include/llvm/CodeGen/GCMetadata.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ class GCFunctionInfo {
101101
// are live per safe point (1.5% on 64-bit hosts).
102102

103103
public:
104-
GCFunctionInfo(const Function &F, GCStrategy &S);
105-
~GCFunctionInfo();
104+
LLVM_ABI GCFunctionInfo(const Function &F, GCStrategy &S);
105+
LLVM_ABI ~GCFunctionInfo();
106106

107107
/// Handle invalidation explicitly.
108-
bool invalidate(Function &F, const PreservedAnalyses &PA,
109-
FunctionAnalysisManager::Invalidator &Inv);
108+
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA,
109+
FunctionAnalysisManager::Invalidator &Inv);
110110

111111
/// getFunction - Return the function to which this metadata applies.
112112
const Function &getFunction() const { return F; }
@@ -163,8 +163,8 @@ class GCStrategyMap {
163163
GCStrategyMap(GCStrategyMap &&) = default;
164164

165165
/// Handle invalidation explicitly.
166-
bool invalidate(Module &M, const PreservedAnalyses &PA,
167-
ModuleAnalysisManager::Invalidator &Inv);
166+
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
167+
ModuleAnalysisManager::Invalidator &Inv);
168168

169169
using iterator = MapT::iterator;
170170
using const_iterator = MapT::const_iterator;
@@ -205,7 +205,7 @@ class CollectorMetadataAnalysis
205205

206206
public:
207207
using Result = GCStrategyMap;
208-
Result run(Module &M, ModuleAnalysisManager &MAM);
208+
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &MAM);
209209
};
210210

211211
/// An analysis pass which caches information about the Function.
@@ -217,7 +217,7 @@ class GCFunctionAnalysis : public AnalysisInfoMixin<GCFunctionAnalysis> {
217217

218218
public:
219219
using Result = GCFunctionInfo;
220-
Result run(Function &F, FunctionAnalysisManager &FAM);
220+
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM);
221221
};
222222

223223
/// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
@@ -228,7 +228,7 @@ class GCFunctionAnalysis : public AnalysisInfoMixin<GCFunctionAnalysis> {
228228
/// This pass requires `CollectorMetadataAnalysis`.
229229
class GCLoweringPass : public PassInfoMixin<GCLoweringPass> {
230230
public:
231-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
231+
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
232232
};
233233

234234
/// An analysis pass which caches information about the entire Module.
@@ -244,7 +244,7 @@ class GCModuleInfo : public ImmutablePass {
244244
/// Lookup the GCStrategy object associated with the given gc name.
245245
/// Objects are owned internally; No caller should attempt to delete the
246246
/// returned objects.
247-
GCStrategy *getGCStrategy(const StringRef Name);
247+
LLVM_ABI GCStrategy *getGCStrategy(const StringRef Name);
248248

249249
/// List of per function info objects. In theory, Each of these
250250
/// may be associated with a different GC.
@@ -265,14 +265,14 @@ class GCModuleInfo : public ImmutablePass {
265265
public:
266266
using iterator = SmallVector<std::unique_ptr<GCStrategy>, 1>::const_iterator;
267267

268-
static char ID;
268+
LLVM_ABI static char ID;
269269

270-
GCModuleInfo();
270+
LLVM_ABI GCModuleInfo();
271271

272272
/// clear - Resets the pass. Any pass, which uses GCModuleInfo, should
273273
/// call it in doFinalization().
274274
///
275-
void clear();
275+
LLVM_ABI void clear();
276276

277277
/// begin/end - Iterators for used strategies.
278278
///
@@ -282,7 +282,7 @@ class GCModuleInfo : public ImmutablePass {
282282
/// get - Look up function metadata. This is currently assumed
283283
/// have the side effect of initializing the associated GCStrategy. That
284284
/// will soon change.
285-
GCFunctionInfo &getFunctionInfo(const Function &F);
285+
LLVM_ABI GCFunctionInfo &getFunctionInfo(const Function &F);
286286
};
287287

288288
} // end namespace llvm

llvm/include/llvm/Config/abi-breaking.h.cmake

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,41 @@
1212
#ifndef LLVM_ABI_BREAKING_CHECKS_H
1313
#define LLVM_ABI_BREAKING_CHECKS_H
1414

15+
// llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
16+
#include "llvm/Config/llvm-config.h"
17+
1518
/* Define to enable checks that alter the LLVM C++ ABI */
1619
#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS
1720

1821
/* Define to enable reverse iteration of unordered llvm containers */
1922
#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION
2023

24+
#if !defined(__has_attribute)
25+
#define __has_attribute(attribute) 0
26+
#endif
27+
28+
// Properly annotate EnableABIBreakingChecks or DisableABIBreakingChecks for
29+
// export from shared library.
30+
// TODO(https://github.com/llvm/llvm-project/issues/145406): eliminate need for
31+
// two preprocessor definitions to gate LLVM_ABI macro definitions.
32+
#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
33+
#define ABI_BREAKING_EXPORT_ABI
34+
#else
35+
#if defined(_WIN32)
36+
#if defined(LLVM_EXPORTS)
37+
#define ABI_BREAKING_EXPORT_ABI __declspec(dllexport)
38+
#else
39+
#define ABI_BREAKING_EXPORT_ABI __declspec(dllimport)
40+
#endif
41+
#else
42+
#if __has_attribute(visibility)
43+
#define ABI_BREAKING_EXPORT_ABI __attribute__((__visibility__("default")))
44+
#else
45+
#define ABI_BREAKING_EXPORT_ABI
46+
#endif
47+
#endif
48+
#endif
49+
2150
/* Allow selectively disabling link-time mismatch checking so that header-only
2251
ADT content from LLVM can be used without linking libSupport. */
2352
#if !defined(LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING) || !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING
@@ -43,12 +72,12 @@
4372
#endif
4473
namespace llvm {
4574
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
46-
extern int EnableABIBreakingChecks;
75+
ABI_BREAKING_EXPORT_ABI extern int EnableABIBreakingChecks;
4776
LLVM_HIDDEN_VISIBILITY
4877
__attribute__((weak)) int *VerifyEnableABIBreakingChecks =
4978
&EnableABIBreakingChecks;
5079
#else
51-
extern int DisableABIBreakingChecks;
80+
ABI_BREAKING_EXPORT_ABI extern int DisableABIBreakingChecks;
5281
LLVM_HIDDEN_VISIBILITY
5382
__attribute__((weak)) int *VerifyDisableABIBreakingChecks =
5483
&DisableABIBreakingChecks;

llvm/include/llvm/Demangle/Demangle.h

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_DEMANGLE_DEMANGLE_H
1010
#define LLVM_DEMANGLE_DEMANGLE_H
1111

12+
#include "DemangleConfig.h"
1213
#include <cstddef>
1314
#include <optional>
1415
#include <string>
@@ -33,7 +34,8 @@ enum : int {
3334
/// Returns a non-NULL pointer to a NUL-terminated C style string
3435
/// that should be explicitly freed, if successful. Otherwise, may return
3536
/// nullptr if mangled_name is not a valid mangling or is nullptr.
36-
char *itaniumDemangle(std::string_view mangled_name, bool ParseParams = true);
37+
DEMANGLE_ABI char *itaniumDemangle(std::string_view mangled_name,
38+
bool ParseParams = true);
3739

3840
enum MSDemangleFlags {
3941
MSDF_None = 0,
@@ -52,87 +54,90 @@ enum MSDemangleFlags {
5254
/// bytes of the input string were consumed.
5355
/// status receives one of the demangle_ enum entries above if it's not nullptr.
5456
/// Flags controls various details of the demangled representation.
55-
char *microsoftDemangle(std::string_view mangled_name, size_t *n_read,
56-
int *status, MSDemangleFlags Flags = MSDF_None);
57+
DEMANGLE_ABI char *microsoftDemangle(std::string_view mangled_name,
58+
size_t *n_read, int *status,
59+
MSDemangleFlags Flags = MSDF_None);
5760

58-
std::optional<size_t>
61+
DEMANGLE_ABI std::optional<size_t>
5962
getArm64ECInsertionPointInMangledName(std::string_view MangledName);
6063

6164
// Demangles a Rust v0 mangled symbol.
62-
char *rustDemangle(std::string_view MangledName);
65+
DEMANGLE_ABI char *rustDemangle(std::string_view MangledName);
6366

6467
// Demangles a D mangled symbol.
65-
char *dlangDemangle(std::string_view MangledName);
68+
DEMANGLE_ABI char *dlangDemangle(std::string_view MangledName);
6669

6770
/// Attempt to demangle a string using different demangling schemes.
6871
/// The function uses heuristics to determine which demangling scheme to use.
6972
/// \param MangledName - reference to string to demangle.
7073
/// \returns - the demangled string, or a copy of the input string if no
7174
/// demangling occurred.
72-
std::string demangle(std::string_view MangledName);
75+
DEMANGLE_ABI std::string demangle(std::string_view MangledName);
7376

74-
bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result,
75-
bool CanHaveLeadingDot = true,
76-
bool ParseParams = true);
77+
DEMANGLE_ABI bool nonMicrosoftDemangle(std::string_view MangledName,
78+
std::string &Result,
79+
bool CanHaveLeadingDot = true,
80+
bool ParseParams = true);
7781

7882
/// "Partial" demangler. This supports demangling a string into an AST
7983
/// (typically an intermediate stage in itaniumDemangle) and querying certain
8084
/// properties or partially printing the demangled name.
8185
struct ItaniumPartialDemangler {
82-
ItaniumPartialDemangler();
86+
DEMANGLE_ABI ItaniumPartialDemangler();
8387

84-
ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
85-
ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
88+
DEMANGLE_ABI ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
89+
DEMANGLE_ABI ItaniumPartialDemangler &
90+
operator=(ItaniumPartialDemangler &&Other);
8691

8792
/// Demangle into an AST. Subsequent calls to the rest of the member functions
8893
/// implicitly operate on the AST this produces.
8994
/// \return true on error, false otherwise
90-
bool partialDemangle(const char *MangledName);
95+
DEMANGLE_ABI bool partialDemangle(const char *MangledName);
9196

9297
/// Just print the entire mangled name into Buf. Buf and N behave like the
9398
/// second and third parameters to __cxa_demangle.
94-
char *finishDemangle(char *Buf, size_t *N) const;
99+
DEMANGLE_ABI char *finishDemangle(char *Buf, size_t *N) const;
95100

96101
/// See \ref finishDemangle
97102
///
98103
/// \param[in] OB A llvm::itanium_demangle::OutputBuffer that the demangled
99104
/// name will be printed into.
100105
///
101-
char *finishDemangle(void *OB) const;
106+
DEMANGLE_ABI char *finishDemangle(void *OB) const;
102107

103108
/// Get the base name of a function. This doesn't include trailing template
104109
/// arguments, ie for "a::b<int>" this function returns "b".
105-
char *getFunctionBaseName(char *Buf, size_t *N) const;
110+
DEMANGLE_ABI char *getFunctionBaseName(char *Buf, size_t *N) const;
106111

107112
/// Get the context name for a function. For "a::b::c", this function returns
108113
/// "a::b".
109-
char *getFunctionDeclContextName(char *Buf, size_t *N) const;
114+
DEMANGLE_ABI char *getFunctionDeclContextName(char *Buf, size_t *N) const;
110115

111116
/// Get the entire name of this function.
112-
char *getFunctionName(char *Buf, size_t *N) const;
117+
DEMANGLE_ABI char *getFunctionName(char *Buf, size_t *N) const;
113118

114119
/// Get the parameters for this function.
115-
char *getFunctionParameters(char *Buf, size_t *N) const;
116-
char *getFunctionReturnType(char *Buf, size_t *N) const;
120+
DEMANGLE_ABI char *getFunctionParameters(char *Buf, size_t *N) const;
121+
DEMANGLE_ABI char *getFunctionReturnType(char *Buf, size_t *N) const;
117122

118123
/// If this function has any cv or reference qualifiers. These imply that
119124
/// the function is a non-static member function.
120-
bool hasFunctionQualifiers() const;
125+
DEMANGLE_ABI bool hasFunctionQualifiers() const;
121126

122127
/// If this symbol describes a constructor or destructor.
123-
bool isCtorOrDtor() const;
128+
DEMANGLE_ABI bool isCtorOrDtor() const;
124129

125130
/// If this symbol describes a function.
126-
bool isFunction() const;
131+
DEMANGLE_ABI bool isFunction() const;
127132

128133
/// If this symbol describes a variable.
129-
bool isData() const;
134+
DEMANGLE_ABI bool isData() const;
130135

131136
/// If this symbol is a <special-name>. These are generally implicitly
132137
/// generated by the implementation, such as vtables and typeinfo names.
133-
bool isSpecialName() const;
138+
DEMANGLE_ABI bool isSpecialName() const;
134139

135-
~ItaniumPartialDemangler();
140+
DEMANGLE_ABI ~ItaniumPartialDemangler();
136141

137142
private:
138143
void *RootNode;

llvm/include/llvm/Demangle/DemangleConfig.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef LLVM_DEMANGLE_DEMANGLECONFIG_H
1616
#define LLVM_DEMANGLE_DEMANGLECONFIG_H
1717

18+
// llvm-config.h is required for LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS
19+
#include "llvm/Config/llvm-config.h"
20+
1821
#ifndef __has_feature
1922
#define __has_feature(x) 0
2023
#endif
@@ -94,4 +97,24 @@
9497
#define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
9598
#define DEMANGLE_NAMESPACE_END } }
9699

100+
/// DEMANGLE_ABI is the export/visibility macro used to mark symbols delcared in
101+
/// llvm/Demangle as exported when built as a shared library.
102+
#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
103+
#define DEMANGLE_ABI
104+
#else
105+
#if defined(_WIN32)
106+
#if defined(LLVM_EXPORTS)
107+
#define DEMANGLE_ABI __declspec(dllexport)
108+
#else
109+
#define DEMANGLE_ABI __declspec(dllimport)
110+
#endif
111+
#else
112+
#if __has_attribute(visibility)
113+
#define DEMANGLE_ABI __attribute__((__visibility__("default")))
114+
#else
115+
#define DEMANGLE_ABI
116+
#endif
117+
#endif
118+
#endif
119+
97120
#endif

0 commit comments

Comments
 (0)