[PATCH] D16170: Registry initialization and linkage interactions

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 10:40:47 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL258157: [GC] Registry initialization and linkage interactions (authored by reames).

Changed prior to commit:
  http://reviews.llvm.org/D16170?vs=44819&id=45284#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16170

Files:
  llvm/trunk/include/llvm/Support/Registry.h
  llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
  llvm/trunk/lib/CodeGen/GCStrategy.cpp

Index: llvm/trunk/include/llvm/Support/Registry.h
===================================================================
--- llvm/trunk/include/llvm/Support/Registry.h
+++ llvm/trunk/include/llvm/Support/Registry.h
@@ -116,14 +116,15 @@
     };
   };
 
-  
-  // Since these are defined in a header file, plugins must be sure to export
-  // these symbols.
-  template <typename T>
-  typename Registry<T>::node *Registry<T>::Head;
-
-  template <typename T>
-  typename Registry<T>::node *Registry<T>::Tail;
+  // Use this macro to stamp out definitions for required static symbols in an
+  // appropriate source file.  This is required to avoid getting multiple
+  // definitions of the Registry's fields in different translation or linkage
+  // units.   
+#define DEFINE_REGISTRY(T)                      \
+  template <>                                    \
+  typename Registry<T>::node *Registry<T>::Head = nullptr; \
+  template <>                          \
+  typename Registry<T>::node *Registry<T>::Tail = nullptr;
 } // end namespace llvm
 
 #endif // LLVM_SUPPORT_REGISTRY_H
Index: llvm/trunk/lib/CodeGen/GCStrategy.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/GCStrategy.cpp
+++ llvm/trunk/lib/CodeGen/GCStrategy.cpp
@@ -20,3 +20,7 @@
     : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
       CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
       UsesMetadata(false) {}
+
+// Stamp out the registry of GCStrategy objects so that pulgins can load new
+// Strategies.  
+DEFINE_REGISTRY(GCStrategy)
Index: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
+++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
@@ -17,3 +17,7 @@
 GCMetadataPrinter::GCMetadataPrinter() {}
 
 GCMetadataPrinter::~GCMetadataPrinter() {}
+
+// Stamp out the registry of GCMetadataPrinter objects so that pulgins can load
+// new Strategies.  
+DEFINE_REGISTRY(GCMetadataPrinter)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16170.45284.patch
Type: text/x-patch
Size: 2073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160119/9b51477d/attachment.bin>


More information about the llvm-commits mailing list