<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Already reverted in r277008.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">John<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Mike Aizatsky [mailto:aizatsky@google.com]
<br>
<b>Sent:</b> 28 July 2016 21:19<br>
<b>To:</b> John Brawn; llvm-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm] r276973 - Reapply r276856 "Adjust Registry interface to not require plugins to export a registry"<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">John,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Looks like this change breaks build. Could you take a look?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><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><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">/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]<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    static iterator begin() { return iterator(Head); }<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">                                              ^<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">/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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">  for (PragmaHandlerRegistry::iterator it = PragmaHandlerRegistry::begin(),<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">                                                                   ^<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">/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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    static node *Head, *Tail;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">                 ^<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">/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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    static iterator begin() { return iterator(Head); }<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">                                              ^<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">1 error generated.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">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:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">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" 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" 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" 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" 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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</blockquote>
</div>
<div>
<p class="MsoNormal">-- <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mike<br>
Sent from phone<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>