[llvm] r192316 - llvm-c: Make target initializer functions external functions in lib.

Rui Ueyama ruiu at google.com
Wed Oct 9 16:03:44 PDT 2013


Andreas,

I'll be rolling back this change now, as it broke the build because of the
circular dependency which Benjamin described below. Circular dependency is
bad and we shouldn't make such dependency in LLVM.


On Wed, Oct 9, 2013 at 2:54 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:

>
> On 09.10.2013, at 21:02, Anders Waldenborg <anders at 0x63.nu> wrote:
>
> > Author: andersg
> > Date: Wed Oct  9 14:02:09 2013
> > New Revision: 192316
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=192316&view=rev
> > Log:
> > llvm-c: Make target initializer functions external functions in lib.
> >
> > Making them proper functions defined in the (shared)lib instead of
> > static inlines defined in the header files makes it possible to
> > actually distribute a binary compiled against the shared library
> > without having to worry about getting undefined symbol errors when
> > calling e.g LLVMInitializeAllTargetInfos because the shared library on
> > the other system was compiled with different targets.
>
> Sorry, I missed the code review for this change. But there's a very good
> reason why this functionality was never part of llvm-c. Your commit adds a
> big layering violation to LLVM by adding a cyclic dependency.
>
> The individual LLVMInitializeXXXFunctions are part of the backends, now
> they're getting linked into libTarget. This creates a dependency from
> libTarget to all of the backends, which themselves depend on libTarget.
> That will break various users of LLVM which don't link everything into one
> big binary.
>
> I only see one way to fix this, and it's a bit nasty. Create a new
> sublibrary which depends on libTarget and all of the targets and put the
> function entry points there. Users can link that sublibrary when they need
> the functionality and it avoids adding cycles to the dependency graph.
>
> - Ben
>
> >
> > Differential Revision: http://llvm-reviews.chandlerc.com/D1714
> >
> >
> > Added:
> >    llvm/trunk/lib/Target/AllTargets.cpp
> > Modified:
> >    llvm/trunk/include/llvm-c/Target.h
> >    llvm/trunk/lib/Target/CMakeLists.txt
> >
> > Modified: llvm/trunk/include/llvm-c/Target.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Target.h?rev=192316&r1=192315&r2=192316&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm-c/Target.h (original)
> > +++ llvm/trunk/include/llvm-c/Target.h Wed Oct  9 14:02:09 2013
> > @@ -71,62 +71,37 @@ typedef struct LLVMStructLayout *LLVMStr
> >   void LLVMInitialize##TargetName##Disassembler(void);
> > #include "llvm/Config/Disassemblers.def"
> > #undef LLVM_DISASSEMBLER  /* Explicit undef to make SWIG happier */
> > -
> > +
> > /** LLVMInitializeAllTargetInfos - The main program should call this
> function if
> >     it wants access to all available targets that LLVM is configured to
> >     support. */
> > -static inline void LLVMInitializeAllTargetInfos(void) {
> > -#define LLVM_TARGET(TargetName)
> LLVMInitialize##TargetName##TargetInfo();
> > -#include "llvm/Config/Targets.def"
> > -#undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
> > -}
> > +void LLVMInitializeAllTargetInfos(void);
> >
> > /** LLVMInitializeAllTargets - The main program should call this
> function if it
> >     wants to link in all available targets that LLVM is configured to
> >     support. */
> > -static inline void LLVMInitializeAllTargets(void) {
> > -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
> > -#include "llvm/Config/Targets.def"
> > -#undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
> > -}
> > +void LLVMInitializeAllTargets(void);
> >
> > /** LLVMInitializeAllTargetMCs - The main program should call this
> function if
> >     it wants access to all available target MC that LLVM is configured to
> >     support. */
> > -static inline void LLVMInitializeAllTargetMCs(void) {
> > -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
> > -#include "llvm/Config/Targets.def"
> > -#undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
> > -}
> > -
> > +void LLVMInitializeAllTargetMCs(void);
> > +
> > /** LLVMInitializeAllAsmPrinters - The main program should call this
> function if
> >     it wants all asm printers that LLVM is configured to support, to
> make them
> >     available via the TargetRegistry. */
> > -static inline void LLVMInitializeAllAsmPrinters(void) {
> > -#define LLVM_ASM_PRINTER(TargetName)
> LLVMInitialize##TargetName##AsmPrinter();
> > -#include "llvm/Config/AsmPrinters.def"
> > -#undef LLVM_ASM_PRINTER  /* Explicit undef to make SWIG happier */
> > -}
> > -
> > +void LLVMInitializeAllAsmPrinters(void);
> > +
> > /** LLVMInitializeAllAsmParsers - The main program should call this
> function if
> >     it wants all asm parsers that LLVM is configured to support, to make
> them
> >     available via the TargetRegistry. */
> > -static inline void LLVMInitializeAllAsmParsers(void) {
> > -#define LLVM_ASM_PARSER(TargetName)
> LLVMInitialize##TargetName##AsmParser();
> > -#include "llvm/Config/AsmParsers.def"
> > -#undef LLVM_ASM_PARSER  /* Explicit undef to make SWIG happier */
> > -}
> > -
> > +void LLVMInitializeAllAsmParsers(void);
> > +
> > /** LLVMInitializeAllDisassemblers - The main program should call this
> function
> >     if it wants all disassemblers that LLVM is configured to support, to
> make
> >     them available via the TargetRegistry. */
> > -static inline void LLVMInitializeAllDisassemblers(void) {
> > -#define LLVM_DISASSEMBLER(TargetName) \
> > -  LLVMInitialize##TargetName##Disassembler();
> > -#include "llvm/Config/Disassemblers.def"
> > -#undef LLVM_DISASSEMBLER  /* Explicit undef to make SWIG happier */
> > -}
> > -
> > +void LLVMInitializeAllDisassemblers(void);
> > +
> > /** LLVMInitializeNativeTarget - The main program should call this
> function to
> >     initialize the native target corresponding to the host.  This is
> useful
> >     for JIT applications to ensure that the target gets linked in
> correctly. */
> >
> > Added: llvm/trunk/lib/Target/AllTargets.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AllTargets.cpp?rev=192316&view=auto
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/AllTargets.cpp (added)
> > +++ llvm/trunk/lib/Target/AllTargets.cpp Wed Oct  9 14:02:09 2013
> > @@ -0,0 +1,43 @@
> > +//===-- AllTargets.cpp
> ----------------------------------------------------===//
> > +//
> > +//                     The LLVM Compiler Infrastructure
> > +//
> > +// This file is distributed under the University of Illinois Open Source
> > +// License. See LICENSE.TXT for details.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +//
> > +// This file implements functions for initialization of different
> > +// aspects of all configured targets. When calling any of these
> > +// functions all configured targets must be linked in.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +
> > +#include "llvm-c/Target.h"
> > +#include "llvm/Support/TargetSelect.h"
> > +
> > +using namespace llvm;
> > +
> > +void LLVMInitializeAllTargetInfos(void) {
> > +  InitializeAllTargetInfos();
> > +}
> > +
> > +void LLVMInitializeAllTargets(void) {
> > +  InitializeAllTargets();
> > +}
> > +
> > +void LLVMInitializeAllTargetMCs(void) {
> > +  InitializeAllTargetMCs();
> > +}
> > +
> > +void LLVMInitializeAllAsmPrinters(void) {
> > +  InitializeAllAsmPrinters();
> > +}
> > +
> > +void LLVMInitializeAllAsmParsers(void) {
> > +  InitializeAllAsmParsers();
> > +}
> > +
> > +void LLVMInitializeAllDisassemblers(void) {
> > +  InitializeAllDisassemblers();
> > +}
> >
> > Modified: llvm/trunk/lib/Target/CMakeLists.txt
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CMakeLists.txt?rev=192316&r1=192315&r2=192316&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/CMakeLists.txt (original)
> > +++ llvm/trunk/lib/Target/CMakeLists.txt Wed Oct  9 14:02:09 2013
> > @@ -1,4 +1,5 @@
> > add_llvm_library(LLVMTarget
> > +  AllTargets.cpp
> >   Mangler.cpp
> >   Target.cpp
> >   TargetIntrinsicInfo.cpp
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131009/c27eed4e/attachment.html>


More information about the llvm-commits mailing list