llvm.org GIT mirror llvm / f6afae2
Add a shared library for LLVM, named libLLVM2.7svn.(so|dylib), and add an --enable-shared configure flag to have the tools linked shared. (2.7svn is just $(LLVMVersion) so it'll change to "2.7" in the release.) Always link the example programs shared to test that the shared library keeps working. On my mac laptop, Debug libLLVM2.7svn.dylib is 39MB, and opt (for example) is 16M static vs 440K shared. Two things are less than ideal here: 1) The library doesn't include any version information. Since we expect to break the ABI with every release, this shouldn't be much of a problem. If we do release a compatible 2.7.1, we may be able to hack its library to work with binaries compiled against 2.7.0, or we can just ask them to recompile. I'm hoping to get a real packaging expert to look at this for the 2.8 release. 2) llvm-config doesn't yet have an option to print link options for the shared library. I'll add this as a subsequent patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96559 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 9 years ago
10 changed file(s) with 150 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
2929 DIRS := lib/System lib/Support utils
3030 OPTIONAL_DIRS :=
3131 else
32 DIRS := lib/System lib/Support utils lib/VMCore lib tools/llvm-config \
33 tools runtime docs unittests
32 DIRS := lib/System lib/Support utils lib/VMCore lib tools/llvm-shlib \
33 tools/llvm-config tools runtime docs unittests
3434 OPTIONAL_DIRS := projects bindings
3535 endif
3636
265265 # Do we want to build with position independent code?
266266 ENABLE_PIC := @ENABLE_PIC@
267267
268 # Do we want to link the tools shared?
269 ENABLE_SHARED := @ENABLE_SHARED@
270
268271 # Use -fvisibility-inlines-hidden?
269272 ENABLE_VISIBILITY_INLINES_HIDDEN := @ENABLE_VISIBILITY_INLINES_HIDDEN@
270273
274277
275278 # Enable JIT for this platform
276279 TARGET_HAS_JIT = @TARGET_HAS_JIT@
280
281 # Environment variable to set to change the runtime shared library search path.
282 SHLIBPATH_VAR = @SHLIBPATH_VAR@
277283
278284 # Shared library extension for host platform.
279285 SHLIBEXT = @SHLIBEXT@
612612 ifneq ($(HOST_OS),Darwin)
613613 ifneq ($(DARWIN_MAJVERS),4)
614614 ifdef TOOLNAME
615 ifdef EXAMPLE_TOOL
616 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
617 else
618 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
619 endif
615 LD.Flags += $(RPATH) -Wl,'$$ORIGIN/../lib'
616 ifdef EXAMPLE_TOOL
617 LD.Flags += $(RPATH) -Wl,$(ExmplDir) $(RDYNAMIC)
618 else
619 LD.Flags += $(RPATH) -Wl,$(ToolDir) $(RDYNAMIC)
620 endif
620621 endif
621622 endif
622623 endif
951952
952953 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
953954
955 ifeq ($(ENABLE_SHARED), 1)
956 LLVMLibsOptions += -lLLVM$(LLVMVersion)
957 LLVMLibsPaths += $(LibDir)/libLLVM$(LLVMVersion)$(SHLIBEXT)
958 else
959 ifeq ($(EXAMPLE_TOOL), 1)
960 LLVMLibsOptions += -lLLVM$(LLVMVersion)
961 LLVMLibsPaths += $(LibDir)/libLLVM$(LLVMVersion)$(SHLIBEXT)
962 else
954963 LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS))
955964 LLVMLibsPaths += $(LLVM_CONFIG) \
956965 $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
966 endif
967 endif
957968 endif
958969 endif
959970
11611172 # If neither BUILD_ARCHIVE or LOADABLE_MODULE are specified, default to
11621173 # building an archive.
11631174 #---------------------------------------------------------
1175 ifndef NO_BUILD_ARCHIVE
11641176 ifndef BUILD_ARCHIVE
11651177 ifndef LOADABLE_MODULE
11661178 BUILD_ARCHIVE = 1
1179 endif
11671180 endif
11681181 endif
11691182
469469 AC_DEFINE_UNQUOTED([ENABLE_PIC],$ENABLE_PIC,
470470 [Define if position independent code is enabled])
471471
472 dnl Allow linking tools against the shared library.
473 AC_ARG_ENABLE(shared,
474 AS_HELP_STRING([--enable-shared],
475 [Link LLVM tools shared (default is NO)]),,
476 enableval=default)
477 case "$enableval" in
478 yes) AC_SUBST(ENABLE_SHARED,[1]) ;;
479 no) AC_SUBST(ENABLE_SHARED,[0]) ;;
480 default) AC_SUBST(ENABLE_SHARED,[0]) ;;
481 *) AC_MSG_ERROR([Invalid setting for --enable-shared. Use "yes" or "no"]) ;;
482 esac
483
472484 dnl Allow specific targets to be specified for building (or not)
473485 TARGETS_TO_BUILD=""
474486 AC_ARG_ENABLE([targets],AS_HELP_STRING([--enable-targets],
12641276 dnl the Makefiles so we can use it there too
12651277 AC_SUBST(SHLIBEXT,$libltdl_cv_shlibext)
12661278
1279 dnl Propagate the run-time library path variable that the libltdl
1280 dnl checks found to the Makefiles so we can use it there too
1281 AC_SUBST(SHLIBPATH_VAR,$libltdl_cv_shlibpath_var)
1282
12671283 # Translate the various configuration directories and other basic
12681284 # information into substitutions that will end up in Makefile.config.in
12691285 # that these configured values can be used by the makefiles
688688 ENABLE_DOXYGEN
689689 ENABLE_THREADS
690690 ENABLE_PIC
691 ENABLE_SHARED
691692 TARGETS_TO_BUILD
692693 LLVM_ENUM_TARGETS
693694 LLVM_ENUM_ASM_PRINTERS
768769 LLVMGCC_MAJVERS
769770 LLVMGCC_LANGS
770771 SHLIBEXT
772 SHLIBPATH_VAR
771773 LLVM_PREFIX
772774 LLVM_BINDIR
773775 LLVM_LIBDIR
14001402 --enable-threads Use threads if available (default is YES)
14011403 --enable-pic Build LLVM with Position Independent Code (default
14021404 is YES)
1405 --enable-shared Link LLVM tools shared (default is NO)
14031406 --enable-targets Build specific host targets: all or
14041407 target1,target2,... Valid targets are: host, x86,
14051408 x86_64, sparc, powerpc, alpha, arm, mips, spu,
48564859 _ACEOF
48574860
48584861
4862 # Check whether --enable-shared was given.
4863 if test "${enable_shared+set}" = set; then
4864 enableval=$enable_shared;
4865 else
4866 enableval=default
4867 fi
4868
4869 case "$enableval" in
4870 yes) ENABLE_SHARED=1
4871 ;;
4872 no) ENABLE_SHARED=0
4873 ;;
4874 default) ENABLE_SHARED=0
4875 ;;
4876 *) { { echo "$as_me:$LINENO: error: Invalid setting for --enable-shared. Use \"yes\" or \"no\"" >&5
4877 echo "$as_me: error: Invalid setting for --enable-shared. Use \"yes\" or \"no\"" >&2;}
4878 { (exit 1); exit 1; }; } ;;
4879 esac
4880
48594881 TARGETS_TO_BUILD=""
48604882 # Check whether --enable-targets was given.
48614883 if test "${enable_targets+set}" = set; then
1103411056 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1103511057 lt_status=$lt_dlunknown
1103611058 cat > conftest.$ac_ext <
11037 #line 11038 "configure"
11059 #line 11060 "configure"
1103811060 #include "confdefs.h"
1103911061
1104011062 #if HAVE_DLFCN_H
1959219614 fi
1959319615
1959419616 SHLIBEXT=$libltdl_cv_shlibext
19617
19618
19619 SHLIBPATH_VAR=$libltdl_cv_shlibpath_var
1959519620
1959619621
1959719622 # Translate the various configuration directories and other basic
2065120676 ENABLE_DOXYGEN!$ENABLE_DOXYGEN$ac_delim
2065220677 ENABLE_THREADS!$ENABLE_THREADS$ac_delim
2065320678 ENABLE_PIC!$ENABLE_PIC$ac_delim
20679 ENABLE_SHARED!$ENABLE_SHARED$ac_delim
2065420680 TARGETS_TO_BUILD!$TARGETS_TO_BUILD$ac_delim
2065520681 LLVM_ENUM_TARGETS!$LLVM_ENUM_TARGETS$ac_delim
2065620682 LLVM_ENUM_ASM_PRINTERS!$LLVM_ENUM_ASM_PRINTERS$ac_delim
2066020686 OPTIMIZE_OPTION!$OPTIMIZE_OPTION$ac_delim
2066120687 EXTRA_OPTIONS!$EXTRA_OPTIONS$ac_delim
2066220688 BINUTILS_INCDIR!$BINUTILS_INCDIR$ac_delim
20663 ENABLE_LLVMC_DYNAMIC!$ENABLE_LLVMC_DYNAMIC$ac_delim
2066420689 _ACEOF
2066520690
2066620691 if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
2070220727 ac_delim='%!_!# '
2070320728 for ac_last_try in false false false false false :; do
2070420729 cat >conf$$subs.sed <<_ACEOF
20730 ENABLE_LLVMC_DYNAMIC!$ENABLE_LLVMC_DYNAMIC$ac_delim
2070520731 ENABLE_LLVMC_DYNAMIC_PLUGINS!$ENABLE_LLVMC_DYNAMIC_PLUGINS$ac_delim
2070620732 CXX!$CXX$ac_delim
2070720733 CXXFLAGS!$CXXFLAGS$ac_delim
2077220798 LLVMGCC_MAJVERS!$LLVMGCC_MAJVERS$ac_delim
2077320799 LLVMGCC_LANGS!$LLVMGCC_LANGS$ac_delim
2077420800 SHLIBEXT!$SHLIBEXT$ac_delim
20801 SHLIBPATH_VAR!$SHLIBPATH_VAR$ac_delim
2077520802 LLVM_PREFIX!$LLVM_PREFIX$ac_delim
2077620803 LLVM_BINDIR!$LLVM_BINDIR$ac_delim
2077720804 LLVM_LIBDIR!$LLVM_LIBDIR$ac_delim
2079220819 LTLIBOBJS!$LTLIBOBJS$ac_delim
2079320820 _ACEOF
2079420821
20795 if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 88; then
20822 if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 90; then
2079620823 break
2079720824 elif $ac_last_try; then
2079820825 { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
199199 -e "s#@LLVM_TOOLS_DIR@#$(ToolDir)#g" \
200200 -e "s#@LLVMGCCDIR@#$(LLVMGCCDIR)#g" \
201201 -e "s#@LLVM_BUILD_MODE@#$(BuildMode)#g" \
202 -e "s#@ENABLE_SHARED@#$(ENABLE_SHARED)#g" \
203 -e "s#@SHLIBPATH_VAR@#$(SHLIBPATH_VAR)#g" \
202204 $(PROJ_SRC_DIR)/Unit/lit.site.cfg.in > $@
2222
2323 ###
2424
25 import os
25 # If necessary, point the dynamic loader at libLLVM.so.
26 if config.enable_shared:
27 libdir = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'lib')
28 shlibpath = config.environment.get(config.shlibpath_var,'')
29 if shlibpath:
30 shlibpath = ':' + shlibpath
31 shlibpath = libdir + shlibpath
32 config.environment[config.shlibpath_var] = shlibpath
2633
2734 # Check that the object root is known.
2835 if config.test_exec_root is None:
44 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
55 config.llvmgcc_dir = "@LLVMGCCDIR@"
66 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
7 config.enable_shared = @ENABLE_SHARED@
8 config.shlibpath_var = "@SHLIBPATH_VAR@"
79
810 # Let the main config do the real work.
911 lit.load_config(config, "@LLVM_SOURCE_DIR@/test/Unit/lit.cfg")
0 ##===- tools/shlib/Makefile --------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10 LIBRARYNAME = LLVM$(LLVMVersion)
11
12 NO_BUILD_ARCHIVE = 1
13 LINK_LIBS_IN_SHARED = 1
14 SHARED_LIBRARY = 1
15
16 include $(LEVEL)/Makefile.common
17
18 # Include all archives in libLLVM.(so|dylib) except the ones that have
19 # their own dynamic libraries.
20 Archives := $(wildcard $(LibDir)/libLLVM*.a)
21 SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT))
22 IncludeInLibLlvm := $(filter-out $(basename $(SharedLibraries)).a, $(Archives))
23 LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%)
24 LLVMLibsPaths := $(IncludeInLibLlvm)
25
26 $(LibName.SO): $(LLVMLibsPaths)
27
28 ifeq ($(HOST_OS),Darwin)
29 # set dylib internal version number to llvmCore submission number
30 ifdef LLVM_SUBMIT_VERSION
31 LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \
32 -Wl,$(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION) \
33 -Wl,-compatibility_version -Wl,1
34 endif
35 # Include everything from the .a's into the shared library.
36 LLVMLibsOptions := $(LLVMLibsOptions) \
37 -Wl,-all_load
38 # extra options to override libtool defaults
39 LLVMLibsOptions := $(LLVMLibsOptions) \
40 -avoid-version \
41 -Wl,-dead_strip \
42 -Wl,-seg1addr -Wl,0xE0000000
43
44 # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line
45 DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/')
46 ifneq ($(DARWIN_VERS),8)
47 LLVMLibsOptions := $(LLVMLibsOptions) \
48 -Wl,-install_name \
49 -Wl,"@executable_path/../lib/lib$(LIBRARYNAME)$(SHLIBEXT)"
50 endif
51 endif
52
53 ifeq ($(HOST_OS), Linux)
54 # Include everything from the .a's into the shared library.
55 LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \
56 -Wl,--no-whole-archive
57 # Don't allow unresolved symbols, and warn if we'll need to modify
58 # the text segment when loading libLLVM.so.
59 LLVMLibsOptions += -Wl,--no-undefined,--warn-shared-textrel
60 endif
2727 CPP.Flags += $(NO_VARIADIC_MACROS)
2828 TESTLIBS = -lGoogleTest -lUnitTestMain
2929
30 ifeq ($(ENABLE_SHARED), 1)
31 Run.Shared := $(SHLIBPATH_VAR)="$(LibDir)$${$(SHLIBPATH_VAR):+:}$$$(SHLIBPATH_VAR)"
32 endif
33
3034 $(LLVMUnitTestExe): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
3135 $(Echo) Linking $(BuildMode) unit test $(TESTNAME) $(StripWarnMsg)
3236 $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
3741 all:: $(LLVMUnitTestExe)
3842
3943 unitcheck:: $(LLVMUnitTestExe)
40 $(LLVMUnitTestExe)
44 $(Run.Shared) $(LLVMUnitTestExe)
4145
4246 endif