[llvm] r276973 - Reapply r276856 "Adjust Registry interface to not require plugins to export a registry"

Mike Aizatsky via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 13:18:42 PDT 2016


John,

Looks like this change breaks build. Could you take a look?

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/24923
/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]
    static iterator begin() { return iterator(Head); }
                                              ^
/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
  for (PragmaHandlerRegistry::iterator it = PragmaHandlerRegistry::begin(),
                                                                   ^
/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
    static node *Head, *Tail;
                 ^
/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
    static iterator begin() { return iterator(Head); }
                                              ^
1 error generated.


On Thu, Jul 28, 2016 at 5:55 AM John Brawn via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: john.brawn
> Date: Thu Jul 28 07:48:17 2016
> New Revision: 276973
>
> URL: http://llvm.org/viewvc/llvm-project?rev=276973&view=rev
> Log:
> Reapply r276856 "Adjust Registry interface to not require plugins to
> export a registry"
>
> This version has two fixes compared to the original:
>  * In Registry.h the template static members are instantiated before they
> are
>    used, as clang gives an error if you do it the other way around.
>  * The use of the Registry template in clang-tidy is updated in the same
> way as
>    has been done everywhere else.
>
> Original commit message:
>
> Currently the Registry class contains the vestiges of a previous attempt to
> allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where
> a
> plugin would have its own copy of a registry and export it to be imported
> by
> the tool that's loading the plugin. This only works if the plugin is
> entirely
> self-contained with the only interface between the plugin and tool being
> the
> registry, and in particular this conflicts with how IR pass plugins work.
>
> This patch changes things so that instead the add_node function of the
> registry
> is exported by the tool and then imported by the plugin, which solves this
> problem and also means that instead of every plugin having to export every
> registry they use instead LLVM only has to export the add_node functions.
> This
> allows plugins that use a registry to work on Windows if
> LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.
>
> Modified:
>     llvm/trunk/include/llvm/Support/Registry.h
>     llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
>     llvm/trunk/lib/CodeGen/GCStrategy.cpp
>
> Modified: llvm/trunk/include/llvm/Support/Registry.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Registry.h?rev=276973&r1=276972&r2=276973&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/Registry.h (original)
> +++ llvm/trunk/include/llvm/Support/Registry.h Thu Jul 28 07:48:17 2016
> @@ -69,13 +69,14 @@ namespace llvm {
>        node(const entry &V) : Next(nullptr), Val(V) {}
>      };
>
> -    static void add_node(node *N) {
> -      if (Tail)
> -        Tail->Next = N;
> -      else
> -        Head = N;
> -      Tail = N;
> -    }
> +    /// Add a node to the Registry: this is the interface between the
> plugin and
> +    /// the executable.
> +    ///
> +    /// This function is exported by the executable and called by the
> plugin to
> +    /// add a node to the executable's registry. Therefore it's not
> defined here
> +    /// to avoid it being instantiated in the plugin and is instead
> defined in
> +    /// the executable (see LLVM_INSTANTIATE_REGISTRY below).
> +    static void add_node(node *N);
>
>      /// Iterators for registry entries.
>      ///
> @@ -120,61 +121,23 @@ namespace llvm {
>          add_node(&Node);
>        }
>      };
> -
> -    /// A dynamic import facility.  This is used on Windows to
> -    /// import the entries added in the plugin.
> -    static void import(sys::DynamicLibrary &DL, const char *RegistryName)
> {
> -      typedef void *(*GetRegistry)();
> -      std::string Name("LLVMGetRegistry_");
> -      Name.append(RegistryName);
> -      GetRegistry Getter =
> -          (GetRegistry)(intptr_t)DL.getAddressOfSymbol(Name.c_str());
> -      if (Getter) {
> -        // Call the getter function in order to get the full copy of the
> -        // registry defined in the plugin DLL, and copy them over to the
> -        // current Registry.
> -        typedef std::pair<const node *, const node *> Info;
> -        Info *I = static_cast<Info *>(Getter());
> -        iterator begin(I->first);
> -        iterator end(I->second);
> -        for (++end; begin != end; ++begin) {
> -          // This Node object needs to remain alive for the
> -          // duration of the program.
> -          add_node(new node(*begin));
> -        }
> -      }
> -    }
> -
> -    /// Retrieve the data to be passed across DLL boundaries when
> -    /// importing registries from another DLL on Windows.
> -    static void *exportRegistry() {
> -      static std::pair<const node *, const node *> Info(Head, Tail);
> -      return &Info;
> -    }
>    };
> -
> -
> -  // 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;
>  } // end namespace llvm
>
> -#ifdef LLVM_ON_WIN32
> -#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS)
>      \
> -  extern "C" {
>      \
> -  __declspec(dllexport) void *__cdecl LLVMGetRegistry_##REGISTRY_CLASS()
> {     \
> -    return REGISTRY_CLASS::exportRegistry();
>      \
> -  }
>       \
> +/// Instantiate a registry class.
> +///
> +/// This instantiates add_node and the Head and Tail pointers.
> +#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
> +  namespace llvm { \
> +  template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Head =
> nullptr; \
> +  template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Tail =
> nullptr; \
> +  template<> void REGISTRY_CLASS::add_node(REGISTRY_CLASS::node *N) { \
> +    if (Tail) \
> +      Tail->Next = N; \
> +    else \
> +      Head = N; \
> +    Tail = N; \
> +  } \
>    }
> -#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL)
>      \
> -  REGISTRY_CLASS::import(DL, #REGISTRY_CLASS)
> -#else
> -#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS)
> -#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL)
> -#endif
>
>  #endif // LLVM_SUPPORT_REGISTRY_H
>
> Modified: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp?rev=276973&r1=276972&r2=276973&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp Thu Jul 28 07:48:17 2016
> @@ -14,6 +14,8 @@
>  #include "llvm/CodeGen/GCMetadataPrinter.h"
>  using namespace llvm;
>
> +LLVM_INSTANTIATE_REGISTRY(GCMetadataPrinterRegistry)
> +
>  GCMetadataPrinter::GCMetadataPrinter() {}
>
>  GCMetadataPrinter::~GCMetadataPrinter() {}
>
> Modified: llvm/trunk/lib/CodeGen/GCStrategy.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCStrategy.cpp?rev=276973&r1=276972&r2=276973&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/GCStrategy.cpp (original)
> +++ llvm/trunk/lib/CodeGen/GCStrategy.cpp Thu Jul 28 07:48:17 2016
> @@ -16,6 +16,8 @@
>
>  using namespace llvm;
>
> +LLVM_INSTANTIATE_REGISTRY(GCRegistry)
> +
>  GCStrategy::GCStrategy()
>      : UseStatepoints(false), NeededSafePoints(0),
> CustomReadBarriers(false),
>        CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-- 
Mike
Sent from phone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/85fbb4ed/attachment.html>


More information about the llvm-commits mailing list