<div dir="ltr">John,<div><br></div><div>Looks like this change breaks build. Could you take a look?</div><div><br></div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/24923">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/24923</a><br></div><div><div>/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Support/Registry.h:96:47: error: instantiation of variable 'llvm::Registry<clang::PragmaHandler>::Head' required here, but no definition is available [-Werror,-Wundefined-var-template]</div><div> static iterator begin() { return iterator(Head); }</div><div> ^</div><div>/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/tools/clang/lib/Lex/Pragma.cpp:1495:68: note: in instantiation of member function 'llvm::Registry<clang::PragmaHandler>::begin' requested here</div><div> for (PragmaHandlerRegistry::iterator it = PragmaHandlerRegistry::begin(),</div><div> ^</div><div>/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Support/Registry.h:56:18: note: forward declaration of template entity is here</div><div> static node *Head, *Tail;</div><div> ^</div><div>/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/include/llvm/Support/Registry.h:96:47: note: add an explicit instantiation declaration to suppress this warning if 'llvm::Registry<clang::PragmaHandler>::Head' is explicitly instantiated in another translation unit</div><div> static iterator begin() { return iterator(Head); }</div><div> ^</div><div>1 error generated.</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 28, 2016 at 5:55 AM John Brawn via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: john.brawn<br>
Date: Thu Jul 28 07:48:17 2016<br>
New Revision: 276973<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=276973&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=276973&view=rev</a><br>
Log:<br>
Reapply r276856 "Adjust Registry interface to not require plugins to export a registry"<br>
<br>
This version has two fixes compared to the original:<br>
* In Registry.h the template static members are instantiated before they are<br>
used, as clang gives an error if you do it the other way around.<br>
* The use of the Registry template in clang-tidy is updated in the same way as<br>
has been done everywhere else.<br>
<br>
Original commit message:<br>
<br>
Currently the Registry class contains the vestiges of a previous attempt to<br>
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a<br>
plugin would have its own copy of a registry and export it to be imported by<br>
the tool that's loading the plugin. This only works if the plugin is entirely<br>
self-contained with the only interface between the plugin and tool being the<br>
registry, and in particular this conflicts with how IR pass plugins work.<br>
<br>
This patch changes things so that instead the add_node function of the registry<br>
is exported by the tool and then imported by the plugin, which solves this<br>
problem and also means that instead of every plugin having to export every<br>
registry they use instead LLVM only has to export the add_node functions. This<br>
allows plugins that use a registry to work on Windows if<br>
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/Support/Registry.h<br>
llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp<br>
llvm/trunk/lib/CodeGen/GCStrategy.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Support/Registry.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Registry.h?rev=276973&r1=276972&r2=276973&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Registry.h?rev=276973&r1=276972&r2=276973&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/Registry.h (original)<br>
+++ llvm/trunk/include/llvm/Support/Registry.h Thu Jul 28 07:48:17 2016<br>
@@ -69,13 +69,14 @@ namespace llvm {<br>
node(const entry &V) : Next(nullptr), Val(V) {}<br>
};<br>
<br>
- static void add_node(node *N) {<br>
- if (Tail)<br>
- Tail->Next = N;<br>
- else<br>
- Head = N;<br>
- Tail = N;<br>
- }<br>
+ /// Add a node to the Registry: this is the interface between the plugin and<br>
+ /// the executable.<br>
+ ///<br>
+ /// This function is exported by the executable and called by the plugin to<br>
+ /// add a node to the executable's registry. Therefore it's not defined here<br>
+ /// to avoid it being instantiated in the plugin and is instead defined in<br>
+ /// the executable (see LLVM_INSTANTIATE_REGISTRY below).<br>
+ static void add_node(node *N);<br>
<br>
/// Iterators for registry entries.<br>
///<br>
@@ -120,61 +121,23 @@ namespace llvm {<br>
add_node(&Node);<br>
}<br>
};<br>
-<br>
- /// A dynamic import facility. This is used on Windows to<br>
- /// import the entries added in the plugin.<br>
- static void import(sys::DynamicLibrary &DL, const char *RegistryName) {<br>
- typedef void *(*GetRegistry)();<br>
- std::string Name("LLVMGetRegistry_");<br>
- Name.append(RegistryName);<br>
- GetRegistry Getter =<br>
- (GetRegistry)(intptr_t)DL.getAddressOfSymbol(Name.c_str());<br>
- if (Getter) {<br>
- // Call the getter function in order to get the full copy of the<br>
- // registry defined in the plugin DLL, and copy them over to the<br>
- // current Registry.<br>
- typedef std::pair<const node *, const node *> Info;<br>
- Info *I = static_cast<Info *>(Getter());<br>
- iterator begin(I->first);<br>
- iterator end(I->second);<br>
- for (++end; begin != end; ++begin) {<br>
- // This Node object needs to remain alive for the<br>
- // duration of the program.<br>
- add_node(new node(*begin));<br>
- }<br>
- }<br>
- }<br>
-<br>
- /// Retrieve the data to be passed across DLL boundaries when<br>
- /// importing registries from another DLL on Windows.<br>
- static void *exportRegistry() {<br>
- static std::pair<const node *, const node *> Info(Head, Tail);<br>
- return &Info;<br>
- }<br>
};<br>
-<br>
-<br>
- // Since these are defined in a header file, plugins must be sure to export<br>
- // these symbols.<br>
- template <typename T><br>
- typename Registry<T>::node *Registry<T>::Head;<br>
-<br>
- template <typename T><br>
- typename Registry<T>::node *Registry<T>::Tail;<br>
} // end namespace llvm<br>
<br>
-#ifdef LLVM_ON_WIN32<br>
-#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS) \<br>
- extern "C" { \<br>
- __declspec(dllexport) void *__cdecl LLVMGetRegistry_##REGISTRY_CLASS() { \<br>
- return REGISTRY_CLASS::exportRegistry(); \<br>
- } \<br>
+/// Instantiate a registry class.<br>
+///<br>
+/// This instantiates add_node and the Head and Tail pointers.<br>
+#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \<br>
+ namespace llvm { \<br>
+ template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Head = nullptr; \<br>
+ template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Tail = nullptr; \<br>
+ template<> void REGISTRY_CLASS::add_node(REGISTRY_CLASS::node *N) { \<br>
+ if (Tail) \<br>
+ Tail->Next = N; \<br>
+ else \<br>
+ Head = N; \<br>
+ Tail = N; \<br>
+ } \<br>
}<br>
-#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL) \<br>
- REGISTRY_CLASS::import(DL, #REGISTRY_CLASS)<br>
-#else<br>
-#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS)<br>
-#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL)<br>
-#endif<br>
<br>
#endif // LLVM_SUPPORT_REGISTRY_H<br>
<br>
Modified: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp?rev=276973&r1=276972&r2=276973&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp?rev=276973&r1=276972&r2=276973&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp Thu Jul 28 07:48:17 2016<br>
@@ -14,6 +14,8 @@<br>
#include "llvm/CodeGen/GCMetadataPrinter.h"<br>
using namespace llvm;<br>
<br>
+LLVM_INSTANTIATE_REGISTRY(GCMetadataPrinterRegistry)<br>
+<br>
GCMetadataPrinter::GCMetadataPrinter() {}<br>
<br>
GCMetadataPrinter::~GCMetadataPrinter() {}<br>
<br>
Modified: llvm/trunk/lib/CodeGen/GCStrategy.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCStrategy.cpp?rev=276973&r1=276972&r2=276973&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCStrategy.cpp?rev=276973&r1=276972&r2=276973&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/GCStrategy.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/GCStrategy.cpp Thu Jul 28 07:48:17 2016<br>
@@ -16,6 +16,8 @@<br>
<br>
using namespace llvm;<br>
<br>
+LLVM_INSTANTIATE_REGISTRY(GCRegistry)<br>
+<br>
GCStrategy::GCStrategy()<br>
: UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),<br>
CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature">Mike<br>Sent from phone</div>