mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00
Fix linker script generation for in-tree builds
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@283700 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -270,13 +270,13 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
|
|||||||
# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
|
# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
|
||||||
# LIBCXX_COMPILE_FLAGS: Compile only flags.
|
# LIBCXX_COMPILE_FLAGS: Compile only flags.
|
||||||
# LIBCXX_LINK_FLAGS: Linker only flags.
|
# LIBCXX_LINK_FLAGS: Linker only flags.
|
||||||
# LIBCXX_LIBRARIES: Private libraries libc++ is linked to.
|
# LIBCXX_LIBRARIES: libraries libc++ is linked to.
|
||||||
# LIBCXX_LIBRARIES_PUBLIC: Public libraries libc++ is linked to,
|
# LIBCXX_INTERFACE_LIBRARIES: Libraries that must be linked when using libc++
|
||||||
# also exposed in the linker script.
|
# There libraries are exposed in the linker script.
|
||||||
set(LIBCXX_COMPILE_FLAGS "")
|
set(LIBCXX_COMPILE_FLAGS "")
|
||||||
set(LIBCXX_LINK_FLAGS "")
|
set(LIBCXX_LINK_FLAGS "")
|
||||||
set(LIBCXX_LIBRARIES "")
|
set(LIBCXX_LIBRARIES "")
|
||||||
set(LIBCXX_LIBRARIES_PUBLIC "")
|
set(LIBCXX_INTERFACE_LIBRARIES "")
|
||||||
|
|
||||||
# Include macros for adding and removing libc++ flags.
|
# Include macros for adding and removing libc++ flags.
|
||||||
include(HandleLibcxxFlags)
|
include(HandleLibcxxFlags)
|
||||||
|
@@ -188,6 +188,14 @@ macro(add_library_flags_if condition)
|
|||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
# Add a list of libraries or link flags to 'LIBCXX_LIBRARIES'.
|
||||||
|
macro(add_interface_library)
|
||||||
|
foreach(lib ${ARGN})
|
||||||
|
list(APPEND LIBCXX_LIBRARIES ${lib})
|
||||||
|
list(APPEND LIBCXX_INTERFACE_LIBRARIES ${lib})
|
||||||
|
endforeach()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
# Turn a comma separated CMake list into a space separated string.
|
# Turn a comma separated CMake list into a space separated string.
|
||||||
macro(split_list listname)
|
macro(split_list listname)
|
||||||
string(REPLACE ";" " " ${listname} "${${listname}}")
|
string(REPLACE ";" " " ${listname} "${${listname}}")
|
||||||
|
@@ -33,16 +33,19 @@ add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}"
|
|||||||
|
|
||||||
add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}")
|
add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}")
|
||||||
|
|
||||||
|
if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR
|
||||||
|
LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"))
|
||||||
|
set(LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
|
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
|
||||||
add_library_flags("-Wl,--whole-archive" "-Wl,-Bstatic")
|
add_library_flags("-Wl,--whole-archive" "-Wl,-Bstatic")
|
||||||
add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}")
|
add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}")
|
||||||
add_library_flags("-Wl,-Bdynamic" "-Wl,--no-whole-archive")
|
add_library_flags("-Wl,-Bdynamic" "-Wl,--no-whole-archive")
|
||||||
elseif (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR
|
elseif (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY)
|
||||||
LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"))
|
|
||||||
# Apple re-exports libc++abi in libc++, so don't make it public
|
|
||||||
add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}")
|
add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}")
|
||||||
else ()
|
else ()
|
||||||
list(APPEND LIBCXX_LIBRARIES_PUBLIC "${LIBCXX_CXX_ABI_LIBRARY}")
|
add_interface_library("${LIBCXX_CXX_ABI_LIBRARY}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (APPLE AND LLVM_USE_SANITIZER)
|
if (APPLE AND LLVM_USE_SANITIZER)
|
||||||
@@ -85,7 +88,13 @@ add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic)
|
|||||||
|
|
||||||
# Add the unwinder library.
|
# Add the unwinder library.
|
||||||
if (LIBCXXABI_USE_LLVM_UNWINDER)
|
if (LIBCXXABI_USE_LLVM_UNWINDER)
|
||||||
list(APPEND LIBCXX_LIBRARIES_PUBLIC unwind)
|
if (TARGET unwind_shared)
|
||||||
|
add_interface_library(unwind_shared)
|
||||||
|
elseif (TARGET unwind_static)
|
||||||
|
add_interface_library(unwind_static)
|
||||||
|
else()
|
||||||
|
add_interface_library(unwind)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Setup flags.
|
# Setup flags.
|
||||||
@@ -94,8 +103,7 @@ if (NOT WIN32)
|
|||||||
endif()
|
endif()
|
||||||
add_link_flags_if_supported(-nodefaultlibs)
|
add_link_flags_if_supported(-nodefaultlibs)
|
||||||
|
|
||||||
if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR
|
if (LIBCXX_OSX_REEXPORT_SYSTEM_ABI_LIBRARY)
|
||||||
LIBCXX_CXX_ABI_LIBNAME STREQUAL "none"))
|
|
||||||
if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION)
|
if (NOT DEFINED LIBCXX_LIBCPPABI_VERSION)
|
||||||
set(LIBCXX_LIBCPPABI_VERSION "2") # Default value
|
set(LIBCXX_LIBCPPABI_VERSION "2") # Default value
|
||||||
execute_process(
|
execute_process(
|
||||||
@@ -164,9 +172,7 @@ set(LIBCXX_TARGETS)
|
|||||||
# Build the shared library.
|
# Build the shared library.
|
||||||
if (LIBCXX_ENABLE_SHARED)
|
if (LIBCXX_ENABLE_SHARED)
|
||||||
add_library(cxx_shared SHARED $<TARGET_OBJECTS:cxx_objects>)
|
add_library(cxx_shared SHARED $<TARGET_OBJECTS:cxx_objects>)
|
||||||
target_link_libraries(cxx_shared
|
target_link_libraries(cxx_shared ${LIBCXX_LIBRARIES})
|
||||||
PRIVATE ${LIBCXX_LIBRARIES}
|
|
||||||
PUBLIC ${LIBCXX_LIBRARIES_PUBLIC})
|
|
||||||
set_target_properties(cxx_shared
|
set_target_properties(cxx_shared
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
||||||
@@ -180,9 +186,7 @@ endif()
|
|||||||
# Build the static library.
|
# Build the static library.
|
||||||
if (LIBCXX_ENABLE_STATIC)
|
if (LIBCXX_ENABLE_STATIC)
|
||||||
add_library(cxx_static STATIC $<TARGET_OBJECTS:cxx_objects>)
|
add_library(cxx_static STATIC $<TARGET_OBJECTS:cxx_objects>)
|
||||||
target_link_libraries(cxx_static
|
target_link_libraries(cxx_static ${LIBCXX_LIBRARIES})
|
||||||
PRIVATE ${LIBCXX_LIBRARIES}
|
|
||||||
PUBLIC ${LIBCXX_LIBRARIES_PUBLIC})
|
|
||||||
set_target_properties(cxx_static
|
set_target_properties(cxx_static
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
|
||||||
@@ -244,15 +248,16 @@ endif()
|
|||||||
if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
||||||
# Get the name of the ABI library and handle the case where CXXABI_LIBNAME
|
# Get the name of the ABI library and handle the case where CXXABI_LIBNAME
|
||||||
# is a target name and not a library. Ex cxxabi_shared.
|
# is a target name and not a library. Ex cxxabi_shared.
|
||||||
set(LIBCXX_LIBRARIES_PUBLIC_NAMES)
|
set(LIBCXX_INTERFACE_LIBRARY_NAMES)
|
||||||
foreach(lib ${LIBCXX_LIBRARIES_PUBLIC})
|
foreach(lib ${LIBCXX_INTERFACE_LIBRARIES})
|
||||||
if (lib STREQUAL "cxxabi_shared")
|
# FIXME: Handle cxxabi_static and unwind_static.
|
||||||
list(APPEND LIBCXX_LIBRARIES_PUBLIC_NAMES "c++abi")
|
if (TARGET ${lib})
|
||||||
|
list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "$<TARGET_PROPERTY:${lib},OUTPUT_NAME>")
|
||||||
else()
|
else()
|
||||||
list(APPEND LIBCXX_LIBRARIES_PUBLIC_NAMES "${lib}")
|
list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "${lib}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
#split_list(LIBCXX_INTERFACE_LIBRARY_NAMES)
|
||||||
# Generate a linker script inplace of a libc++.so symlink. Rerun this command
|
# Generate a linker script inplace of a libc++.so symlink. Rerun this command
|
||||||
# after cxx builds.
|
# after cxx builds.
|
||||||
add_custom_command(TARGET cxx_shared POST_BUILD
|
add_custom_command(TARGET cxx_shared POST_BUILD
|
||||||
@@ -260,7 +265,7 @@ if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
|||||||
${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script/gen_link_script.py
|
${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script/gen_link_script.py
|
||||||
ARGS
|
ARGS
|
||||||
"$<TARGET_LINKER_FILE:cxx_shared>"
|
"$<TARGET_LINKER_FILE:cxx_shared>"
|
||||||
"\"${LIBCXX_LIBRARIES_PUBLIC_NAMES}\""
|
${LIBCXX_INTERFACE_LIBRARY_NAMES}
|
||||||
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
|
WORKING_DIRECTORY ${LIBCXX_BUILD_DIR}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
@@ -11,6 +11,18 @@ endmacro()
|
|||||||
set(LIBCXX_LIT_VARIANT "libcxx" CACHE STRING
|
set(LIBCXX_LIT_VARIANT "libcxx" CACHE STRING
|
||||||
"Configuration variant to use for LIT.")
|
"Configuration variant to use for LIT.")
|
||||||
|
|
||||||
|
# The tests shouldn't link to any ABI library when it has been linked into
|
||||||
|
# libc++ statically or via a linker script.
|
||||||
|
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY OR LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
||||||
|
set(LIBCXX_CXX_ABI_LIBNAME "none")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# The tests shouldn't link to libunwind if we have a linker script which
|
||||||
|
# already does so.
|
||||||
|
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
||||||
|
set(LIBCXXABI_USE_LLVM_UNWINDER OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
pythonize_bool(LIBCXX_ENABLE_EXCEPTIONS)
|
pythonize_bool(LIBCXX_ENABLE_EXCEPTIONS)
|
||||||
pythonize_bool(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
|
pythonize_bool(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
|
||||||
pythonize_bool(LIBCXX_ENABLE_FILESYSTEM)
|
pythonize_bool(LIBCXX_ENABLE_FILESYSTEM)
|
||||||
@@ -24,12 +36,6 @@ pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
|
|||||||
pythonize_bool(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
|
pythonize_bool(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
|
||||||
pythonize_bool(LIBCXX_HAS_EXTERNAL_THREAD_API)
|
pythonize_bool(LIBCXX_HAS_EXTERNAL_THREAD_API)
|
||||||
|
|
||||||
# The tests shouldn't link to any ABI library when it has been linked into
|
|
||||||
# libc++ statically or via a linker script.
|
|
||||||
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY OR LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
|
|
||||||
set(LIBCXX_CXX_ABI_LIBNAME "none")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# By default, for non-standalone builds, libcxx and libcxxabi share a library
|
# By default, for non-standalone builds, libcxx and libcxxabi share a library
|
||||||
# directory.
|
# directory.
|
||||||
if (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)
|
if (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)
|
||||||
|
@@ -16,13 +16,13 @@ def print_and_exit(msg):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def usage_and_exit():
|
def usage_and_exit():
|
||||||
print_and_exit("Usage: ./gen_link_script.py [--help] [--dryrun] <path/to/libcxx.so> <abi_libname>")
|
print_and_exit("Usage: ./gen_link_script.py [--help] [--dryrun] <path/to/libcxx.so> <public_libs>...")
|
||||||
|
|
||||||
def help_and_exit():
|
def help_and_exit():
|
||||||
help_msg = \
|
help_msg = \
|
||||||
"""Usage
|
"""Usage
|
||||||
|
|
||||||
gen_link_script.py [--help] [--dryrun] <path/to/libcxx.so> <public_libs>
|
gen_link_script.py [--help] [--dryrun] <path/to/libcxx.so> <public_libs>...
|
||||||
|
|
||||||
Generate a linker script that links libc++ to the proper ABI library.
|
Generate a linker script that links libc++ to the proper ABI library.
|
||||||
The script replaces the specified libc++ symlink.
|
The script replaces the specified libc++ symlink.
|
||||||
@@ -49,10 +49,12 @@ def parse_args():
|
|||||||
dryrun = '--dryrun' == args[0]
|
dryrun = '--dryrun' == args[0]
|
||||||
if dryrun:
|
if dryrun:
|
||||||
del args[0]
|
del args[0]
|
||||||
if len(args) != 2:
|
if len(args) < 2:
|
||||||
usage_and_exit()
|
usage_and_exit()
|
||||||
symlink_file = args[0]
|
symlink_file = args[0]
|
||||||
public_libs = args[1].split(';')
|
del args[0]
|
||||||
|
public_libs = list(args)
|
||||||
|
print('%r' % public_libs)
|
||||||
return dryrun, symlink_file, public_libs
|
return dryrun, symlink_file, public_libs
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Reference in New Issue
Block a user