2014-10-23 17:22:14 +00:00
# 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.
set ( SOURCES
l i b l l v m . c p p
)
2015-04-13 21:29:46 +00:00
llvm_map_components_to_libnames ( LIB_NAMES ${ LLVM_DYLIB_COMPONENTS } )
2016-11-01 20:19:33 +00:00
if ( LLVM_LINK_LLVM_DYLIB AND 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." )
Enable linking tools, shared libraries against libLLVM
Summary:
Three closely related changes, to have a mode in which we link all
executables and shared libraries against libLLVM.
1. Add a new LLVM_LINK_LLVM_DYLIB cmake option, which, when ON, will link
executables and shared libraries against libLLVM. For this to work, it
is necessary to also set LLVM_BUILD_LLVM_DYLIB and LLVM_DYLIB_EXPORT_ALL.
It is not strictly necessary to set LLVM_DISABLE_LLVM_DYLIB_ATEXIT, but
we also default to OFF in this mode, or tools tend to misbehave (e.g.
stdout may not flush on exit when output is buffered.)
llvm-config and Tablegen do not use libLLVM, as they are dependencies of
libLLVM.
2. Modify llvm-go to take a new flag, "linkmode=component-libs|dylib".
Depending on which one is passed (default is component-libs), we link
with the individual libraries or libLLVM respectively. We pass in dylib
when LLVM_LINK_LLVM_DYLIB is ON.
3. Fix LLVM_DYLIB_EXPORT_ALL on Linux, and expand the symbols exported to
actually export all. Don't strip leading underscore from symbols on Linux,
and make sure we get all exported symbols and weak-with-default symbols
("W" in nm output). Without these changes, passes won't load because
the "Annotate..." symbols defined in lib/Support/Valigrind.cpp are not
found.
Testing:
- Ran default build ("ninja") with LLVM, clang, compiler-rt, llgo, lldb.
- Ran "check", "check-clang", "check-tsan", "check-libgo" targets. I've
never had much success with LLDB tests, and llgoi is currently broken
so check-llgo fails for an unrelated reason.
- Ran "lldb" to ensure it loads.
Reviewers: chandlerc, beanz, pcc, rnk
Subscribers: rnk, chapuni, sylvestre.ledru, llvm-commits
Differential Revision: http://reviews.llvm.org/D12488
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246527 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-01 03:14:31 +00:00
endif ( )
2016-11-01 20:19:33 +00:00
# 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 } )
2015-10-27 16:02:04 +00:00
if ( LLVM_DYLIB_EXPORTED_SYMBOL_FILE )
2015-04-13 21:29:46 +00:00
set ( LLVM_EXPORTED_SYMBOL_FILE ${ LLVM_DYLIB_EXPORTED_SYMBOL_FILE } )
add_custom_target ( libLLVMExports DEPENDS ${ LLVM_EXPORTED_SYMBOL_FILE } )
2014-10-23 17:22:14 +00:00
endif ( )
2015-11-04 23:11:12 +00:00
add_llvm_library ( LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${ SOURCES } )
2014-10-23 17:22:14 +00:00
2015-04-16 16:56:22 +00:00
list ( REMOVE_DUPLICATES LIB_NAMES )
2017-03-26 05:58:48 +00:00
if ( ( "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" ) OR ( MINGW ) OR ( "${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD" ) OR ( "${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly" ) ) # FIXME: It should be "GNU ld for elf"
2017-04-17 20:51:50 +00:00
configure_file (
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s i m p l e _ v e r s i o n _ s c r i p t . m a p . i n
$ { L L V M _ L I B R A R Y _ D I R } / t o o l s / l l v m - s h l i b / s i m p l e _ v e r s i o n _ s c r i p t . m a p )
2014-11-10 15:04:02 +00:00
# GNU ld doesn't resolve symbols in the version script.
2017-04-17 20:51:50 +00:00
set ( LIB_NAMES -Wl,--version-script, ${ LLVM_LIBRARY_DIR } /tools/llvm-shlib/simple_version_script.map -Wl,--whole-archive ${ LIB_NAMES } -Wl,--no-whole-archive )
2015-04-16 16:56:22 +00:00
elseif ( "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" )
set ( LIB_NAMES -Wl,-all_load ${ LIB_NAMES } )
2014-11-10 15:04:02 +00:00
endif ( )
2015-03-23 20:03:57 +00:00
target_link_libraries ( LLVM PRIVATE ${ LIB_NAMES } )
2014-11-10 15:04:02 +00:00
2015-10-27 16:02:04 +00:00
if ( APPLE )
set_property ( TARGET LLVM APPEND_STRING PROPERTY
L I N K _ F L A G S
" - c o m p a t i b i l i t y _ v e r s i o n 1 - c u r r e n t _ v e r s i o n $ { L L V M _ V E R S I O N _ M A J O R } . $ { L L V M _ V E R S I O N _ M I N O R } . $ { L L V M _ V E R S I O N _ P A T C H } " )
endif ( )
2015-10-09 17:55:21 +00:00
if ( TARGET libLLVMExports )
add_dependencies ( LLVM libLLVMExports )
endif ( )
2014-10-23 17:22:14 +00:00
2015-10-27 16:02:04 +00:00
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 }
C O M M A N D n m $ { L I B _ P A T H } | a w k " / T _ L L V M / | | / T L L V M / { p r i n t $ 3 } " | s o r t - u | s e d - e " s / ^ _ / / g " > $ { L L V M _ E X P O R T E D _ S Y M B O L _ F I L E }
W O R K I N G _ D I R E C T O R Y $ { L I B _ D I R }
D E P E N D S L L V M
C O M M E N T " G e n e r a t i n g E x p o r t l i s t f o r L L V M . . . "
V E R B A T I M )
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
2014-10-23 17:22:14 +00:00
L I N K _ F L A G S
2015-10-27 16:02:04 +00:00
" - c o m p a t i b i l i t y _ v e r s i o n 1 - c u r r e n t _ v e r s i o n $ { L L V M _ V E R S I O N _ M A J O R } . $ { L L V M _ V E R S I O N _ M I N O R } . $ { L L V M _ V E R S I O N _ P A T C H } - W l , - r e e x p o r t _ l i b r a r y $ { L I B _ P A T H } " )
2014-10-23 17:22:14 +00:00
endif ( )