diff options
Diffstat (limited to 'gnu/llvm/tools/llvm-shlib')
| -rw-r--r-- | gnu/llvm/tools/llvm-shlib/CMakeLists.txt | 97 | ||||
| -rw-r--r-- | gnu/llvm/tools/llvm-shlib/Makefile | 116 | ||||
| -rw-r--r-- | gnu/llvm/tools/llvm-shlib/libllvm.cpp | 20 |
3 files changed, 233 insertions, 0 deletions
diff --git a/gnu/llvm/tools/llvm-shlib/CMakeLists.txt b/gnu/llvm/tools/llvm-shlib/CMakeLists.txt new file mode 100644 index 00000000000..2356103a9cd --- /dev/null +++ b/gnu/llvm/tools/llvm-shlib/CMakeLists.txt @@ -0,0 +1,97 @@ +# This tool creates a shared library from the LLVM libraries. Generating this +# library is enabled by setting LLVM_BUILD_LLVM_DYLIB=yes on the CMake +# commandline. By default the shared library only exports the LLVM C API. + +add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" ) + +set(SOURCES + libllvm.cpp + ) + +llvm_map_components_to_libnames(LIB_NAMES ${LLVM_DYLIB_COMPONENTS}) + +if(LLVM_LINK_LLVM_DYLIB) + if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE) + message(WARNING "Using LLVM_LINK_LLVM_DYLIB with LLVM_DYLIB_EXPORTED_SYMBOL_FILE may not work. Use at your own risk.") + endif() + + # libLLVM.so should not have any dependencies on any other LLVM + # shared libraries. When using the "all" pseudo-component, + # LLVM_AVAILABLE_LIBS is added to the dependencies, which may + # contain shared libraries (e.g. libLTO). + # + # Also exclude libLLVMTableGen for the following reasons: + # - it is only used by internal *-tblgen utilities; + # - it pollutes the global options space. + foreach(lib ${LIB_NAMES}) + get_target_property(t ${lib} TYPE) + if("${lib}" STREQUAL "LLVMTableGen") + elseif("x${t}" STREQUAL "xSTATIC_LIBRARY") + list(APPEND FILTERED_LIB_NAMES ${lib}) + endif() + endforeach() + set(LIB_NAMES ${FILTERED_LIB_NAMES}) +endif() + +if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE) + set(LLVM_EXPORTED_SYMBOL_FILE ${LLVM_DYLIB_EXPORTED_SYMBOL_FILE}) + add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE}) +endif() + +add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES}) + +list(REMOVE_DUPLICATES LIB_NAMES) +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf" + # GNU ld doesn't resolve symbols in the version script. + set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + set(LIB_NAMES -Wl,-all_load ${LIB_NAMES}) +endif() + +target_link_libraries(LLVM PRIVATE ${LIB_NAMES}) + +if (APPLE) + set_property(TARGET LLVM APPEND_STRING PROPERTY + LINK_FLAGS + " -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") +endif() + +if(TARGET libLLVMExports) + add_dependencies(LLVM libLLVMExports) +endif() + +if(LLVM_BUILD_LLVM_C_DYLIB) + # To get the export list for a single llvm library: + # nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports + + if(NOT APPLE) + message(FATAL_ERROR "Generating libLLVM-c is only supported on Darwin") + endif() + + set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm-c.exports) + + set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) + set(LIB_NAME ${LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}LLVM) + set(LIB_PATH ${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(LIB_EXPORTS_PATH ${LIB_NAME}.exports) + list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH}) + + add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE} + COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LLVM_EXPORTED_SYMBOL_FILE} + WORKING_DIRECTORY ${LIB_DIR} + DEPENDS LLVM + COMMENT "Generating Export list for LLVM..." + VERBATIM ) + + add_custom_target(libLLVMCExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE}) + + add_llvm_library(LLVM-C SHARED ${SOURCES}) + + target_link_libraries(LLVM-C PUBLIC LLVM) + add_dependencies(LLVM-C libLLVMCExports) + + set_property(TARGET LLVM-C APPEND_STRING PROPERTY + LINK_FLAGS + " -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH} -Wl,-reexport_library ${LIB_PATH}") +endif() + diff --git a/gnu/llvm/tools/llvm-shlib/Makefile b/gnu/llvm/tools/llvm-shlib/Makefile new file mode 100644 index 00000000000..19077a3858a --- /dev/null +++ b/gnu/llvm/tools/llvm-shlib/Makefile @@ -0,0 +1,116 @@ +##===- tools/shlib/Makefile --------------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL := ../.. + +LIBRARYNAME = LLVM-$(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR)$(LLVM_VERSION_SUFFIX) +LIBRARYALIASNAME = LLVM-$(LLVMVersion) + +NO_BUILD_ARCHIVE := 1 +LINK_LIBS_IN_SHARED := 1 +SHARED_LIBRARY := 1 +SHARED_ALIAS := 1 + +include $(LEVEL)/Makefile.config + +ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) + EXPORTED_SYMBOL_FILE = $(ObjDir)/$(LIBRARYNAME).exports + + ifeq (1,$(ENABLE_EMBED_STDCXX)) + # It is needed to force static-stdc++.a linked. + SHLIB_FRAG_NAMES += stdc++.a.o + endif + +endif + +include $(LEVEL)/Makefile.common + +# Include all archives in libLLVM.(so|dylib) except the ones that have +# their own dynamic libraries and TableGen. +Archives := $(wildcard $(LibDir)/libLLVM*.a) +SharedLibraries := $(wildcard $(LibDir)/libLLVM*$(SHLIBEXT)) +ExcludeFromLibLlvm := $(basename $(SharedLibraries)).a %/libLLVMTableGen.a +IncludeInLibLlvm := $(filter-out $(ExcludeFromLibLlvm), $(Archives)) +LLVMLibsOptions := $(IncludeInLibLlvm:$(LibDir)/lib%.a=-l%) +LLVMLibsPaths := $(IncludeInLibLlvm) + +$(LibName.SO): $(LLVMLibsPaths) + +ifeq ($(HOST_OS),Darwin) + # set dylib internal version number to llvmCore submission number + ifdef LLVM_SUBMIT_VERSION + LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \ + -Wl,$(LLVM_SUBMIT_VERSION).$(LLVM_SUBMIT_SUBVERSION) \ + -Wl,-compatibility_version -Wl,1 + endif + # Include everything from the .a's into the shared library. + LLVMLibsOptions := $(LLVMLibsOptions) -all_load +endif + +ifeq ($(HOST_OS), $(filter $(HOST_OS), DragonFly Linux FreeBSD GNU/kFreeBSD OpenBSD GNU Bitrig)) + # Include everything from the .a's into the shared library. + LLVMLibsOptions := -Wl,--whole-archive $(LLVMLibsOptions) \ + -Wl,--no-whole-archive +endif + +ifeq ($(HOST_OS), $(filter $(HOST_OS), DragonFly Linux FreeBSD GNU/kFreeBSD GNU)) + # Add soname to the library. + LLVMLibsOptions += -Wl,--soname,lib$(LIBRARYNAME)$(SHLIBEXT) +endif + +ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux GNU GNU/kFreeBSD)) + # Don't allow unresolved symbols. + LLVMLibsOptions += -Wl,--no-undefined +endif + +ifeq ($(HOST_OS),SunOS) + # add -z allextract ahead of other libraries on Solaris + LLVMLibsOptions := -Wl,-z -Wl,allextract $(LLVMLibsOptions) +endif + +ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) + +SHLIB_STUBS := $(addprefix $(ObjDir)/, $(SHLIB_FRAG_NAMES)) +SHLIB_FRAGS := $(patsubst %.a.o, $(ObjDir)/%.syms.txt, $(LIBRARYNAME).a.o $(SHLIB_FRAG_NAMES)) +LLVMLibsOptions := $(SHLIB_STUBS) $(LLVMLibsOptions) + +$(LibName.SO): $(SHLIB_STUBS) + +%.syms.txt: %.a.o + $(Echo) Collecting global symbols of $(notdir $*) + $(Verb) $(NM_PATH) -g $< > $@ + +$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir + $(Echo) Generating exports for $(LIBRARYNAME) + $(Verb) ($(SED) -n \ + -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \ + -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \ + $(SHLIB_FRAGS) \ + | sort -u) > $@ + +$(ObjDir)/$(LIBRARYNAME).a.o: $(LLVMLibsPaths) $(ObjDir)/.dir + $(Echo) Linking all LLVMLibs together for $(LIBRARYNAME) + $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \ + -Wl,--whole-archive $(LLVMLibsPaths) \ + -Wl,--no-whole-archive + +$(ObjDir)/stdc++.a.o: $(ObjDir)/.dir + $(Echo) Linking all libs together for static libstdc++.a + $(Verb) $(Link) -nostartfiles -Wl,-r -nodefaultlibs -o $@ \ + -Wl,--whole-archive -lstdc++ \ + -Wl,--no-whole-archive +# FIXME: workaround to invalidate -lstdc++ + $(Echo) Making dummy -lstdc++ to lib + $(Verb) $(AR) rc $(ToolDir)/libstdc++.dll.a +# FIXME: Is install-local needed? + +clean-local:: + $(Verb) $(RM) -f $(ToolDir)/libstdc++.dll.a + +endif diff --git a/gnu/llvm/tools/llvm-shlib/libllvm.cpp b/gnu/llvm/tools/llvm-shlib/libllvm.cpp new file mode 100644 index 00000000000..8424d660c9d --- /dev/null +++ b/gnu/llvm/tools/llvm-shlib/libllvm.cpp @@ -0,0 +1,20 @@ +//===-libllvm.cpp - LLVM Shared Library -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is empty and serves only the purpose of making CMake happy because +// you can't define a target with no sources. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Config/config.h" + +#if defined(DISABLE_LLVM_DYLIB_ATEXIT) +extern "C" int __cxa_atexit(); +extern "C" int __cxa_atexit() { return 0; } +#endif |
