llvm.org GIT mirror llvm / 42fe455
For PR780: 1. Change the usage of LOADABLE_MODULE so that it implies all the things necessary to make a loadable module. This reduces the user's burdern to get a loadable module correctly built. 2. Document the usage of LOADABLE_MODULE in the MakefileGuide 3. Adjust the makefile for lib/Transforms/Hello to use the new specification for building loadable modules 4. Adjust the sample project to not attempt to build a shared library for its little library. This was just wasteful and not instructive at all. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29551 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Spencer 14 years ago
5 changed file(s) with 71 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
322322
323323 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
324324 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
325 # shared library can be opened with dlopen
325 # shared library can be opened with dlopen. Also, LOADABLE_MODULE implies
326 # several other things so we force them to be defined/on.
327 ifdef LOADABLE_MODULE
328 SHARED_LIBRARY := 1
329 DONT_BUILD_RELINKED := 1
330 LINK_LIBS_IN_SHARED := 1
331 LD.Flags += -module
332 endif
333
326334 ifdef SHARED_LIBRARY
327335 LD.Flags += -rpath $(LibDir)
328 ifdef LOADABLE_MODULE
329 LD.Flags += -module
330 endif
331336 else
332337 LibTool.Flags += --tag=disable-shared
333338 endif
424429 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
425430 $(CXX.Flags)
426431 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
427 Link = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
428 $(CXX.Flags) $(CompileCommonOpts) $(LD.Flags) $(Strip)
429 Relink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
430 $(CXX.Flags) $(CompileCommonOpts) $(Relink.Flags)
432 Link = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
433 $(LD.Flags) $(Strip)
434 LTLink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Link)
435 Relink = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
436 $(Relink.Flags)
437 LTRelink = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Relink)
431438 LTInstall = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
432439 $(Install.Flags)
433440 ProgInstall = $(INSTALL) $(Install.StripFlag) -m 0755
771778 all-local:: $(LibName.LA)
772779
773780 ifdef LINK_LIBS_IN_SHARED
781 ifdef LOADABLE_MODULE
782 SharedLibKindMessage := "Lodable Module"
783 else
784 SharedLibKindMessage := "Shared Library"
785 endif
786 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
787 $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
788 $(LIBRARYNAME)$(SHLIBEXT)
789 $(Verb) $(LTLink) -o $@ $(ObjectsLO) $(ProjLibsOptions) \
790 $(LLVMLibsOptions)
791 $(Verb) $(LTInstall) $@ $(LibDir)
792 else
774793 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
775794 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
776 $(Verb) $(Link) -o $@ $(ObjectsLO) \
777 $(ProjLibsOptions) $(LLVMLibsOptions)
778 $(Verb) $(LTInstall) $@ $(LibDir)
779 else
780 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
781 $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
782 $(Verb) $(Link) -o $@ $(ObjectsLO)
795 $(Verb) $(LTLink) -o $@ $(ObjectsLO)
783796 $(Verb) $(LTInstall) $@ $(LibDir)
784797 endif
785798
883896
884897 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
885898 $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
886 $(Verb) $(Relink) -o $@ $(ObjectsO)
899 $(Verb) $(LTRelink) -o $@ $(ObjectsO)
887900
888901 clean-local::
889902 ifneq ($(strip $(LibName.O)),)
982995
983996 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
984997 $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
985 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
998 $(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
986999 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
9871000 $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
9881001 $(StripWarnMsg)
2929
3030
  • Libraries
  • 3131
    32
  • Bytecode Modules
  • 32
  • Bytecode Modules
  • 33
  • Loadable Modules
  • 3334
    3435
    3536
  • Tools
  • 258259
    259260
    260261
    261
    262
    262263
    263264

    In some situations, it is desireable to build a single bytecode module from

    264265 a variety of sources, instead of an archive, shared library, or bytecode
    276277 containing a bytecode module for each compiled source file. The difference is
    277278 subtle, but important depending on how the module or library is to be linked.
    278279

    280
    281
    282
    283
    284 Loadable Modules
    285
    286
    287

    In some situations, you need to create a loadable module. Loadable modules

    288 can be loaded into programs like opt or llc to specify
    289 additional passes to run or targets to support. Loadable modules are also
    290 useful for debugging a pass or providing a pass with another package if that
    291 pass can't be included in LLVM.

    292

    LLVM provides complete support for building such a module. All you need to

    293 do is use the LOADABLE_MODULE variable in your Makefile. For example, to
    294 build a loadable module named MyMod that uses the LLVM libraries
    295 LLVMSupport.a and LLVMSystem.a, you would specify:

    296
    
    
                      
                    
    297 LIBRARYNAME := MyMod
    298 LOADABLE_MODULE := 1
    299 USEDLIBS := LLVMSupport.a LLVMSystem.a
    300
    301

    Use of the LOADABLE_MODULE facility implies several things:

    302
    303
  • There will be no "lib" prefix on the module. This differentiates it from
  • 304 a standard shared library of the same name.
    305
  • The SHARED_LIBRARY variable is turned
  • 306 on.
    307
  • The LINK_LIBS_IN_SHARED variable
  • 308 is turned on.
    309
  • The DONT_BUILD_RELINKED variable
  • 310 is turned on.
    311
    312

    A loadable module is loaded by LLVM via the facilities of libtool's libltdl

    313 library which is part of lib/System implementation.

    279314
    280315
    281316
    88
    99 LEVEL = ../../..
    1010 LIBRARYNAME = LLVMHello
    11 SHARED_LIBRARY = 1
    1211 LOADABLE_MODULE = 1
    12 USEDLIBS = LLVMSupport.a LLVMSystem.a
    1313
    1414 include $(LEVEL)/Makefile.common
    1515
    88 # Give the name of a library. This will build a dynamic version.
    99 #
    1010 LIBRARYNAME=sample
    11 SHARED_LIBRARY=1
    12 LOADABLE_MODULE=1
    13 #DONT_BUILD_RELINKED=1
    14 #ARCHIVE_LIBRARY=1
    11 DONT_BUILD_RELINKED=1
    12 BUILD_ARCHIVE=1
    1513
    1614 #
    1715 # Include Makefile.common so we know what to do.
    1313 # List libraries that we'll need
    1414 # We use LIBS because sample is a dynamic library.
    1515 #
    16 USEDLIBS = sample
    16 USEDLIBS = sample.a
    1717
    1818 #
    1919 # Include Makefile.common so we know what to do.