Add support for building and testing the unwinder.

Note: The unwinder currently only works on Darwin and on ARM Linux.
Non-ARM Linux support is not yet implemented, and will fail to build.

llvm-svn: 212824
This commit is contained in:
Dan Albert 2014-07-11 15:36:02 +00:00
parent 8e9a5b1899
commit 7c06819ecd
6 changed files with 124 additions and 8 deletions

View File

@ -104,6 +104,7 @@ endif()
option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
# Default to building a shared library so that the default options still test
# the libc++abi that is being built. There are two problems with testing a
@ -243,6 +244,10 @@ include_directories(include)
# soname, etc...
add_subdirectory(src)
if (LIBCXXABI_USE_LLVM_UNWINDER)
add_subdirectory(src/Unwind)
endif()
if(NOT LIBCXXABI_ENABLE_SHARED)
# TODO: Fix the libc++ cmake files so that libc++abi can be statically linked.
# As it is now, libc++ will prefer linking against a dynamic libc++abi in the

View File

@ -19,13 +19,7 @@ set(LIBCXXABI_SOURCES
typeinfo.cpp
)
set(LIBCXXABI_HEADERS
../include/cxxabi.h
../include/libunwind.h
../include/unwind.h
)
append_if(LIBCXXABI_HEADERS APPLE ../include/mach-o/compact_unwind_encoding.h)
set(LIBCXXABI_HEADERS ../include/cxxabi.h)
# Add all the headers to the project for IDEs.
if (MSVC_IDE OR XCODE)

View File

@ -0,0 +1,101 @@
# Get sources
set(LIBUNWIND_SOURCES
libunwind.cpp
Unwind-EHABI.cpp
UnwindLevel1.c
UnwindLevel1-gcc-ext.c
Unwind-sjlj.c
)
append_if(LIBUNWIND_SOURCES APPLE Unwind_AppleExtras.cpp)
set(LIBUNWIND_ASM_SOURCES
UnwindRegistersRestore.S
UnwindRegistersSave.S
)
set_source_files_properties(${LIBUNWIND_ASM_SOURCES} PROPERTIES LANGUAGE C)
set(LIBUNWIND_HEADERS
AddressSpace.hpp
assembly.h
CompactUnwinder.hpp
config.h
dwarf2.h
DwarfInstructions.hpp
DwarfParser.hpp
libunwind_ext.h
Registers.hpp
UnwindCursor.hpp
unwind_ext.h
../../include/libunwind.h
../../include/unwind.h
)
append_if(LIBCXXABI_HEADERS APPLE ../../include/mach-o/compact_unwind_encoding.h)
if (MSVC_IDE)
# Force them all into the headers dir on MSVC, otherwise they end up at
# project scope because they don't have extensions.
source_group("Header Files" FILES ${LIBUNWIND_HEADERS})
endif()
if (LIBUNWIND_ENABLE_SHARED)
add_library(unwind SHARED
${LIBUNWIND_SOURCES}
${LIBUNWIND_ASM_SOURCES}
${LIBUNWIND_HEADERS}
)
else()
add_library(unwind STATIC
${LIBUNWIND_SOURCES}
${LIBUNWIND_ASM_SOURCES}
${LIBUNWIND_HEADERS}
)
endif()
include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
# Generate library list.
set(libraries ${LIBCXXABI_CXX_ABI_LIBRARIES})
append_if(libraries LIBCXXABI_HAS_C_LIB c)
target_link_libraries(unwind ${libraries})
# Setup flags.
append_if(compile_flags LIBCXXABI_HAS_FPIC_FLAG -fPIC)
append_if(link_flags LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
set(LIBCXXABI_UNWINDER_NAME "unwind")
if ( APPLE )
if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
list(APPEND compile_flags "-U__STRICT_ANSI__")
list(APPEND link_flags
"-compatibility_version 1"
"-current_version ${LIBCXXABI_VERSION}"
"-install_name /usr/lib/lib${LIBCXXABI_UNWINDER_NAME}.1.dylib"
"/usr/lib/libSystem.B.dylib")
else()
list(APPEND link_flags
"-compatibility_version 1"
"-install_name /usr/lib/lib${LIBCXXABI_UNWINDER_NAME}.1.dylib")
endif()
endif()
string(REPLACE ";" " " compile_flags "${compile_flags}")
string(REPLACE ";" " " link_flags "${link_flags}")
set_target_properties(unwind
PROPERTIES
COMPILE_FLAGS "${compile_flags}"
LINK_FLAGS "${link_flags}"
OUTPUT_NAME "${LIBCXXABI_UNWINDER_NAME}"
VERSION "1.0"
SOVERSION "1"
)
install(TARGETS unwind
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

View File

@ -10,6 +10,7 @@ set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPILER})
set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(LIBCXXABI_BINARY_DIR ${CMAKE_BINARY_DIR})
pythonize_bool(LIBCXXABI_ENABLE_SHARED)
pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not edit!")
configure_file(
@ -22,6 +23,10 @@ if (NOT LIBCXXABI_BUILT_STANDALONE)
list(APPEND LIBCXXABI_TEST_DEPS cxx)
endif()
if (LIBCXXABI_USE_LLVM_UNWINDER)
list(APPEND LIBCXXABI_TEST_DEPS unwind)
endif()
add_lit_testsuite(check-libcxxabi "Running libcxxabi tests"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${LIBCXXABI_TEST_DEPS}

View File

@ -188,6 +188,10 @@ if enable_shared is None:
if enable_shared is None:
lit_config.fatal("enable_shared must be defined")
llvm_unwinder = getattr(config, 'llvm_unwinder', None)
if llvm_unwinder is None:
lit_config.fatal("llvm_unwinder must be defined")
link_flags = []
link_flags_str = lit_config.params.get('link_flags', None)
if link_flags_str is None:
@ -198,7 +202,13 @@ if link_flags_str is None:
if sys.platform == 'darwin':
link_flags += ['-lSystem']
elif sys.platform == 'linux2':
link_flags += ['-lgcc_eh', '-lc', '-lm', '-lpthread', '-lgcc_s']
if not llvm_unwinder:
link_flags += ['-lgcc_eh']
link_flags += ['-lc', '-lm', '-lpthread']
if llvm_unwinder:
link_flags += ['-lunwind', '-ldl']
else:
link_flags += ['-lgcc_s']
else:
lit_config.fatal("unrecognized system")

View File

@ -5,6 +5,7 @@ config.libcxxabi_obj_root = "@LIBCXXABI_BINARY_DIR@"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.enable_shared = @LIBCXXABI_ENABLE_SHARED@
config.libcxx_includes = "@LIBCXXABI_LIBCXX_INCLUDES@"
config.llvm_unwinder = @LIBCXXABI_USE_LLVM_UNWINDER@
# Let the main config do the real work.
lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg")