Skip to content

Commit beef0d9

Browse files
fsfodvgvassilev
authored andcommitted
Update llvm::Registry to work for LLVM shared library builds on windows
Windows doesn't implicitly import and merge exported symbols across shared libraries like Linux does so we need to explicitly export/import each instantiation of llvm::Registry. Updated LLVM_INSTANTIATE_REGISTRY macro to export Registry::add_node and Registry::begin() and add extern template declarations for the all instantiations of llvm::Registry.
1 parent 39ac8b2 commit beef0d9

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

clang/include/clang/Basic/ParsedAttrInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "clang/Basic/AttrSubjectMatchRules.h"
1919
#include "clang/Basic/AttributeCommonInfo.h"
20+
#include "clang/Support/Compiler.h"
2021
#include "llvm/ADT/ArrayRef.h"
2122
#include "llvm/Support/Registry.h"
2223
#include <climits>
@@ -175,4 +176,8 @@ const std::list<std::unique_ptr<ParsedAttrInfo>> &getAttributePluginInstances();
175176

176177
} // namespace clang
177178

179+
namespace llvm {
180+
extern template class CLANG_TEMPLATE_ABI llvm::Registry<clang::ParsedAttrInfo>;
181+
} // namespace llvm
182+
178183
#endif // LLVM_CLANG_BASIC_PARSEDATTRINFO_H

clang/include/clang/Frontend/FrontendPluginRegistry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H
1515

1616
#include "clang/Frontend/FrontendAction.h"
17+
#include "clang/Support/Compiler.h"
1718
#include "llvm/Support/Registry.h"
1819

1920
namespace clang {
@@ -23,4 +24,8 @@ using FrontendPluginRegistry = llvm::Registry<PluginASTAction>;
2324

2425
} // namespace clang
2526

27+
namespace llvm {
28+
extern template class CLANG_TEMPLATE_ABI Registry<clang::PluginASTAction>;
29+
} // namespace llvm
30+
2631
#endif // LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H

llvm/include/llvm/CodeGen/GCMetadataPrinter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class StackMaps;
3434
/// defaults from Registry.
3535
using GCMetadataPrinterRegistry = Registry<GCMetadataPrinter>;
3636

37+
extern template class LLVM_TEMPLATE_ABI Registry<GCMetadataPrinter>;
38+
3739
/// GCMetadataPrinter - Emits GC metadata as assembly code. Instances are
3840
/// created, managed, and owned by the AsmPrinter.
3941
class GCMetadataPrinter {

llvm/include/llvm/IR/GCStrategy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class GCStrategy {
141141
/// GCMetadataPrinterRegistery as well.
142142
using GCRegistry = Registry<GCStrategy>;
143143

144+
extern template class LLVM_TEMPLATE_ABI Registry<GCStrategy>;
145+
144146
/// Lookup the GCStrategy object associated with the given gc name.
145147
std::unique_ptr<GCStrategy> getGCStrategy(const StringRef Name);
146148

llvm/include/llvm/Support/Compiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
#define LLVM_ABI
180180
#define LLVM_TEMPLATE_ABI
181181
#define LLVM_EXPORT_TEMPLATE
182+
#define LLVM_ABI_EXPORT
182183
#elif defined(_WIN32) && !defined(__MINGW32__)
183184
#if defined(LLVM_EXPORTS)
184185
#define LLVM_ABI __declspec(dllexport)
@@ -189,19 +190,23 @@
189190
#define LLVM_TEMPLATE_ABI __declspec(dllimport)
190191
#define LLVM_EXPORT_TEMPLATE
191192
#endif
193+
#define LLVM_ABI_EXPORT __declspec(dllexport)
192194
#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX)
193195
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
194196
#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
195197
#define LLVM_EXPORT_TEMPLATE
198+
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
196199
#elif defined(__MACH__) || defined(__WASM__)
197200
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
198201
#define LLVM_TEMPLATE_ABI
199202
#define LLVM_EXPORT_TEMPLATE
203+
#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
200204
#endif
201205
#else
202206
#define LLVM_ABI
203207
#define LLVM_TEMPLATE_ABI
204208
#define LLVM_EXPORT_TEMPLATE
209+
#define LLVM_ABI_EXPORT
205210
#endif
206211
#define LLVM_C_ABI LLVM_ABI
207212
#endif

llvm/include/llvm/Support/Registry.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,29 @@ namespace llvm {
134134
/// strictly speaking that's not allowed by the C++ standard (we would need to
135135
/// have explicit specialization declarations in all translation units where the
136136
/// specialization is used) so we don't.
137-
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
138-
namespace llvm { \
139-
template<typename T> typename Registry<T>::node *Registry<T>::Head = nullptr;\
140-
template<typename T> typename Registry<T>::node *Registry<T>::Tail = nullptr;\
141-
template<typename T> \
142-
void Registry<T>::add_node(typename Registry<T>::node *N) { \
143-
if (Tail) \
144-
Tail->Next = N; \
145-
else \
146-
Head = N; \
147-
Tail = N; \
148-
} \
149-
template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150-
return iterator(Head); \
151-
} \
152-
template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Head; \
153-
template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Tail; \
154-
template \
155-
void Registry<REGISTRY_CLASS::type>::add_node(REGISTRY_CLASS::node*); \
156-
template REGISTRY_CLASS::iterator Registry<REGISTRY_CLASS::type>::begin(); \
137+
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
138+
namespace llvm { \
139+
template <typename T> \
140+
typename Registry<T>::node *Registry<T>::Head = nullptr; \
141+
template <typename T> \
142+
typename Registry<T>::node *Registry<T>::Tail = nullptr; \
143+
template <typename T> \
144+
void Registry<T>::add_node(typename Registry<T>::node *N) { \
145+
if (Tail) \
146+
Tail->Next = N; \
147+
else \
148+
Head = N; \
149+
Tail = N; \
150+
} \
151+
template <typename T> typename Registry<T>::iterator Registry<T>::begin() { \
152+
return iterator(Head); \
153+
} \
154+
template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Head; \
155+
template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Tail; \
156+
template LLVM_ABI_EXPORT void \
157+
Registry<REGISTRY_CLASS::type>::add_node(REGISTRY_CLASS::node *); \
158+
template LLVM_ABI_EXPORT REGISTRY_CLASS::iterator \
159+
Registry<REGISTRY_CLASS::type>::begin(); \
157160
}
158161

159162
#endif // LLVM_SUPPORT_REGISTRY_H

0 commit comments

Comments
 (0)