diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index 058e4e20adde42..00c78b006c415a 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -152,9 +152,6 @@ else() include_directories($ENV{EMSCRIPTEN/system/lib/libcxxabi/include}) endif() - # Disable building _Unwind_XXX style APIs of libunwind, since we don't use them. - add_definitions(-D_LIBUNWIND_DISABLE_ZERO_COST_APIS=1) - # Compile unwinding only for the current compilation target architecture add_definitions(-D_LIBUNWIND_IS_NATIVE_ONLY) diff --git a/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp b/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp index 266b56bd1f6e4e..982c541c7014f6 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp @@ -56,7 +56,7 @@ UnixNativeCodeManager::UnixNativeCodeManager(TADDR moduleBase, m_pClasslibFunctions(pClasslibFunctions), m_nClasslibFunctions(nClasslibFunctions) { // Cache the location of unwind sections - libunwind::LocalAddressSpace::sThisAddressSpace.findUnwindSections( + UnwindHelpers::FindUnwindSections( (uintptr_t)pvManagedCodeStartRange, m_UnwindInfoSections); } diff --git a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp index b1e51f8cad6782..ecbe08f2978abf 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp @@ -62,6 +62,49 @@ using libunwind::UnwindInfoSections; LocalAddressSpace _addressSpace; +// Debug logging hooks referenced by libunwind's config.h when NDEBUG is not +// defined. These were previously in libunwind.cpp which is no longer compiled. +#ifndef NDEBUG +#include + +extern "C" { + +_LIBUNWIND_HIDDEN +bool logAPIs() { + static bool checked = false; + static bool log = false; + if (!checked) { + log = (getenv("LIBUNWIND_PRINT_APIS") != NULL); + checked = true; + } + return log; +} + +_LIBUNWIND_HIDDEN +bool logUnwinding() { + static bool checked = false; + static bool log = false; + if (!checked) { + log = (getenv("LIBUNWIND_PRINT_UNWINDING") != NULL); + checked = true; + } + return log; +} + +_LIBUNWIND_HIDDEN +bool logDWARF() { + static bool checked = false; + static bool log = false; + if (!checked) { + log = (getenv("LIBUNWIND_PRINT_DWARF") != NULL); + checked = true; + } + return log; +} + +} // extern "C" +#endif // NDEBUG + #ifdef TARGET_AMD64 // Shim that implements methods required by libunwind over REGDISPLAY @@ -1396,6 +1439,11 @@ bool UnwindHelpers::GetUnwindProcInfo(PCODE pc, UnwindInfoSections &uwInfoSectio return true; } +bool UnwindHelpers::FindUnwindSections(uintptr_t pc, UnwindInfoSections §ions) +{ + return _addressSpace.findUnwindSections(pc, sections); +} + #if defined(TARGET_APPLE) // Apple considers _dyld_find_unwind_sections to be private API that cannot be used // by apps submitted to App Store and TestFlight, both for iOS-like and macOS platforms. diff --git a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.h b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.h index 2e9d7a299e0e01..a185c990648b62 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.h +++ b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.h @@ -15,4 +15,5 @@ class UnwindHelpers public: static bool StepFrame(REGDISPLAY *regs, unw_word_t start_ip, uint32_t format, unw_word_t unwind_info); static bool GetUnwindProcInfo(PCODE ip, libunwind::UnwindInfoSections &uwInfoSections, unw_proc_info_t *procInfo); + static bool FindUnwindSections(uintptr_t pc, libunwind::UnwindInfoSections §ions); }; diff --git a/src/native/external/llvm-libunwind.cmake b/src/native/external/llvm-libunwind.cmake index 720dc5ae6f890f..bac63302fdc5bb 100644 --- a/src/native/external/llvm-libunwind.cmake +++ b/src/native/external/llvm-libunwind.cmake @@ -6,7 +6,6 @@ endif() set (LLVM_LIBUNWIND_SOURCES_BASE src/Unwind-EHABI.cpp - src/libunwind.cpp ) set(LLVM_LIBUNWIND_ASM_SOURCES_BASE diff --git a/src/native/external/llvm-libunwind/.clang-format b/src/native/external/llvm-libunwind/.clang-format deleted file mode 100644 index 5bead5f39dd3c5..00000000000000 --- a/src/native/external/llvm-libunwind/.clang-format +++ /dev/null @@ -1,2 +0,0 @@ -BasedOnStyle: LLVM - diff --git a/src/native/external/llvm-libunwind/CMakeLists.txt b/src/native/external/llvm-libunwind/CMakeLists.txt deleted file mode 100644 index fbef71f3f74467..00000000000000 --- a/src/native/external/llvm-libunwind/CMakeLists.txt +++ /dev/null @@ -1,356 +0,0 @@ -#=============================================================================== -# Setup Project -#=============================================================================== - -cmake_minimum_required(VERSION 3.20.0) -set(LLVM_SUBPROJECT_TITLE "libunwind") - -set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") - -# Add path for custom modules -list(INSERT CMAKE_MODULE_PATH 0 - "${CMAKE_CURRENT_SOURCE_DIR}/cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" - "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules" - "${LLVM_COMMON_CMAKE_UTILS}" - "${LLVM_COMMON_CMAKE_UTILS}/Modules" - ) - -set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH - "Specify path to libc++ source.") - -include(GNUInstallDirs) -include(CheckSymbolExists) - -if (MSVC) - message(FATAL_ERROR "Libunwind doesn't build for MSVC targets, and that is almost certainly not what you want to do " - "anyway since libunwind is tied to the Itanium C++ ABI, and MSVC targets must use the MS C++ ABI.") -endif() - -#=============================================================================== -# Setup CMake Options -#=============================================================================== -include(CMakeDependentOption) -include(HandleCompilerRT) - -# Define options. -option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF) -option(LIBUNWIND_ENABLE_GCS "Build libunwind with GCS enabled." OFF) -option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) -option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) -option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) -option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON) -option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON) -option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF) -option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF) -option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON) -option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF) -option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) -option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${LLVM_INCLUDE_DOCS}) -option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS}) -option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF) -option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF) -option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF) -option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON) -option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF) - -set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING - "Define suffix of library directory name (32/64)") -option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON) -cmake_dependent_option(LIBUNWIND_INSTALL_STATIC_LIBRARY - "Install the static libunwind library." ON - "LIBUNWIND_ENABLE_STATIC;LIBUNWIND_INSTALL_LIBRARY" OFF) -cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY - "Install the shared libunwind library." ON - "LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF) - -set(LIBUNWIND_LIBRARY_VERSION "1.0" CACHE STRING - "Version of libunwind. This will be reflected in the name of the shared library produced. - For example, -DLIBUNWIND_LIBRARY_VERSION=x.y will result in the library being named - libunwind.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms, - this also controls the linker's 'current_version' property.") - -if(MINGW) - if (LIBUNWIND_ENABLE_SHARED) - set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared-mingw.cfg.in") - else() - set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static-mingw.cfg.in") - endif() -elseif (LIBUNWIND_ENABLE_SHARED) - set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in") -else() - set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in") -endif() -set(LIBUNWIND_TEST_CONFIG "${LIBUNWIND_DEFAULT_TEST_CONFIG}" CACHE STRING - "The path to the Lit testing configuration to use when running the tests. - If a relative path is provided, it is assumed to be relative to '/libunwind/test/configs'.") -if (NOT IS_ABSOLUTE "${LIBUNWIND_TEST_CONFIG}") - set(LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBUNWIND_TEST_CONFIG}") -endif() -message(STATUS "Using libunwind testing configuration: ${LIBUNWIND_TEST_CONFIG}") -set(LIBUNWIND_TEST_PARAMS "" CACHE STRING - "A list of parameters to run the Lit test suite with.") - -if (NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC) - message(FATAL_ERROR "libunwind must be built as either a shared or static library.") -endif() - -if (LIBUNWIND_ENABLE_CET AND MSVC) - message(FATAL_ERROR "libunwind CET support is not available for MSVC!") -endif() - -if (WIN32) - set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS TRUE) -else() - set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS FALSE) -endif() -option(LIBUNWIND_HIDE_SYMBOLS - "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS}) - -# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See: -# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking -check_symbol_exists(__mips_hard_float "" __MIPSHF) -check_symbol_exists(_ABIO32 "" __MIPS_O32) -if (__MIPSHF AND __MIPS_O32) - file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c - "#if __mips_fpr != 0\n" - "# error\n" - "#endif\n") - try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c - CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo') -endif() - -#=============================================================================== -# Configure System -#=============================================================================== - -# Add path for custom modules -set(CMAKE_MODULE_PATH - "${CMAKE_CURRENT_SOURCE_DIR}/cmake" - ${CMAKE_MODULE_PATH}) - -set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING - "Path where built libunwind headers should be installed.") -set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING - "Path where built libunwind runtime libraries should be installed.") - -set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library.") -set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.") - -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) - set(LIBUNWIND_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) - if(LIBUNWIND_LIBDIR_SUBDIR) - string(APPEND LIBUNWIND_TARGET_SUBDIR /${LIBUNWIND_LIBDIR_SUBDIR}) - endif() - cmake_path(NORMAL_PATH LIBUNWIND_TARGET_SUBDIR) - set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBUNWIND_TARGET_SUBDIR}) - set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBUNWIND_TARGET_SUBDIR} CACHE STRING - "Path where built libunwind libraries should be installed.") - unset(LIBUNWIND_TARGET_SUBDIR) -else() - if(LLVM_LIBRARY_OUTPUT_INTDIR) - set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) - else() - set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) - endif() - set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE STRING - "Path where built libunwind libraries should be installed.") -endif() - -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) - -set(LIBUNWIND_C_FLAGS "") -set(LIBUNWIND_CXX_FLAGS "") -set(LIBUNWIND_COMPILE_FLAGS "") -set(LIBUNWIND_LINK_FLAGS "") -set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING "See documentation for LIBCXX_ADDITIONAL_COMPILE_FLAGS") -set(LIBUNWIND_ADDITIONAL_LIBRARIES "" CACHE STRING - "Additional libraries libunwind is linked to which can be provided in cache") - -# Include macros for adding and removing libunwind flags. -include(HandleLibunwindFlags) - -#=============================================================================== -# Setup Compiler Flags -#=============================================================================== - -# Configure compiler. -include(config-ix) - -include(HandleLibC) # Setup the C library flags - -if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) - list(APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt") -endif() - -add_compile_flags_if_supported(-Werror=return-type) - -if (LIBUNWIND_ENABLE_CET) - add_compile_flags_if_supported(-fcf-protection=full) - add_compile_flags_if_supported(-mshstk) - if (NOT CXX_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG) - message(SEND_ERROR "Compiler doesn't support CET -fcf-protection option!") - endif() - if (NOT CXX_SUPPORTS_MSHSTK_FLAG) - message(SEND_ERROR "Compiler doesn't support CET -mshstk option!") - endif() -endif() - -if (LIBUNWIND_ENABLE_GCS) - add_compile_flags_if_supported(-mbranch-protection=standard) - if (NOT CXX_SUPPORTS_MBRANCH_PROTECTION_EQ_STANDARD_FLAG) - message(SEND_ERROR "Compiler doesn't support GCS -mbranch-protection option!") - endif() -endif() - -if (WIN32) - # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT); - # silence the warning instead of cluttering the headers (which aren't - # necessarily the ones that the callers will use anyway) with the - # attributes. - add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration) -endif() - -if (MIPS_FPABI_FPXX) - add_compile_flags(-mfp64) -endif() - -# Get feature flags. -# Exceptions -# Catches C++ exceptions only and tells the compiler to assume that extern C -# functions never throw a C++ exception. -add_cxx_compile_flags_if_supported(-fstrict-aliasing) -add_cxx_compile_flags_if_supported(-EHsc) - -# Don't run the linker in this CMake check. -# -# The reason why this was added is that when building libunwind for -# ARM Linux, we need to pass the -funwind-tables flag in order for it to -# work properly with ARM EHABI. -# -# However, when performing CMake checks, adding this flag causes the check -# to produce a false negative, because the compiler generates calls -# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself, -# which isn't built yet, so the linker complains about undefined symbols. -# -# This leads to libunwind not being built with this flag, which makes -# libunwind quite useless in this setup. -set(_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -add_compile_flags_if_supported(-funwind-tables) -set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE}) - -if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG) - message(SEND_ERROR "The -funwind-tables flag must be supported " - "because this target uses ARM Exception Handling ABI") -endif() - -add_cxx_compile_flags_if_supported(-fno-exceptions) -add_cxx_compile_flags_if_supported(-fno-rtti) - -# Ensure that we don't depend on C++ standard library. -if (CXX_SUPPORTS_NOSTDINCXX_FLAG) - list(APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++) - # Remove -stdlib flags to prevent them from causing an unused flag warning. - string(REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -endif() - -# Assert -string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) -if (LIBUNWIND_ENABLE_ASSERTIONS) - # MSVC doesn't like _DEBUG on release builds. See PR 4379. - if (NOT MSVC) - add_compile_flags(-D_DEBUG) - endif() - - # On Release builds cmake automatically defines NDEBUG, so we - # explicitly undefine it: - if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - add_compile_flags(-UNDEBUG) - endif() -else() - if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - add_compile_flags(-DNDEBUG) - endif() -endif() - -# Cross-unwinding -if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING) - add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY) -endif() - -# Include stubs for __register_frame_info_bases and related -if (LIBUNWIND_ENABLE_FRAME_APIS) - add_compile_flags(-D_LIBUNWIND_SUPPORT_FRAME_APIS) -endif() - -# Threading-support -if (NOT LIBUNWIND_ENABLE_THREADS) - add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS) -endif() - -# ARM WMMX register support -if (LIBUNWIND_ENABLE_ARM_WMMX) - # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not - # define this macro for any supported target at present. Therefore, here we - # provide the option to explicitly enable support for WMMX registers in the - # unwinder. - add_compile_flags(-D__ARM_WMMX) -endif() - -if(LIBUNWIND_IS_BAREMETAL) - add_compile_definitions(_LIBUNWIND_IS_BAREMETAL) -endif() - -if(LIBUNWIND_USE_FRAME_HEADER_CACHE) - add_compile_definitions(_LIBUNWIND_USE_FRAME_HEADER_CACHE) -endif() - -if(LIBUNWIND_REMEMBER_HEAP_ALLOC) - add_compile_definitions(_LIBUNWIND_REMEMBER_HEAP_ALLOC) -endif() - -# This is the _ONLY_ place where add_definitions is called. -if (MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) -endif() - -if (C_SUPPORTS_COMMENT_LIB_PRAGMA) - if (LIBUNWIND_HAS_DL_LIB) - add_definitions(-D_LIBUNWIND_LINK_DL_LIB) - endif() - if (LIBUNWIND_HAS_PTHREAD_LIB) - add_definitions(-D_LIBUNWIND_LINK_PTHREAD_LIB) - endif() -endif() - -if (RUNTIMES_EXECUTE_ONLY_CODE) - add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE) -endif() - -add_custom_target(unwind-test-depends - COMMENT "Build dependencies required to run the libunwind test suite.") - -#=============================================================================== -# Setup Source Code -#=============================================================================== - -add_subdirectory(include) - -add_subdirectory(src) - -if (LIBUNWIND_INCLUDE_DOCS) - add_subdirectory(docs) -endif() - -if (LIBUNWIND_INCLUDE_TESTS AND EXISTS ${LLVM_CMAKE_DIR}) - add_subdirectory(test) -endif() diff --git a/src/native/external/llvm-libunwind/cmake/Modules/HandleLibunwindFlags.cmake b/src/native/external/llvm-libunwind/cmake/Modules/HandleLibunwindFlags.cmake deleted file mode 100644 index 94c676338821c7..00000000000000 --- a/src/native/external/llvm-libunwind/cmake/Modules/HandleLibunwindFlags.cmake +++ /dev/null @@ -1,116 +0,0 @@ -# HandleLibcxxFlags - A set of macros used to setup the flags used to compile -# and link libc++abi. These macros add flags to the following CMake variables. -# - LIBUNWIND_COMPILE_FLAGS: flags used to compile libunwind -# - LIBUNWIND_LINK_FLAGS: flags used to link libunwind -# - LIBUNWIND_LIBRARIES: libraries to link libunwind to. - -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) -include(HandleFlags) - -unset(add_flag_if_supported) - -# Add a list of flags to 'LIBUNWIND_COMPILE_FLAGS'. -macro(add_compile_flags) - foreach(f ${ARGN}) - list(APPEND LIBUNWIND_COMPILE_FLAGS ${f}) - endforeach() -endmacro() - -# If 'condition' is true then add the specified list of flags to -# 'LIBUNWIND_COMPILE_FLAGS' -macro(add_compile_flags_if condition) - if (${condition}) - add_compile_flags(${ARGN}) - endif() -endmacro() - -# For each specified flag, add that flag to 'LIBUNWIND_COMPILE_FLAGS' if the -# flag is supported by the C++ compiler. -macro(add_compile_flags_if_supported) - foreach(flag ${ARGN}) - mangle_name("${flag}" flagname) - check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") - add_compile_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) - endforeach() -endmacro() - -# Add a list of flags to 'LIBUNWIND_C_FLAGS'. -macro(add_c_flags) - foreach(f ${ARGN}) - list(APPEND LIBUNWIND_C_FLAGS ${f}) - endforeach() -endmacro() - -# If 'condition' is true then add the specified list of flags to -# 'LIBUNWIND_C_FLAGS' -macro(add_c_flags_if condition) - if (${condition}) - add_c_flags(${ARGN}) - endif() -endmacro() - -# Add a list of flags to 'LIBUNWIND_CXX_FLAGS'. -macro(add_cxx_flags) - foreach(f ${ARGN}) - list(APPEND LIBUNWIND_CXX_FLAGS ${f}) - endforeach() -endmacro() - -# If 'condition' is true then add the specified list of flags to -# 'LIBUNWIND_CXX_FLAGS' -macro(add_cxx_flags_if condition) - if (${condition}) - add_cxx_flags(${ARGN}) - endif() -endmacro() - -# For each specified flag, add that flag to 'LIBUNWIND_CXX_FLAGS' if the -# flag is supported by the C compiler. -macro(add_cxx_compile_flags_if_supported) - foreach(flag ${ARGN}) - mangle_name("${flag}" flagname) - check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") - add_cxx_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) - endforeach() -endmacro() - -# Add a list of flags to 'LIBUNWIND_LINK_FLAGS'. -macro(add_link_flags) - foreach(f ${ARGN}) - list(APPEND LIBUNWIND_LINK_FLAGS ${f}) - endforeach() -endmacro() - -# If 'condition' is true then add the specified list of flags to -# 'LIBUNWIND_LINK_FLAGS' -macro(add_link_flags_if condition) - if (${condition}) - add_link_flags(${ARGN}) - endif() -endmacro() - -# For each specified flag, add that flag to 'LIBUNWIND_LINK_FLAGS' if the -# flag is supported by the C++ compiler. -macro(add_link_flags_if_supported) - foreach(flag ${ARGN}) - mangle_name("${flag}" flagname) - check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") - add_link_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) - endforeach() -endmacro() - -# Add a list of libraries or link flags to 'LIBUNWIND_LIBRARIES'. -macro(add_library_flags) - foreach(lib ${ARGN}) - list(APPEND LIBUNWIND_LIBRARIES ${lib}) - endforeach() -endmacro() - -# if 'condition' is true then add the specified list of libraries and flags -# to 'LIBUNWIND_LIBRARIES'. -macro(add_library_flags_if condition) - if(${condition}) - add_library_flags(${ARGN}) - endif() -endmacro() diff --git a/src/native/external/llvm-libunwind/cmake/config-ix.cmake b/src/native/external/llvm-libunwind/cmake/config-ix.cmake deleted file mode 100644 index d42ceffb1f631e..00000000000000 --- a/src/native/external/llvm-libunwind/cmake/config-ix.cmake +++ /dev/null @@ -1,73 +0,0 @@ -include(CMakePushCheckState) -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) -include(CheckLibraryExists) -include(LLVMCheckCompilerLinkerFlag) -include(CheckSymbolExists) -include(CheckCSourceCompiles) - -# The compiler driver may be implicitly trying to link against libunwind, which -# might not work if libunwind doesn't exist yet. Try to check if -# --unwindlib=none is supported, and use that if possible. -llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG) - -if (HAIKU) - check_library_exists(root fopen "" LIBUNWIND_HAS_ROOT_LIB) -else() - check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB) -endif() - -if (NOT LIBUNWIND_USE_COMPILER_RT) - if (ANDROID) - check_library_exists(gcc __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_LIB) - else () - check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB) - check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB) - endif () -endif() - -if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG) - if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") - endif () - if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fsanitize-coverage=0") - endif () -endif () - -# Check compiler pragmas -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas") - check_c_source_compiles(" -#pragma comment(lib, \"c\") -int main(void) { return 0; } -" C_SUPPORTS_COMMENT_LIB_PRAGMA) - cmake_pop_check_state() -endif() - -# Check compiler flags -check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG) - -# Check symbols -check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM) -check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS) -check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH) - -if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT LIBUNWIND_USES_DWARF_EH) - # This condition is copied from __libunwind_config.h - set(LIBUNWIND_USES_ARM_EHABI ON) -endif() - -# Check libraries -if(FUCHSIA) - set(LIBUNWIND_HAS_DL_LIB NO) - set(LIBUNWIND_HAS_PTHREAD_LIB NO) -else() - check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB) - check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB) -endif() - -if(HAIKU) - check_library_exists(bsd dl_iterate_phdr "" LIBUNWIND_HAS_BSD_LIB) -endif() diff --git a/src/native/external/llvm-libunwind/docs/BuildingLibunwind.rst b/src/native/external/llvm-libunwind/docs/BuildingLibunwind.rst deleted file mode 100644 index c231587fd50224..00000000000000 --- a/src/native/external/llvm-libunwind/docs/BuildingLibunwind.rst +++ /dev/null @@ -1,133 +0,0 @@ -.. _BuildingLibunwind: - -================== -Building libunwind -================== - -.. contents:: - :local: - -.. _build instructions: - -Getting Started -=============== - -On Mac OS, the easiest way to get this library is to link with -lSystem. -However if you want to build tip-of-trunk from here (getting the bleeding -edge), read on. - -The basic steps needed to build libunwind are: - -#. Checkout LLVM, libunwind, and related projects: - - * ``cd where-you-want-llvm-to-live`` - * ``git clone https://github.com/llvm/llvm-project.git`` - -#. Configure and build libunwind: - - CMake is the only supported configuration system. - - Clang is the preferred compiler when building and using libunwind. - - * ``cd where you want to build llvm`` - * ``mkdir build`` - * ``cd build`` - * ``cmake -G -DLLVM_ENABLE_RUNTIMES=libunwind [options] /runtimes`` - - For more information about configuring libunwind see :ref:`CMake Options`. - - * ``make unwind`` --- will build libunwind. - * ``make check-unwind`` --- will run the test suite. - - Shared and static libraries for libunwind should now be present in llvm/build/lib. - -#. **Optional**: Install libunwind - - If your system already provides an unwinder, it is important to be careful - not to replace it. Remember Use the CMake option ``CMAKE_INSTALL_PREFIX`` to - select a safe place to install libunwind. - - * ``make install-unwind`` --- Will install the libraries and the headers - - -.. _CMake Options: - -CMake Options -============= - -Here are some of the CMake variables that are used often, along with a -brief explanation and LLVM-specific notes. For full documentation, check the -CMake docs or execute ``cmake --help-variable VARIABLE_NAME``. - -**CMAKE_BUILD_TYPE**:STRING - Sets the build type for ``make`` based generators. Possible values are - Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio - the user sets the build type with the IDE settings. - -**CMAKE_INSTALL_PREFIX**:PATH - Path where LLVM will be installed if "make install" is invoked or the - "INSTALL" target is built. - -**CMAKE_CXX_COMPILER**:STRING - The C++ compiler to use when building and testing libunwind. - - -.. _libunwind-specific options: - -libunwind specific options --------------------------- - -.. option:: LIBUNWIND_ENABLE_ASSERTIONS:BOOL - - **Default**: ``ON`` - - Toggle assertions independent of the build mode. - -.. option:: LIBUNWIND_ENABLE_PEDANTIC:BOOL - - **Default**: ``ON`` - - Compile with -Wpedantic. - -.. option:: LIBUNWIND_ENABLE_WERROR:BOOL - - **Default**: ``OFF`` - - Compile with -Werror - -.. option:: LIBUNWIND_ENABLE_SHARED:BOOL - - **Default**: ``ON`` - - Build libunwind as a shared library. - -.. option:: LIBUNWIND_ENABLE_STATIC:BOOL - - **Default**: ``ON`` - - Build libunwind as a static archive. - -.. option:: LIBUNWIND_ENABLE_CROSS_UNWINDING:BOOL - - **Default**: ``OFF`` - - Enable cross-platform unwinding support. - -.. option:: LIBUNWIND_ENABLE_ARM_WMMX:BOOL - - **Default**: ``OFF`` - - Enable unwinding support for ARM WMMX registers. - -.. option:: LIBUNWIND_ENABLE_THREADS:BOOL - - **Default**: ``ON`` - - Build libunwind with threading support. - -.. option:: LIBUNWIND_INSTALL_LIBRARY_DIR:PATH - - **Default**: ``lib${LIBUNWIND_LIBDIR_SUFFIX}`` - - Path where built libunwind libraries should be installed. If a relative path, - relative to ``CMAKE_INSTALL_PREFIX``. diff --git a/src/native/external/llvm-libunwind/docs/CMakeLists.txt b/src/native/external/llvm-libunwind/docs/CMakeLists.txt deleted file mode 100644 index 79b87eb03b447f..00000000000000 --- a/src/native/external/llvm-libunwind/docs/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -include(FindSphinx) -if (SPHINX_FOUND AND LLVM_ENABLE_SPHINX) - include(AddSphinxTarget) - if (${SPHINX_OUTPUT_HTML}) - add_sphinx_target(html libunwind) - endif() -endif() diff --git a/src/native/external/llvm-libunwind/docs/README.txt b/src/native/external/llvm-libunwind/docs/README.txt deleted file mode 100644 index 968982fce5e076..00000000000000 --- a/src/native/external/llvm-libunwind/docs/README.txt +++ /dev/null @@ -1,13 +0,0 @@ -libunwind Documentation -==================== - -The libunwind documentation is written using the Sphinx documentation generator. It is -currently tested with Sphinx 1.1.3. - -To build the documents into html configure libunwind with the following cmake options: - - * -DLLVM_ENABLE_SPHINX=ON - * -DLIBUNWIND_INCLUDE_DOCS=ON - -After configuring libunwind with these options the make rule `docs-libunwind-html` -should be available. diff --git a/src/native/external/llvm-libunwind/docs/conf.py b/src/native/external/llvm-libunwind/docs/conf.py deleted file mode 100644 index 29f9c24a7ee261..00000000000000 --- a/src/native/external/llvm-libunwind/docs/conf.py +++ /dev/null @@ -1,252 +0,0 @@ -# -*- coding: utf-8 -*- -# -# libunwind documentation build configuration file. -# -# This file is execfile()d with the current directory set to its containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys, os -from datetime import date - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# sys.path.insert(0, os.path.abspath('.')) - -# -- General configuration ----------------------------------------------------- - -# If your documentation needs a minimal Sphinx version, state it here. -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ["sphinx.ext.intersphinx", "sphinx.ext.todo"] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# The suffix of source filenames. -source_suffix = ".rst" - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = "index" - -# General information about the project. -project = "libunwind" -copyright = "2011-%d, LLVM Project" % date.today().year - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -version = "17.0" -# The full version, including alpha/beta/rc tags. -release = "17.0" - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -today_fmt = "%Y-%m-%d" - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -show_authors = True - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "friendly" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - - -# -- Options for HTML output --------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "haiku" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = "libunwinddoc" - - -# -- Options for LaTeX output -------------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - #'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - #'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - #'preamble': '', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). -latex_documents = [ - ("contents", "libunwind.tex", "libunwind Documentation", "LLVM project", "manual"), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output -------------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [("contents", "libunwind", "libunwind Documentation", ["LLVM project"], 1)] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------------ - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - "contents", - "libunwind", - "libunwind Documentation", - "LLVM project", - "libunwind", - "LLVM Unwinder", - "Miscellaneous", - ), -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - - -# FIXME: Define intersphinx configuration. -intersphinx_mapping = {} - - -# -- Options for extensions ---------------------------------------------------- - -# Enable this if you want TODOs to show up in the generated documentation. -todo_include_todos = True diff --git a/src/native/external/llvm-libunwind/docs/index.rst b/src/native/external/llvm-libunwind/docs/index.rst deleted file mode 100644 index 03542464011461..00000000000000 --- a/src/native/external/llvm-libunwind/docs/index.rst +++ /dev/null @@ -1,101 +0,0 @@ -.. _index: - -======================= -libunwind LLVM Unwinder -======================= - -Overview -======== - -libunwind is an implementation of the interface defined by the HP libunwind -project. It was contributed by Apple as a way to enable clang++ to port to -platforms that do not have a system unwinder. It is intended to be a small and -fast implementation of the ABI, leaving off some features of HP's libunwind -that never materialized (e.g. remote unwinding). - -The unwinder has two levels of API. The high level APIs are the `_Unwind_*` -functions which implement functionality required by `__cxa_*` exception -functions. The low level APIs are the `unw_*` functions which are an interface -defined by the old HP libunwind project. - -Getting Started with libunwind ------------------------------- - -.. toctree:: - :maxdepth: 2 - - BuildingLibunwind - -Current Status --------------- - -libunwind is a production-quality unwinder, with platform support for DWARF -unwind info, SjLj, and ARM EHABI. - -The low level libunwind API was designed to work either in-process (aka local) -or to operate on another process (aka remote), but only the local path has been -implemented. Remote unwinding remains as future work. - -Platform and Compiler Support ------------------------------ - -libunwind is known to work on the following platforms: - -============ ======================== ============ ======================== -OS Arch Compilers Unwind Info -============ ======================== ============ ======================== -Any i386, x86_64, ARM Clang SjLj -Bare Metal ARM Clang, GCC EHABI -FreeBSD i386, x86_64, ARM64 Clang DWARF CFI -iOS ARM Clang SjLj -Linux ARM Clang, GCC EHABI -Linux i386, x86_64, ARM64 Clang, GCC DWARF CFI -macOS i386, x86_64 Clang, GCC DWARF CFI -NetBSD x86_64 Clang, GCC DWARF CFI -Windows i386, x86_64, ARM, ARM64 Clang DWARF CFI -============ ======================== ============ ======================== - -The following minimum compiler versions are strongly recommended. - -* Clang 3.5 and above -* GCC 4.7 and above. - -Anything older *may* work. - -Notes and Known Issues ----------------------- - -* TODO - - -Getting Involved -================ - -First please review our `Developer's Policy `__ -and `Getting started with LLVM `__. - -**Bug Reports** - -If you think you've found a bug in libunwind, please report it using -the `LLVM bug tracker`_. If you're not sure, you -can ask for support on the `Runtimes forum`_ or on Discord. -Please use the tag "libunwind" for new threads. - -**Patches** - -If you want to contribute a patch to libunwind, please start by reading the LLVM -`documentation about contributing `__. - -**Discussion and Questions** - -Send discussions and questions to the `Runtimes forum`_. Please add the tag "libunwind" to your post. - - -Quick Links -=========== -* `LLVM Homepage `_ -* `LLVM Bug Tracker `_ -* `Clang Discourse Forums `_ -* `cfe-commits Mailing List `_ -* `Runtimes Forum `_ -* `Browse libunwind Sources `_ diff --git a/src/native/external/llvm-libunwind/include/CMakeLists.txt b/src/native/external/llvm-libunwind/include/CMakeLists.txt deleted file mode 100644 index eefd4305d06cc1..00000000000000 --- a/src/native/external/llvm-libunwind/include/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(files - __libunwind_config.h - libunwind.h - libunwind.modulemap - mach-o/compact_unwind_encoding.h - unwind_arm_ehabi.h - unwind_itanium.h - unwind.h - ) - -add_library(unwind-headers INTERFACE) -target_include_directories(unwind-headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) - -if(LIBUNWIND_INSTALL_HEADERS) - foreach(file ${files}) - get_filename_component(dir ${file} DIRECTORY) - install(FILES ${file} - DESTINATION "${LIBUNWIND_INSTALL_INCLUDE_DIR}/${dir}" - COMPONENT unwind-headers - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - ) - endforeach() - - if (NOT CMAKE_CONFIGURATION_TYPES) - add_custom_target(install-unwind-headers - DEPENDS unwind-headers - COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind-headers) - add_custom_target(install-unwind-headers-stripped DEPENDS install-unwind-headers) - endif() -endif() diff --git a/src/native/external/llvm-libunwind/include/libunwind.modulemap b/src/native/external/llvm-libunwind/include/libunwind.modulemap deleted file mode 100644 index 775841ecb5f188..00000000000000 --- a/src/native/external/llvm-libunwind/include/libunwind.modulemap +++ /dev/null @@ -1,13 +0,0 @@ -module libunwind [system] { - header "libunwind.h" - export * -} - -module unwind [system] { - header "__libunwind_config.h" - header "unwind.h" - private textual header "unwind_arm_ehabi.h" - private textual header "unwind_itanium.h" - - export * -} diff --git a/src/native/external/llvm-libunwind/src/AddressSpace.hpp b/src/native/external/llvm-libunwind/src/AddressSpace.hpp index 435232dff8f423..0967f598195402 100644 --- a/src/native/external/llvm-libunwind/src/AddressSpace.hpp +++ b/src/native/external/llvm-libunwind/src/AddressSpace.hpp @@ -225,8 +225,6 @@ class _LIBUNWIND_HIDDEN LocalAddressSpace { template bool findOtherFDE(typename R::link_hardened_reg_arg_t targetAddr, pint_t &fde); - - static LocalAddressSpace sThisAddressSpace; }; inline uintptr_t LocalAddressSpace::getP(pint_t addr) { diff --git a/src/native/external/llvm-libunwind/src/CMakeLists.txt b/src/native/external/llvm-libunwind/src/CMakeLists.txt deleted file mode 100644 index 6e947039fb0d52..00000000000000 --- a/src/native/external/llvm-libunwind/src/CMakeLists.txt +++ /dev/null @@ -1,239 +0,0 @@ -# Get sources - -set(LIBUNWIND_CXX_SOURCES - libunwind.cpp - Unwind-EHABI.cpp - Unwind-seh.cpp - ) - -if("${CMAKE_SYSTEM_NAME}" MATCHES "AIX") - list(APPEND LIBUNWIND_CXX_SOURCES - Unwind_AIXExtras.cpp - ) -endif() - -set(LIBUNWIND_C_SOURCES - UnwindLevel1.c - UnwindLevel1-gcc-ext.c - Unwind-sjlj.c - Unwind-wasm.c - ) -set_source_files_properties(${LIBUNWIND_C_SOURCES} - PROPERTIES - # We need to set `-fexceptions` here so that key - # unwinding functions, like - # _UNWIND_RaiseException, are not marked as - # `nounwind`, which breaks LTO builds of - # libunwind. See #56825 and #120657 for context. - COMPILE_FLAGS "-std=c99 -fexceptions") - -set(LIBUNWIND_ASM_SOURCES - UnwindRegistersRestore.S - UnwindRegistersSave.S - ) - -set(LIBUNWIND_HEADERS - AddressSpace.hpp - assembly.h - CompactUnwinder.hpp - config.h - dwarf2.h - DwarfInstructions.hpp - DwarfParser.hpp - EHHeaderParser.hpp - FrameHeaderCache.hpp - libunwind_ext.h - Registers.hpp - RWMutex.hpp - shadow_stack_unwind.h - Unwind-EHABI.h - UnwindCursor.hpp - ../include/libunwind.h - ../include/unwind.h - ../include/unwind_itanium.h - ../include/unwind_arm_ehabi.h - ) -if(APPLE) - list(APPEND LIBUNWIND_HEADERS - ../include/mach-o/compact_unwind_encoding.h - ) -endif() - -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() - -set(LIBUNWIND_SOURCES - ${LIBUNWIND_CXX_SOURCES} - ${LIBUNWIND_C_SOURCES} - ${LIBUNWIND_ASM_SOURCES}) - -# Generate library list. -if (NOT APPLE) - add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl) -endif() - -if (LIBUNWIND_ENABLE_THREADS AND NOT APPLE) - add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread) -endif() - -if (LIBUNWIND_ENABLE_THREADS) - add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1) -endif() - -# Setup flags. -add_link_flags_if(CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG --unwindlib=none) - -# MINGW_LIBRARIES is defined in config-ix.cmake -add_library_flags_if(MINGW "${MINGW_LIBRARIES}") - -if (LIBUNWIND_ENABLE_SHARED AND - NOT (CXX_SUPPORTS_FNO_EXCEPTIONS_FLAG AND - CXX_SUPPORTS_FUNWIND_TABLES_FLAG)) - message(FATAL_ERROR - "Compiler doesn't support generation of unwind tables if exception " - "support is disabled. Building libunwind DSO with runtime dependency " - "on C++ ABI library is not supported.") -endif() - -if (HAIKU) - add_library_flags_if(LIBUNWIND_HAS_ROOT_LIB root) - - add_library_flags_if(LIBUNWIND_HAS_BSD_LIB bsd) - add_compile_flags_if(LIBUNWIND_HAS_BSD_LIB -D_LIBUNWIND_USE_HAIKU_BSD_LIB=1) - - add_compile_flags("-D_DEFAULT_SOURCE") - add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME") -endif () - -string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}") -string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}") -string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}") -string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}") - -set_property(SOURCE ${LIBUNWIND_CXX_SOURCES} - APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_CXX_FLAGS}") -set_property(SOURCE ${LIBUNWIND_C_SOURCES} - APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBUNWIND_C_FLAGS}") - -# NOTE: avoid implicit dependencies on C++ runtimes. libunwind uses C++ for -# ease, but does not rely on C++ at runtime. -set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") - -include(WarningFlags) - -# Build the shared library. -add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) -cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC}) -if(CMAKE_C_COMPILER_ID STREQUAL MSVC) - target_compile_options(unwind_shared_objects PRIVATE /GR-) -else() - target_compile_options(unwind_shared_objects PRIVATE -fno-rtti) -endif() -target_compile_options(unwind_shared_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}") -target_link_libraries(unwind_shared_objects - PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}" - PRIVATE unwind-headers runtimes-libc-headers ${LIBUNWIND_LIBRARIES}) -set_target_properties(unwind_shared_objects - PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED ON - COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" -) -if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) - set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library -endif() - -add_library(unwind_shared SHARED) -target_link_libraries(unwind_shared PUBLIC unwind_shared_objects runtimes-libc-shared) -set_target_properties(unwind_shared - PROPERTIES - EXCLUDE_FROM_ALL "$,FALSE,TRUE>" - LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" - LINKER_LANGUAGE C - OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}" - VERSION "${LIBUNWIND_LIBRARY_VERSION}" - SOVERSION "1" -) - -# Build the static library. -add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS}) -cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC}) -if(CMAKE_C_COMPILER_ID STREQUAL MSVC) - target_compile_options(unwind_static_objects PRIVATE /GR-) -else() - target_compile_options(unwind_static_objects PRIVATE -fno-rtti) -endif() -target_compile_options(unwind_static_objects PUBLIC "${LIBUNWIND_ADDITIONAL_COMPILE_FLAGS}") -target_link_libraries(unwind_static_objects - PUBLIC "${LIBUNWIND_ADDITIONAL_LIBRARIES}" - PRIVATE unwind-headers runtimes-libc-headers ${LIBUNWIND_LIBRARIES}) -set_target_properties(unwind_static_objects - PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED ON - COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}" -) - -if(LIBUNWIND_HIDE_SYMBOLS) - target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility=hidden) - target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete=force-hidden) - if (NOT CXX_SUPPORTS_FVISIBILITY_GLOBAL_NEW_DELETE_EQ_FORCE_HIDDEN_FLAG) - target_add_compile_flags_if_supported(unwind_static_objects PRIVATE -fvisibility-global-new-delete-hidden) - endif() - target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS) -endif() - -add_library(unwind_static STATIC) -target_link_libraries(unwind_static PUBLIC unwind_static_objects runtimes-libc-static) -set_target_properties(unwind_static - PROPERTIES - EXCLUDE_FROM_ALL "$,FALSE,TRUE>" - LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" - LINKER_LANGUAGE C - OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}" -) - -# Add a meta-target for both libraries. -add_custom_target(unwind) -if (LIBUNWIND_ENABLE_SHARED) - add_dependencies(unwind unwind_shared) -endif() -if (LIBUNWIND_ENABLE_STATIC) - add_dependencies(unwind unwind_static) -endif() - -if (LIBUNWIND_INSTALL_SHARED_LIBRARY) - install(TARGETS unwind_shared - ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind - LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind - RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind) -endif() - -if (LIBUNWIND_INSTALL_STATIC_LIBRARY) - install(TARGETS unwind_static - ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind - LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind - RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind) -endif() - -if (NOT CMAKE_CONFIGURATION_TYPES) - add_custom_target(install-unwind - COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind) - add_custom_target(install-unwind-stripped - COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind --strip) - - if (LIBUNWIND_INSTALL_LIBRARY) - add_dependencies(install-unwind unwind) - add_dependencies(install-unwind-stripped unwind) - endif() - - if(LIBUNWIND_INSTALL_HEADERS) - add_dependencies(install-unwind install-unwind-headers) - add_dependencies(install-unwind-stripped install-unwind-headers-stripped) - endif() -endif() diff --git a/src/native/external/llvm-libunwind/src/Unwind-EHABI.cpp b/src/native/external/llvm-libunwind/src/Unwind-EHABI.cpp index 338c853bca780e..738e51706a5047 100644 --- a/src/native/external/llvm-libunwind/src/Unwind-EHABI.cpp +++ b/src/native/external/llvm-libunwind/src/Unwind-EHABI.cpp @@ -40,16 +40,6 @@ uint8_t getByte(const uint32_t* data, size_t offset) { #endif } -const char* getNextWord(const char* data, uint32_t* out) { - *out = *reinterpret_cast(data); - return data + 4; -} - -const char* getNextNibble(const char* data, uint32_t* out) { - *out = *reinterpret_cast(data); - return data + 2; -} - struct Descriptor { // See # 9.2 typedef enum { @@ -60,142 +50,8 @@ struct Descriptor { RESERVED4 = 8, RESERVED5 = 9, RESERVED6 = 10, RESERVED7 = 11, RESERVED8 = 12, RESERVED9 = 13, RESERVED10 = 14, RESERVED11 = 15 } Format; - - // See # 9.2 - typedef enum { - CLEANUP = 0x0, - FUNC = 0x1, - CATCH = 0x2, - INVALID = 0x4 - } Kind; }; -_Unwind_Reason_Code ProcessDescriptors( - _Unwind_State state, - _Unwind_Control_Block* ucbp, - struct _Unwind_Context* context, - Descriptor::Format format, - const char* descriptorStart, - uint32_t flags) { - - // EHT is inlined in the index using compact form. No descriptors. #5 - if (flags & 0x1) - return _URC_CONTINUE_UNWIND; - - // TODO: We should check the state here, and determine whether we need to - // perform phase1 or phase2 unwinding. - (void)state; - - const char* descriptor = descriptorStart; - uint32_t descriptorWord; - getNextWord(descriptor, &descriptorWord); - while (descriptorWord) { - // Read descriptor based on # 9.2. - uint32_t length; - uint32_t offset; - switch (format) { - case Descriptor::LU32: - descriptor = getNextWord(descriptor, &length); - descriptor = getNextWord(descriptor, &offset); - break; - case Descriptor::LU16: - descriptor = getNextNibble(descriptor, &length); - descriptor = getNextNibble(descriptor, &offset); - break; - default: - assert(false); - return _URC_FAILURE; - } - - // See # 9.2 table for decoding the kind of descriptor. It's a 2-bit value. - Descriptor::Kind kind = - static_cast((length & 0x1) | ((offset & 0x1) << 1)); - - // Clear off flag from last bit. - length &= ~1u; - offset &= ~1u; - uintptr_t scopeStart = ucbp->pr_cache.fnstart + offset; - uintptr_t scopeEnd = scopeStart + length; - uintptr_t pc = _Unwind_GetIP(context); - bool isInScope = (scopeStart <= pc) && (pc < scopeEnd); - - switch (kind) { - case Descriptor::CLEANUP: { - // TODO(ajwong): Handle cleanup descriptors. - break; - } - case Descriptor::FUNC: { - // TODO(ajwong): Handle function descriptors. - break; - } - case Descriptor::CATCH: { - // Catch descriptors require gobbling one more word. - uint32_t landing_pad; - descriptor = getNextWord(descriptor, &landing_pad); - - if (isInScope) { - // TODO(ajwong): This is only phase1 compatible logic. Implement - // phase2. - landing_pad = signExtendPrel31(landing_pad & ~0x80000000); - if (landing_pad == 0xffffffff) { - return _URC_HANDLER_FOUND; - } else if (landing_pad == 0xfffffffe) { - return _URC_FAILURE; - } else { - /* - bool is_reference_type = landing_pad & 0x80000000; - void* matched_object; - if (__cxxabiv1::__cxa_type_match( - ucbp, reinterpret_cast(landing_pad), - is_reference_type, - &matched_object) != __cxxabiv1::ctm_failed) - return _URC_HANDLER_FOUND; - */ - _LIBUNWIND_ABORT("Type matching not implemented"); - } - } - break; - } - default: - _LIBUNWIND_ABORT("Invalid descriptor kind found."); - } - - getNextWord(descriptor, &descriptorWord); - } - - return _URC_CONTINUE_UNWIND; -} - -static _Unwind_Reason_Code unwindOneFrame(_Unwind_State state, - _Unwind_Control_Block* ucbp, - struct _Unwind_Context* context) { - // Read the compact model EHT entry's header # 6.3 - const uint32_t* unwindingData = ucbp->pr_cache.ehtp; - assert((*unwindingData & 0xf0000000) == 0x80000000 && "Must be a compact entry"); - Descriptor::Format format = - static_cast((*unwindingData & 0x0f000000) >> 24); - - const char *lsda = - reinterpret_cast(_Unwind_GetLanguageSpecificData(context)); - - // Handle descriptors before unwinding so they are processed in the context - // of the correct stack frame. - _Unwind_Reason_Code result = - ProcessDescriptors(state, ucbp, context, format, lsda, - ucbp->pr_cache.additional); - - if (result != _URC_CONTINUE_UNWIND) - return result; - - switch (__unw_step(reinterpret_cast(context))) { - case UNW_STEP_SUCCESS: - return _URC_CONTINUE_UNWIND; - case UNW_STEP_END: - return _URC_END_OF_STACK; - default: - return _URC_FAILURE; - } -} // Generates mask discriminator for _Unwind_VRS_Pop, e.g. for _UVRSC_CORE / // _UVRSD_UINT32. @@ -443,771 +299,5 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data, return _URC_CONTINUE_UNWIND; } -extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code -__aeabi_unwind_cpp_pr0(_Unwind_State state, _Unwind_Control_Block *ucbp, - _Unwind_Context *context) { - return unwindOneFrame(state, ucbp, context); -} - -extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code -__aeabi_unwind_cpp_pr1(_Unwind_State state, _Unwind_Control_Block *ucbp, - _Unwind_Context *context) { - return unwindOneFrame(state, ucbp, context); -} - -extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code -__aeabi_unwind_cpp_pr2(_Unwind_State state, _Unwind_Control_Block *ucbp, - _Unwind_Context *context) { - return unwindOneFrame(state, ucbp, context); -} - -static _Unwind_Reason_Code -unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { - // EHABI #7.3 discusses preserving the VRS in a "temporary VRS" during - // phase 1 and then restoring it to the "primary VRS" for phase 2. The - // effect is phase 2 doesn't see any of the VRS manipulations from phase 1. - // In this implementation, the phases don't share the VRS backing store. - // Instead, they are passed the original |uc| and they create a new VRS - // from scratch thus achieving the same effect. - __unw_init_local(cursor, uc); - - // Walk each frame looking for a place to stop. - for (bool handlerNotFound = true; handlerNotFound;) { - - // See if frame has code to run (has personality routine). - unw_proc_info_t frameInfo; - if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): __unw_get_proc_info " - "failed => _URC_FATAL_PHASE1_ERROR", - static_cast(exception_object)); - return _URC_FATAL_PHASE1_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - unw_word_t pc; - __unw_get_reg(cursor, UNW_REG_IP, &pc); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): pc=0x%" PRIxPTR ", start_ip=0x%" PRIxPTR ", func=%s, " - "lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR, - static_cast(exception_object), pc, - frameInfo.start_ip, functionName, - frameInfo.lsda, frameInfo.handler); - } -#endif - - // If there is a personality routine, ask it if it will want to stop at - // this frame. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = - (_Unwind_Personality_Fn)(long)(frameInfo.handler); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): calling personality function %p", - static_cast(exception_object), - reinterpret_cast(reinterpret_cast(p))); - struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor); - exception_object->pr_cache.fnstart = frameInfo.start_ip; - exception_object->pr_cache.ehtp = - (_Unwind_EHT_Header *)frameInfo.unwind_info; - exception_object->pr_cache.additional = frameInfo.flags; - _Unwind_Reason_Code personalityResult = - (*p)(_US_VIRTUAL_UNWIND_FRAME, exception_object, context); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): personality result %d start_ip %x ehtp %p " - "additional %x", - static_cast(exception_object), personalityResult, - exception_object->pr_cache.fnstart, - static_cast(exception_object->pr_cache.ehtp), - exception_object->pr_cache.additional); - switch (personalityResult) { - case _URC_HANDLER_FOUND: - // found a catch clause or locals that need destructing in this frame - // stop search and remember stack pointer at the frame - handlerNotFound = false; - // p should have initialized barrier_cache. EHABI #7.3.5 - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): _URC_HANDLER_FOUND", - static_cast(exception_object)); - return _URC_NO_REASON; - - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): _URC_CONTINUE_UNWIND", - static_cast(exception_object)); - // continue unwinding - break; - - // EHABI #7.3.3 - case _URC_FAILURE: - return _URC_FAILURE; - - default: - // something went wrong - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): _URC_FATAL_PHASE1_ERROR", - static_cast(exception_object)); - return _URC_FATAL_PHASE1_ERROR; - } - } - } - return _URC_NO_REASON; -} - -static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, - _Unwind_Exception *exception_object, - bool resume) { - // See comment at the start of unwind_phase1 regarding VRS integrity. - __unw_init_local(cursor, uc); - - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)", - static_cast(exception_object)); - int frame_count = 0; - - // Walk each frame until we reach where search phase said to stop. - while (true) { - // Ask libunwind to get next frame (skip over first which is - // _Unwind_RaiseException or _Unwind_Resume). - // - // Resume only ever makes sense for 1 frame. - _Unwind_State state = - resume ? _US_UNWIND_FRAME_RESUME : _US_UNWIND_FRAME_STARTING; - if (resume && frame_count == 1) { - // On a resume, first unwind the _Unwind_Resume() frame. The next frame - // is now the landing pad for the cleanup from a previous execution of - // phase2. To continue unwindingly correctly, replace VRS[15] with the - // IP of the frame that the previous run of phase2 installed the context - // for. After this, continue unwinding as if normal. - // - // See #7.4.6 for details. - __unw_set_reg(cursor, UNW_REG_IP, - exception_object->unwinder_cache.reserved2, NULL); - resume = false; - } - - // Get info about this frame. - unw_word_t sp; - unw_proc_info_t frameInfo; - __unw_get_reg(cursor, UNW_REG_SP, &sp); - if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): __unw_get_proc_info " - "failed => _URC_FATAL_PHASE2_ERROR", - static_cast(exception_object)); - return _URC_FATAL_PHASE2_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIxPTR ", func=%s, sp=0x%" PRIxPTR ", " - "lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR "", - static_cast(exception_object), frameInfo.start_ip, - functionName, sp, frameInfo.lsda, - frameInfo.handler); - } -#endif - - // If there is a personality routine, tell it we are unwinding. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = - (_Unwind_Personality_Fn)(intptr_t)(frameInfo.handler); - struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor); - // EHABI #7.2 - exception_object->pr_cache.fnstart = frameInfo.start_ip; - exception_object->pr_cache.ehtp = - (_Unwind_EHT_Header *)frameInfo.unwind_info; - exception_object->pr_cache.additional = frameInfo.flags; - _Unwind_Reason_Code personalityResult = - (*p)(state, exception_object, context); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - // Continue unwinding - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND", - static_cast(exception_object)); - // EHABI #7.2 - if (sp == exception_object->barrier_cache.sp) { - // Phase 1 said we would stop at this frame, but we did not... - _LIBUNWIND_ABORT("during phase1 personality function said it would " - "stop here, but now in phase2 it did not stop here"); - } - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): _URC_INSTALL_CONTEXT", - static_cast(exception_object)); - // Personality routine says to transfer control to landing pad. - // We may get control back if landing pad calls _Unwind_Resume(). - if (_LIBUNWIND_TRACING_UNWINDING) { - unw_word_t pc; - __unw_get_reg(cursor, UNW_REG_IP, &pc); - __unw_get_reg(cursor, UNW_REG_SP, &sp); - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering " - "user code with ip=0x%" PRIxPTR ", sp=0x%" PRIxPTR, - static_cast(exception_object), - pc, sp); - } - - { - // EHABI #7.4.1 says we need to preserve pc for when _Unwind_Resume - // is called back, to find this same frame. - unw_word_t pc; - __unw_get_reg(cursor, UNW_REG_IP, &pc); - exception_object->unwinder_cache.reserved2 = (uint32_t)pc; - } - __unw_resume(cursor); - // __unw_resume() only returns if there was an error. - return _URC_FATAL_PHASE2_ERROR; - - // # EHABI #7.4.3 - case _URC_FAILURE: - abort(); - - default: - // Personality routine returned an unknown result code. - _LIBUNWIND_DEBUG_LOG("personality function returned unknown result %d", - personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - } - frame_count++; - } - - // Clean up phase did not resume at the frame that the search phase - // said it would... - return _URC_FATAL_PHASE2_ERROR; -} - -static _Unwind_Reason_Code -unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor, - _Unwind_Exception *exception_object, _Unwind_Stop_Fn stop, - void *stop_parameter) { - bool endOfStack = false; - // See comment at the start of unwind_phase1 regarding VRS integrity. - __unw_init_local(cursor, uc); - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_force(ex_ojb=%p)", - static_cast(exception_object)); - // Walk each frame until we reach where search phase said to stop - while (!endOfStack) { - // Update info about this frame. - unw_proc_info_t frameInfo; - if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_get_proc_info " - "failed => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR - ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR, - (void *)exception_object, frameInfo.start_ip, functionName, - frameInfo.lsda, frameInfo.handler); - } -#endif - - // Call stop function at each frame. - _Unwind_Action action = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE); - _Unwind_Reason_Code stopResult = - (*stop)(1, action, exception_object->exception_class, exception_object, - (_Unwind_Context *)(cursor), stop_parameter); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): stop function returned %d", - (void *)exception_object, stopResult); - if (stopResult != _URC_NO_REASON) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): stopped by stop function", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - - // If there is a personality routine, tell it we are unwinding. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = - (_Unwind_Personality_Fn)(uintptr_t)(frameInfo.handler); - struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor); - // EHABI #7.2 - exception_object->pr_cache.fnstart = frameInfo.start_ip; - exception_object->pr_cache.ehtp = - (_Unwind_EHT_Header *)frameInfo.unwind_info; - exception_object->pr_cache.additional = frameInfo.flags; - _Unwind_Reason_Code personalityResult = - (*p)(_US_FORCE_UNWIND | _US_UNWIND_FRAME_STARTING, exception_object, - context); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned " - "_URC_CONTINUE_UNWIND", - (void *)exception_object); - // Destructors called, continue unwinding - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned " - "_URC_INSTALL_CONTEXT", - (void *)exception_object); - // We may get control back if landing pad calls _Unwind_Resume(). - __unw_resume(cursor); - break; - case _URC_END_OF_STACK: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned " - "_URC_END_OF_STACK", - (void *)exception_object); - // Personalty routine did the step and it can't step forward. - endOfStack = true; - break; - default: - // Personality routine returned an unknown result code. - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned %d, " - "_URC_FATAL_PHASE2_ERROR", - (void *)exception_object, personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - } - } - - // Call stop function one last time and tell it we've reached the end - // of the stack. - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop " - "function with _UA_END_OF_STACK", - (void *)exception_object); - _Unwind_Action lastAction = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK); - (*stop)(1, lastAction, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(cursor), stop_parameter); - - // Clean up phase did not resume at the frame that the search phase said it - // would. - return _URC_FATAL_PHASE2_ERROR; -} - -/// Called by __cxa_throw. Only returns if there is a fatal error. -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_RaiseException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)", - static_cast(exception_object)); - unw_context_t uc; - unw_cursor_t cursor; - __unw_getcontext(&uc); - - // This field for is for compatibility with GCC to say this isn't a forced - // unwind. EHABI #7.2 - exception_object->unwinder_cache.reserved1 = 0; - - // phase 1: the search phase - _Unwind_Reason_Code phase1 = unwind_phase1(&uc, &cursor, exception_object); - if (phase1 != _URC_NO_REASON) - return phase1; - - // phase 2: the clean up phase - return unwind_phase2(&uc, &cursor, exception_object, false); -} - -_LIBUNWIND_EXPORT void _Unwind_Complete(_Unwind_Exception* exception_object) { - // This is to be called when exception handling completes to give us a chance - // to perform any housekeeping. EHABI #7.2. But we have nothing to do here. - (void)exception_object; -} - -/// When _Unwind_RaiseException() is in phase2, it hands control -/// to the personality function at each frame. The personality -/// may force a jump to a landing pad in that function, the landing -/// pad code may then call _Unwind_Resume() to continue with the -/// unwinding. Note: the call to _Unwind_Resume() is from compiler -/// generated user code. All other _Unwind_* routines are called -/// by the C++ runtime __cxa_* routines. -/// -/// Note: re-throwing an exception (as opposed to continuing the unwind) -/// is implemented by having the code call __cxa_rethrow() which -/// in turn calls _Unwind_Resume_or_Rethrow(). -_LIBUNWIND_EXPORT void -_Unwind_Resume(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)", - static_cast(exception_object)); - unw_context_t uc; - unw_cursor_t cursor; - __unw_getcontext(&uc); - - if (exception_object->unwinder_cache.reserved1) - unwind_phase2_forced( - &uc, &cursor, exception_object, - (_Unwind_Stop_Fn)exception_object->unwinder_cache.reserved1, - (void *)exception_object->unwinder_cache.reserved3); - else - unwind_phase2(&uc, &cursor, exception_object, true); - - // Clients assume _Unwind_Resume() does not return, so all we can do is abort. - _LIBUNWIND_ABORT("_Unwind_Resume() can't return"); -} - -/// Called by personality handler during phase 2 to get LSDA for current frame. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_proc_info_t frameInfo; - uintptr_t result = 0; - if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) - result = (uintptr_t)frameInfo.lsda; - _LIBUNWIND_TRACE_API( - "_Unwind_GetLanguageSpecificData(context=%p) => 0x%llx", - static_cast(context), (long long)result); - return result; -} - -// Only used in _LIBUNWIND_TRACE_API, which is a no-op when assertions are -// disabled. -[[gnu::unused]] static uint64_t -ValueAsBitPattern(_Unwind_VRS_DataRepresentation representation, - const void *valuep) { - uint64_t value = 0; - switch (representation) { - case _UVRSD_UINT32: - case _UVRSD_FLOAT: - memcpy(&value, valuep, sizeof(uint32_t)); - break; - - case _UVRSD_VFPX: - case _UVRSD_UINT64: - case _UVRSD_DOUBLE: - memcpy(&value, valuep, sizeof(uint64_t)); - break; - } - return value; -} - -_LIBUNWIND_EXPORT _Unwind_VRS_Result -_Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, - uint32_t regno, _Unwind_VRS_DataRepresentation representation, - void *valuep, unw_word_t *pos) { - _LIBUNWIND_TRACE_API("_Unwind_VRS_Set(context=%p, regclass=%d, reg=%d, " - "rep=%d, value=0x%llX)", - static_cast(context), regclass, regno, - representation, - ValueAsBitPattern(representation, valuep)); - unw_cursor_t *cursor = (unw_cursor_t *)context; - switch (regclass) { - case _UVRSC_CORE: - if (representation != _UVRSD_UINT32 || regno > 15) - return _UVRSR_FAILED; - return __unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno), - *(unw_word_t *)valuep,(unw_word_t *)pos) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; - case _UVRSC_VFP: - if (representation != _UVRSD_VFPX && representation != _UVRSD_DOUBLE) - return _UVRSR_FAILED; - if (representation == _UVRSD_VFPX) { - // Can only touch d0-15 with FSTMFDX. - if (regno > 15) - return _UVRSR_FAILED; - __unw_save_vfp_as_X(cursor); - } else { - if (regno > 31) - return _UVRSR_FAILED; - } - return __unw_set_fpreg(cursor, (unw_regnum_t)(UNW_ARM_D0 + regno), - *(unw_fpreg_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; -#if defined(__ARM_WMMX) - case _UVRSC_WMMXC: - if (representation != _UVRSD_UINT32 || regno > 3) - return _UVRSR_FAILED; - return __unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_WC0 + regno), - *(unw_word_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; - case _UVRSC_WMMXD: - if (representation != _UVRSD_DOUBLE || regno > 31) - return _UVRSR_FAILED; - return __unw_set_fpreg(cursor, (unw_regnum_t)(UNW_ARM_WR0 + regno), - *(unw_fpreg_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; -#else - case _UVRSC_WMMXC: - case _UVRSC_WMMXD: - break; -#endif - case _UVRSC_PSEUDO: - // There's only one pseudo-register, PAC, with regno == 0. - if (representation != _UVRSD_UINT32 || regno != 0) - return _UVRSR_FAILED; - return __unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_RA_AUTH_CODE), - *(unw_word_t *)valuep, NULL) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; - break; - } - _LIBUNWIND_ABORT("unsupported register class"); -} - -static _Unwind_VRS_Result -_Unwind_VRS_Get_Internal(_Unwind_Context *context, - _Unwind_VRS_RegClass regclass, uint32_t regno, - _Unwind_VRS_DataRepresentation representation, - void *valuep) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - switch (regclass) { - case _UVRSC_CORE: - if (representation != _UVRSD_UINT32 || regno > 15) - return _UVRSR_FAILED; - return __unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno), - (unw_word_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; - case _UVRSC_VFP: - if (representation != _UVRSD_VFPX && representation != _UVRSD_DOUBLE) - return _UVRSR_FAILED; - if (representation == _UVRSD_VFPX) { - // Can only touch d0-15 with FSTMFDX. - if (regno > 15) - return _UVRSR_FAILED; - __unw_save_vfp_as_X(cursor); - } else { - if (regno > 31) - return _UVRSR_FAILED; - } - return __unw_get_fpreg(cursor, (unw_regnum_t)(UNW_ARM_D0 + regno), - (unw_fpreg_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; -#if defined(__ARM_WMMX) - case _UVRSC_WMMXC: - if (representation != _UVRSD_UINT32 || regno > 3) - return _UVRSR_FAILED; - return __unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_WC0 + regno), - (unw_word_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; - case _UVRSC_WMMXD: - if (representation != _UVRSD_DOUBLE || regno > 31) - return _UVRSR_FAILED; - return __unw_get_fpreg(cursor, (unw_regnum_t)(UNW_ARM_WR0 + regno), - (unw_fpreg_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; -#else - case _UVRSC_WMMXC: - case _UVRSC_WMMXD: - break; -#endif - case _UVRSC_PSEUDO: - // There's only one pseudo-register, PAC, with regno == 0. - if (representation != _UVRSD_UINT32 || regno != 0) - return _UVRSR_FAILED; - return __unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_RA_AUTH_CODE), - (unw_word_t *)valuep) == UNW_ESUCCESS - ? _UVRSR_OK - : _UVRSR_FAILED; - break; - } - _LIBUNWIND_ABORT("unsupported register class"); -} - -_LIBUNWIND_EXPORT _Unwind_VRS_Result -_Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, - uint32_t regno, _Unwind_VRS_DataRepresentation representation, - void *valuep) { - _Unwind_VRS_Result result = - _Unwind_VRS_Get_Internal(context, regclass, regno, representation, - valuep); - _LIBUNWIND_TRACE_API("_Unwind_VRS_Get(context=%p, regclass=%d, reg=%d, " - "rep=%d, value=0x%llX, result = %d)", - static_cast(context), regclass, regno, - representation, - ValueAsBitPattern(representation, valuep), result); - return result; -} - -_Unwind_VRS_Result -_Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, - uint32_t discriminator, - _Unwind_VRS_DataRepresentation representation) { - _LIBUNWIND_TRACE_API("_Unwind_VRS_Pop(context=%p, regclass=%d, " - "discriminator=%d, representation=%d)", - static_cast(context), regclass, discriminator, - representation); - switch (regclass) { - case _UVRSC_WMMXC: -#if !defined(__ARM_WMMX) - break; -#endif - case _UVRSC_CORE: { - if (representation != _UVRSD_UINT32) - return _UVRSR_FAILED; - // When popping SP from the stack, we don't want to override it from the - // computed new stack location. See EHABI #7.5.4 table 3. - bool poppedSP = false; - uint32_t* sp; - uint32_t* pos; - if (_Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, - _UVRSD_UINT32, &sp) != _UVRSR_OK) { - return _UVRSR_FAILED; - } - for (uint32_t i = 0; i < 16; ++i) { - if (!(discriminator & static_cast(1 << i))) - continue; - pos = sp; - uint32_t value = *sp++; - if (regclass == _UVRSC_CORE && i == 13) - poppedSP = true; - if (_Unwind_VRS_Set(context, regclass, i, - _UVRSD_UINT32, &value, pos) != _UVRSR_OK) { - return _UVRSR_FAILED; - } - } - if (!poppedSP) { - return _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, - _UVRSD_UINT32, &sp, NULL); - } - return _UVRSR_OK; - } - case _UVRSC_WMMXD: -#if !defined(__ARM_WMMX) - break; -#endif - case _UVRSC_VFP: { - if (representation != _UVRSD_VFPX && representation != _UVRSD_DOUBLE) - return _UVRSR_FAILED; - uint32_t first = discriminator >> 16; - uint32_t count = discriminator & 0xffff; - uint32_t end = first+count; - uint32_t* sp; - if (_Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, - _UVRSD_UINT32, &sp) != _UVRSR_OK) { - return _UVRSR_FAILED; - } - // For _UVRSD_VFPX, we're assuming the data is stored in FSTMX "standard - // format 1", which is equivalent to FSTMD + a padding word. - for (uint32_t i = first; i < end; ++i) { - // SP is only 32-bit aligned so don't copy 64-bit at a time. - uint64_t w0 = *sp++; - uint64_t w1 = *sp++; -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - uint64_t value = (w1 << 32) | w0; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - uint64_t value = (w0 << 32) | w1; -#else -#error "Unable to determine endianess" -#endif - if (_Unwind_VRS_Set(context, regclass, i, representation, &value, NULL) != - _UVRSR_OK) - return _UVRSR_FAILED; - } - if (representation == _UVRSD_VFPX) - ++sp; - return _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, - &sp, NULL); - } - case _UVRSC_PSEUDO: { - if (representation != _UVRSD_UINT32 || discriminator != 0) - return _UVRSR_FAILED; - // Return Address Authentication code (PAC) - discriminator 0 - uint32_t *sp; - if (_Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, - &sp) != _UVRSR_OK) { - return _UVRSR_FAILED; - } - uint32_t pac = *sp++; - _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, &sp, NULL); - return _Unwind_VRS_Set(context, _UVRSC_PSEUDO, 0, _UVRSD_UINT32, &pac, NULL); - } - } - _LIBUNWIND_ABORT("unsupported register class"); -} - -/// Not used by C++. -/// Unwinds stack, calling "stop" function at each frame. -/// Could be used to implement longjmp(). -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_ForcedUnwind(_Unwind_Exception *exception_object, _Unwind_Stop_Fn stop, - void *stop_parameter) { - _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)", - (void *)exception_object, (void *)(uintptr_t)stop); - unw_context_t uc; - unw_cursor_t cursor; - __unw_getcontext(&uc); - - // Mark that this is a forced unwind, so _Unwind_Resume() can do - // the right thing. - exception_object->unwinder_cache.reserved1 = (uintptr_t)stop; - exception_object->unwinder_cache.reserved3 = (uintptr_t)stop_parameter; - - return unwind_phase2_forced(&uc, &cursor, exception_object, stop, - stop_parameter); -} - -/// Called by personality handler during phase 2 to find the start of the -/// function. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetRegionStart(struct _Unwind_Context *context) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_proc_info_t frameInfo; - uintptr_t result = 0; - if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) - result = (uintptr_t)frameInfo.start_ip; - _LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p) => 0x%llX", - static_cast(context), (long long)result); - return result; -} - - -/// Called by personality handler during phase 2 if a foreign exception -// is caught. -_LIBUNWIND_EXPORT void -_Unwind_DeleteException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)", - static_cast(exception_object)); - if (exception_object->exception_cleanup != NULL) - (*exception_object->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT, - exception_object); -} - -extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code -__gnu_unwind_frame(_Unwind_Exception *exception_object, - struct _Unwind_Context *context) { - (void)exception_object; - unw_cursor_t *cursor = (unw_cursor_t *)context; - switch (__unw_step(cursor)) { - case UNW_STEP_SUCCESS: - return _URC_OK; - case UNW_STEP_END: - return _URC_END_OF_STACK; - default: - return _URC_FAILURE; - } -} #endif // defined(_LIBUNWIND_ARM_EHABI) diff --git a/src/native/external/llvm-libunwind/src/Unwind-seh.cpp b/src/native/external/llvm-libunwind/src/Unwind-seh.cpp deleted file mode 100644 index 0b1930b44d1c64..00000000000000 --- a/src/native/external/llvm-libunwind/src/Unwind-seh.cpp +++ /dev/null @@ -1,549 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// Implements SEH-based Itanium C++ exceptions. -// -//===----------------------------------------------------------------------===// - -#include "config.h" - -#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) - -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include "libunwind_ext.h" -#include "UnwindCursor.hpp" - -using namespace libunwind; - -#define STATUS_USER_DEFINED (1u << 29) - -#define STATUS_GCC_MAGIC (('G' << 16) | ('C' << 8) | 'C') - -#define MAKE_CUSTOM_STATUS(s, c) \ - ((NTSTATUS)(((s) << 30) | STATUS_USER_DEFINED | (c))) -#define MAKE_GCC_EXCEPTION(c) \ - MAKE_CUSTOM_STATUS(STATUS_SEVERITY_SUCCESS, STATUS_GCC_MAGIC | ((c) << 24)) - -/// SEH exception raised by libunwind when the program calls -/// \c _Unwind_RaiseException. -#define STATUS_GCC_THROW MAKE_GCC_EXCEPTION(0) // 0x20474343 -/// SEH exception raised by libunwind to initiate phase 2 of exception -/// handling. -#define STATUS_GCC_UNWIND MAKE_GCC_EXCEPTION(1) // 0x21474343 - -static int __unw_init_seh(unw_cursor_t *cursor, CONTEXT *ctx); -static DISPATCHER_CONTEXT *__unw_seh_get_disp_ctx(unw_cursor_t *cursor); -static void __unw_seh_set_disp_ctx(unw_cursor_t *cursor, - DISPATCHER_CONTEXT *disp); - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu-anonymous-struct" -// Local redefinition of this type; mingw-w64 headers lack the -// DISPATCHER_CONTEXT_NONVOLREG_ARM64 type as of May 2025, so locally redefine -// it and use that definition, to avoid needing to test/guess whether the real -// type is available of not. -union LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM64 { - BYTE Buffer[11 * sizeof(DWORD64) + 8 * sizeof(double)]; - - struct { - DWORD64 GpNvRegs[11]; - double FpNvRegs[8]; - }; -}; - -// Custom data type definition; this type is not defined in WinSDK. -union LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM { - BYTE Buffer[8 * sizeof(DWORD) + 8 * sizeof(double)]; - - struct { - DWORD GpNvRegs[8]; - double FpNvRegs[8]; - }; -}; -#pragma clang diagnostic pop - -/// Common implementation of SEH-style handler functions used by Itanium- -/// style frames. Depending on how and why it was called, it may do one of: -/// a) Delegate to the given Itanium-style personality function; or -/// b) Initiate a collided unwind to halt unwinding. -_LIBUNWIND_EXPORT EXCEPTION_DISPOSITION -_GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx, - DISPATCHER_CONTEXT *disp, _Unwind_Personality_Fn pers) { - unw_cursor_t cursor; - _Unwind_Exception *exc; - _Unwind_Action action; - struct _Unwind_Context *ctx = nullptr; - _Unwind_Reason_Code urc; - uintptr_t retval, target; - bool ours = false; - - _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler(%#010lx(%lx), %p)", - ms_exc->ExceptionCode, ms_exc->ExceptionFlags, - (void *)frame); - if (ms_exc->ExceptionCode == STATUS_GCC_UNWIND) { - if (IS_TARGET_UNWIND(ms_exc->ExceptionFlags)) { - // Set up the upper return value (the lower one and the target PC - // were set in the call to RtlUnwindEx()) for the landing pad. -#ifdef __x86_64__ - disp->ContextRecord->Rdx = ms_exc->ExceptionInformation[3]; -#elif defined(__arm__) - disp->ContextRecord->R1 = ms_exc->ExceptionInformation[3]; -#elif defined(__aarch64__) - disp->ContextRecord->X1 = ms_exc->ExceptionInformation[3]; -#endif - } - // This is the collided unwind to the landing pad. Nothing to do. - return ExceptionContinueSearch; - } - - if (ms_exc->ExceptionCode == STATUS_GCC_THROW) { - // This is (probably) a libunwind-controlled exception/unwind. Recover the - // parameters which we set below, and pass them to the personality function. - ours = true; - exc = (_Unwind_Exception *)ms_exc->ExceptionInformation[0]; - if (!IS_UNWINDING(ms_exc->ExceptionFlags) && ms_exc->NumberParameters > 1) { - ctx = (struct _Unwind_Context *)ms_exc->ExceptionInformation[1]; - action = (_Unwind_Action)ms_exc->ExceptionInformation[2]; - } - } else { - // Foreign exception. - // We can't interact with them (we don't know the original target frame - // that we should pass on to RtlUnwindEx in _Unwind_Resume), so just - // pass without calling our destructors here. - return ExceptionContinueSearch; - } - if (!ctx) { - __unw_init_seh(&cursor, disp->ContextRecord); - __unw_seh_set_disp_ctx(&cursor, disp); - __unw_set_reg(&cursor, UNW_REG_IP, disp->ControlPc); - ctx = (struct _Unwind_Context *)&cursor; - - if (!IS_UNWINDING(ms_exc->ExceptionFlags)) { - if (ours && ms_exc->NumberParameters > 1) - action = (_Unwind_Action)(_UA_CLEANUP_PHASE | _UA_FORCE_UNWIND); - else - action = _UA_SEARCH_PHASE; - } else { - if (ours && ms_exc->ExceptionInformation[1] == (ULONG_PTR)frame) - action = (_Unwind_Action)(_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME); - else - action = _UA_CLEANUP_PHASE; - } - } - - _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler() calling personality " - "function %p(1, %d, %llx, %p, %p)", - (void *)pers, action, exc->exception_class, - (void *)exc, (void *)ctx); - urc = pers(1, action, exc->exception_class, exc, ctx); - _LIBUNWIND_TRACE_UNWINDING("_GCC_specific_handler() personality returned %d", urc); - switch (urc) { - case _URC_CONTINUE_UNWIND: - // If we're in phase 2, and the personality routine said to continue - // at the target frame, we're in real trouble. - if (action & _UA_HANDLER_FRAME) - _LIBUNWIND_ABORT("Personality continued unwind at the target frame!"); - return ExceptionContinueSearch; - case _URC_HANDLER_FOUND: - // If we were called by __libunwind_seh_personality(), indicate that - // a handler was found; otherwise, initiate phase 2 by unwinding. - if (ours && ms_exc->NumberParameters > 1) - return static_cast(4); - // This should never happen in phase 2. - if (IS_UNWINDING(ms_exc->ExceptionFlags)) - _LIBUNWIND_ABORT("Personality indicated exception handler in phase 2!"); - exc->private_[1] = (ULONG_PTR)frame; - if (ours) { - ms_exc->NumberParameters = 4; - ms_exc->ExceptionInformation[1] = (ULONG_PTR)frame; - } - // FIXME: Indicate target frame in foreign case! - // phase 2: the clean up phase - RtlUnwindEx(frame, (PVOID)disp->ControlPc, ms_exc, exc, disp->ContextRecord, - disp->HistoryTable); - _LIBUNWIND_ABORT("RtlUnwindEx() failed"); - case _URC_INSTALL_CONTEXT: { - // If we were called by __libunwind_seh_personality(), indicate that - // a handler was found; otherwise, it's time to initiate a collided - // unwind to the target. - if (ours && !IS_UNWINDING(ms_exc->ExceptionFlags) && ms_exc->NumberParameters > 1) - return static_cast(4); - // This should never happen in phase 1. - if (!IS_UNWINDING(ms_exc->ExceptionFlags)) - _LIBUNWIND_ABORT("Personality installed context during phase 1!"); -#ifdef __x86_64__ - exc->private_[2] = disp->TargetIp; - __unw_get_reg(&cursor, UNW_X86_64_RAX, &retval); - __unw_get_reg(&cursor, UNW_X86_64_RDX, &exc->private_[3]); -#elif defined(__arm__) - exc->private_[2] = disp->TargetPc; - __unw_get_reg(&cursor, UNW_ARM_R0, &retval); - __unw_get_reg(&cursor, UNW_ARM_R1, &exc->private_[3]); -#elif defined(__aarch64__) - exc->private_[2] = disp->TargetPc; - __unw_get_reg(&cursor, UNW_AARCH64_X0, &retval); - __unw_get_reg(&cursor, UNW_AARCH64_X1, &exc->private_[3]); -#endif - __unw_get_reg(&cursor, UNW_REG_IP, &target); - ms_exc->ExceptionCode = STATUS_GCC_UNWIND; -#ifdef __x86_64__ - ms_exc->ExceptionInformation[2] = disp->TargetIp; -#elif defined(__arm__) || defined(__aarch64__) - ms_exc->ExceptionInformation[2] = disp->TargetPc; -#endif - ms_exc->ExceptionInformation[3] = exc->private_[3]; - // Give NTRTL some scratch space to keep track of the collided unwind. - // Don't use the one that was passed in; we don't want to overwrite the - // context in the DISPATCHER_CONTEXT. - CONTEXT new_ctx; - RtlUnwindEx(frame, (PVOID)target, ms_exc, (PVOID)retval, &new_ctx, disp->HistoryTable); - _LIBUNWIND_ABORT("RtlUnwindEx() failed"); - } - // Anything else indicates a serious problem. - default: return ExceptionContinueExecution; - } -} - -/// Personality function returned by \c __unw_get_proc_info() in SEH contexts. -/// This is a wrapper that calls the real SEH handler function, which in -/// turn (at least, for Itanium-style frames) calls the real Itanium -/// personality function (see \c _GCC_specific_handler()). -extern "C" _Unwind_Reason_Code -__libunwind_seh_personality(int version, _Unwind_Action state, - uint64_t klass, _Unwind_Exception *exc, - struct _Unwind_Context *context) { - (void)version; - (void)klass; - EXCEPTION_RECORD ms_exc; - bool phase2 = (state & (_UA_SEARCH_PHASE|_UA_CLEANUP_PHASE)) == _UA_CLEANUP_PHASE; - ms_exc.ExceptionCode = STATUS_GCC_THROW; - ms_exc.ExceptionFlags = 0; - ms_exc.NumberParameters = 3; - ms_exc.ExceptionInformation[0] = (ULONG_PTR)exc; - ms_exc.ExceptionInformation[1] = (ULONG_PTR)context; - ms_exc.ExceptionInformation[2] = state; - DISPATCHER_CONTEXT *disp_ctx = - __unw_seh_get_disp_ctx((unw_cursor_t *)context); -#if defined(__aarch64__) - LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM64 nonvol; - memcpy(&nonvol.GpNvRegs, &disp_ctx->ContextRecord->X19, - sizeof(nonvol.GpNvRegs)); - for (int i = 0; i < 8; i++) - nonvol.FpNvRegs[i] = disp_ctx->ContextRecord->V[i + 8].D[0]; - disp_ctx->NonVolatileRegisters = nonvol.Buffer; -#elif defined(__arm__) - LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM nonvol; - memcpy(&nonvol.GpNvRegs, &disp_ctx->ContextRecord->R4, - sizeof(nonvol.GpNvRegs)); - memcpy(&nonvol.FpNvRegs, &disp_ctx->ContextRecord->D[8], - sizeof(nonvol.FpNvRegs)); - disp_ctx->NonVolatileRegisters = nonvol.Buffer; -#endif - _LIBUNWIND_TRACE_UNWINDING("__libunwind_seh_personality() calling " - "LanguageHandler %p(%p, %p, %p, %p)", - (void *)disp_ctx->LanguageHandler, (void *)&ms_exc, - (void *)disp_ctx->EstablisherFrame, - (void *)disp_ctx->ContextRecord, (void *)disp_ctx); - int ms_act = static_cast( - disp_ctx->LanguageHandler(&ms_exc, (PVOID)disp_ctx->EstablisherFrame, - disp_ctx->ContextRecord, disp_ctx)); - _LIBUNWIND_TRACE_UNWINDING("__libunwind_seh_personality() LanguageHandler " - "returned %d", - ms_act); - switch (ms_act) { - case ExceptionContinueExecution: return _URC_END_OF_STACK; - case ExceptionContinueSearch: return _URC_CONTINUE_UNWIND; - case 4 /*ExceptionExecuteHandler*/: - return phase2 ? _URC_INSTALL_CONTEXT : _URC_HANDLER_FOUND; - default: - return phase2 ? _URC_FATAL_PHASE2_ERROR : _URC_FATAL_PHASE1_ERROR; - } -} - -static _Unwind_Reason_Code -unwind_phase2_forced(unw_context_t *uc, - _Unwind_Exception *exception_object, - _Unwind_Stop_Fn stop, void *stop_parameter) { - unw_cursor_t cursor2; - __unw_init_local(&cursor2, uc); - - // Walk each frame until we reach where search phase said to stop - while (__unw_step(&cursor2) > 0) { - - // Update info about this frame. - unw_proc_info_t frameInfo; - if (__unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_get_proc_info " - "failed => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR - ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR, - (void *)exception_object, frameInfo.start_ip, functionName, - frameInfo.lsda, frameInfo.handler); - } -#endif - - // Call stop function at each frame. - _Unwind_Action action = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE); - _Unwind_Reason_Code stopResult = - (*stop)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(&cursor2), stop_parameter); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): stop function returned %d", - (void *)exception_object, stopResult); - if (stopResult != _URC_NO_REASON) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): stopped by stop function", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - - // If there is a personality routine, tell it we are unwinding. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = - (_Unwind_Personality_Fn)(intptr_t)(frameInfo.handler); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_ojb=%p): calling personality function %p", - (void *)exception_object, (void *)(uintptr_t)p); - _Unwind_Reason_Code personalityResult = - (*p)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(&cursor2)); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned " - "_URC_CONTINUE_UNWIND", - (void *)exception_object); - // Destructors called, continue unwinding - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned " - "_URC_INSTALL_CONTEXT", - (void *)exception_object); - // We may get control back if landing pad calls _Unwind_Resume(). - __unw_resume(&cursor2); - break; - case _URC_END_OF_STACK: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned " - "_URC_END_OF_STACK", - (void *)exception_object); - break; - default: - // Personality routine returned an unknown result code. - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned %d, " - "_URC_FATAL_PHASE2_ERROR", - (void *)exception_object, personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - if (personalityResult == _URC_END_OF_STACK) - break; - } - } - - // Call stop function one last time and tell it we've reached the end - // of the stack. - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop " - "function with _UA_END_OF_STACK", - (void *)exception_object); - _Unwind_Action lastAction = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK); - (*stop)(1, lastAction, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(&cursor2), stop_parameter); - - // Clean up phase did not resume at the frame that the search phase said it - // would. - return _URC_FATAL_PHASE2_ERROR; -} - -/// Called by \c __cxa_throw(). Only returns if there is a fatal error. -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_RaiseException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)", - (void *)exception_object); - - // Mark that this is a non-forced unwind, so _Unwind_Resume() - // can do the right thing. - memset(exception_object->private_, 0, sizeof(exception_object->private_)); - - // phase 1: the search phase - // We'll let the system do that for us. - RaiseException(STATUS_GCC_THROW, 0, 1, (ULONG_PTR *)&exception_object); - - // If we get here, either something went horribly wrong or we reached the - // top of the stack. Either way, let libc++abi call std::terminate(). - return _URC_END_OF_STACK; -} - -/// When \c _Unwind_RaiseException() is in phase2, it hands control -/// to the personality function at each frame. The personality -/// may force a jump to a landing pad in that function; the landing -/// pad code may then call \c _Unwind_Resume() to continue with the -/// unwinding. Note: the call to \c _Unwind_Resume() is from compiler -/// generated user code. All other \c _Unwind_* routines are called -/// by the C++ runtime \c __cxa_* routines. -/// -/// Note: re-throwing an exception (as opposed to continuing the unwind) -/// is implemented by having the code call \c __cxa_rethrow() which -/// in turn calls \c _Unwind_Resume_or_Rethrow(). -_LIBUNWIND_EXPORT void -_Unwind_Resume(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)", (void *)exception_object); - - if (exception_object->private_[0] != 0) { - unw_context_t uc; - - __unw_getcontext(&uc); - unwind_phase2_forced(&uc, exception_object, - (_Unwind_Stop_Fn) exception_object->private_[0], - (void *)exception_object->private_[4]); - } else { - // Recover the parameters for the unwind from the exception object - // so we can start unwinding again. - EXCEPTION_RECORD ms_exc; - CONTEXT ms_ctx; - UNWIND_HISTORY_TABLE hist; - - memset(&ms_exc, 0, sizeof(ms_exc)); - memset(&hist, 0, sizeof(hist)); - ms_exc.ExceptionCode = STATUS_GCC_THROW; - ms_exc.ExceptionFlags = EXCEPTION_NONCONTINUABLE; - ms_exc.NumberParameters = 4; - ms_exc.ExceptionInformation[0] = (ULONG_PTR)exception_object; - ms_exc.ExceptionInformation[1] = exception_object->private_[1]; - ms_exc.ExceptionInformation[2] = exception_object->private_[2]; - ms_exc.ExceptionInformation[3] = exception_object->private_[3]; - RtlUnwindEx((PVOID)exception_object->private_[1], - (PVOID)exception_object->private_[2], &ms_exc, - exception_object, &ms_ctx, &hist); - } - - // Clients assume _Unwind_Resume() does not return, so all we can do is abort. - _LIBUNWIND_ABORT("_Unwind_Resume() can't return"); -} - -/// Not used by C++. -/// Unwinds stack, calling "stop" function at each frame. -/// Could be used to implement \c longjmp(). -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_ForcedUnwind(_Unwind_Exception *exception_object, - _Unwind_Stop_Fn stop, void *stop_parameter) { - _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)", - (void *)exception_object, (void *)(uintptr_t)stop); - unw_context_t uc; - __unw_getcontext(&uc); - - // Mark that this is a forced unwind, so _Unwind_Resume() can do - // the right thing. - exception_object->private_[0] = (uintptr_t) stop; - exception_object->private_[4] = (uintptr_t) stop_parameter; - - // do it - return unwind_phase2_forced(&uc, exception_object, stop, stop_parameter); -} - -/// Called by personality handler during phase 2 to get LSDA for current frame. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) { - uintptr_t result = - (uintptr_t)__unw_seh_get_disp_ctx((unw_cursor_t *)context)->HandlerData; - _LIBUNWIND_TRACE_API( - "_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIxPTR, - (void *)context, result); - return result; -} - -/// Called by personality handler during phase 2 to find the start of the -/// function. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetRegionStart(struct _Unwind_Context *context) { - DISPATCHER_CONTEXT *disp = __unw_seh_get_disp_ctx((unw_cursor_t *)context); - uintptr_t result = (uintptr_t)disp->FunctionEntry->BeginAddress + disp->ImageBase; - _LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p) => 0x%" PRIxPTR, - (void *)context, result); - return result; -} - -static int __unw_init_seh(unw_cursor_t *cursor, CONTEXT *context) { -#ifdef _LIBUNWIND_TARGET_X86_64 - new (reinterpret_cast *>(cursor)) - UnwindCursor( - context, LocalAddressSpace::sThisAddressSpace); - auto *co = reinterpret_cast(cursor); - co->setInfoBasedOnIPRegister(); - return UNW_ESUCCESS; -#elif defined(_LIBUNWIND_TARGET_ARM) - new (reinterpret_cast *>(cursor)) - UnwindCursor( - context, LocalAddressSpace::sThisAddressSpace); - auto *co = reinterpret_cast(cursor); - co->setInfoBasedOnIPRegister(); - return UNW_ESUCCESS; -#elif defined(_LIBUNWIND_TARGET_AARCH64) - new (reinterpret_cast *>(cursor)) - UnwindCursor( - context, LocalAddressSpace::sThisAddressSpace); - auto *co = reinterpret_cast(cursor); - co->setInfoBasedOnIPRegister(); - return UNW_ESUCCESS; -#else - return UNW_EINVAL; -#endif -} - -static DISPATCHER_CONTEXT *__unw_seh_get_disp_ctx(unw_cursor_t *cursor) { -#ifdef _LIBUNWIND_TARGET_X86_64 - return reinterpret_cast *>(cursor)->getDispatcherContext(); -#elif defined(_LIBUNWIND_TARGET_ARM) - return reinterpret_cast *>(cursor)->getDispatcherContext(); -#elif defined(_LIBUNWIND_TARGET_AARCH64) - return reinterpret_cast *>(cursor)->getDispatcherContext(); -#else - return nullptr; -#endif -} - -static void __unw_seh_set_disp_ctx(unw_cursor_t *cursor, - DISPATCHER_CONTEXT *disp) { -#ifdef _LIBUNWIND_TARGET_X86_64 - reinterpret_cast *>(cursor)->setDispatcherContext(disp); -#elif defined(_LIBUNWIND_TARGET_ARM) - reinterpret_cast *>(cursor)->setDispatcherContext(disp); -#elif defined(_LIBUNWIND_TARGET_AARCH64) - reinterpret_cast *>(cursor)->setDispatcherContext(disp); -#endif -} - -#endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) diff --git a/src/native/external/llvm-libunwind/src/Unwind-sjlj.c b/src/native/external/llvm-libunwind/src/Unwind-sjlj.c deleted file mode 100644 index a3551b328950d1..00000000000000 --- a/src/native/external/llvm-libunwind/src/Unwind-sjlj.c +++ /dev/null @@ -1,529 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// -// Implements setjump-longjump based C++ exceptions -// -//===----------------------------------------------------------------------===// - -#include - -#include -#include -#include -#include - -#include "config.h" - -/// With SJLJ based exceptions, any function that has a catch clause or needs to -/// do any clean up when an exception propagates through it, needs to call -/// \c _Unwind_SjLj_Register at the start of the function and -/// \c _Unwind_SjLj_Unregister at the end. The register function is called with -/// the address of a block of memory in the function's stack frame. The runtime -/// keeps a linked list (stack) of these blocks - one per thread. The calling -/// function also sets the personality and lsda fields of the block. - -#if defined(_LIBUNWIND_BUILD_SJLJ_APIS) - -struct _Unwind_FunctionContext { - // next function in stack of handlers - struct _Unwind_FunctionContext *prev; - -#if defined(__ve__) - // VE requires to store 64 bit pointers in the buffer for SjLj exception. - // We expand the size of values defined here. This size must be matched - // to the size returned by TargetMachine::getSjLjDataSize(). - - // set by calling function before registering to be the landing pad - uint64_t resumeLocation; - - // set by personality handler to be parameters passed to landing pad function - uint64_t resumeParameters[4]; -#else - // set by calling function before registering to be the landing pad - uint32_t resumeLocation; - - // set by personality handler to be parameters passed to landing pad function - uint32_t resumeParameters[4]; -#endif - - // set by calling function before registering - _Unwind_Personality_Fn personality; // arm offset=24 - uintptr_t lsda; // arm offset=28 - - // variable length array, contains registers to restore - // 0 = r7, 1 = pc, 2 = sp - void *jbuf[]; -}; - -#if defined(_LIBUNWIND_HAS_NO_THREADS) -# define _LIBUNWIND_THREAD_LOCAL -#else -# if __STDC_VERSION__ >= 201112L -# define _LIBUNWIND_THREAD_LOCAL _Thread_local -# elif defined(_MSC_VER) -# define _LIBUNWIND_THREAD_LOCAL __declspec(thread) -# elif defined(__GNUC__) || defined(__clang__) -# define _LIBUNWIND_THREAD_LOCAL __thread -# else -# error Unable to create thread local storage -# endif -#endif - - -#if !defined(FOR_DYLD) - -#if defined(__APPLE__) -#include -#else -static _LIBUNWIND_THREAD_LOCAL struct _Unwind_FunctionContext *stack = NULL; -#endif - -static struct _Unwind_FunctionContext * -__Unwind_SjLj_GetTopOfFunctionStack(void) { -#if defined(__APPLE__) - return _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key); -#else - return stack; -#endif -} - -static void -__Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) { -#if defined(__APPLE__) - _pthread_setspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key, fc); -#else - stack = fc; -#endif -} - -#endif - - -/// Called at start of each function that catches exceptions -_LIBUNWIND_EXPORT void -_Unwind_SjLj_Register(struct _Unwind_FunctionContext *fc) { - fc->prev = __Unwind_SjLj_GetTopOfFunctionStack(); - __Unwind_SjLj_SetTopOfFunctionStack(fc); -} - - -/// Called at end of each function that catches exceptions -_LIBUNWIND_EXPORT void -_Unwind_SjLj_Unregister(struct _Unwind_FunctionContext *fc) { - __Unwind_SjLj_SetTopOfFunctionStack(fc->prev); -} - - -static _Unwind_Reason_Code -unwind_phase1(struct _Unwind_Exception *exception_object) { - _Unwind_FunctionContext_t c = __Unwind_SjLj_GetTopOfFunctionStack(); - _LIBUNWIND_TRACE_UNWINDING("unwind_phase1: initial function-context=%p", - (void *)c); - - // walk each frame looking for a place to stop - for (bool handlerNotFound = true; handlerNotFound; c = c->prev) { - - // check for no more frames - if (c == NULL) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): reached " - "bottom => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_END_OF_STACK; - } - - _LIBUNWIND_TRACE_UNWINDING("unwind_phase1: function-context=%p", (void *)c); - // if there is a personality routine, ask it if it will want to stop at this - // frame - if (c->personality != NULL) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): calling " - "personality function %p", - (void *)exception_object, - (void *)c->personality); - _Unwind_Reason_Code personalityResult = (*c->personality)( - 1, _UA_SEARCH_PHASE, exception_object->exception_class, - exception_object, (struct _Unwind_Context *)c); - switch (personalityResult) { - case _URC_HANDLER_FOUND: - // found a catch clause or locals that need destructing in this frame - // stop search and remember function context - handlerNotFound = false; - exception_object->private_2 = (uintptr_t) c; - _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): " - "_URC_HANDLER_FOUND", - (void *)exception_object); - return _URC_NO_REASON; - - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): " - "_URC_CONTINUE_UNWIND", - (void *)exception_object); - // continue unwinding - break; - - default: - // something went wrong - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_ojb=%p): _URC_FATAL_PHASE1_ERROR", - (void *)exception_object); - return _URC_FATAL_PHASE1_ERROR; - } - } - } - return _URC_NO_REASON; -} - - -static _Unwind_Reason_Code -unwind_phase2(struct _Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)", - (void *)exception_object); - - // walk each frame until we reach where search phase said to stop - _Unwind_FunctionContext_t c = __Unwind_SjLj_GetTopOfFunctionStack(); - while (true) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2s(ex_ojb=%p): context=%p", - (void *)exception_object, (void *)c); - - // check for no more frames - if (c == NULL) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): __unw_step() reached " - "bottom => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_END_OF_STACK; - } - - // if there is a personality routine, tell it we are unwinding - if (c->personality != NULL) { - _Unwind_Action action = _UA_CLEANUP_PHASE; - if ((uintptr_t) c == exception_object->private_2) - action = (_Unwind_Action)( - _UA_CLEANUP_PHASE | - _UA_HANDLER_FRAME); // tell personality this was the frame it marked - // in phase 1 - _Unwind_Reason_Code personalityResult = - (*c->personality)(1, action, exception_object->exception_class, - exception_object, (struct _Unwind_Context *)c); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - // continue unwinding - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND", - (void *)exception_object); - if ((uintptr_t) c == exception_object->private_2) { - // phase 1 said we would stop at this frame, but we did not... - _LIBUNWIND_ABORT("during phase1 personality function said it would " - "stop here, but now if phase2 it did not stop here"); - } - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): " - "_URC_INSTALL_CONTEXT, will resume at " - "landing pad %p", - (void *)exception_object, c->jbuf[1]); - // personality routine says to transfer control to landing pad - // we may get control back if landing pad calls _Unwind_Resume() - __Unwind_SjLj_SetTopOfFunctionStack(c); - __builtin_longjmp(c->jbuf, 1); - // __unw_resume() only returns if there was an error - return _URC_FATAL_PHASE2_ERROR; - default: - // something went wrong - _LIBUNWIND_DEBUG_LOG("personality function returned unknown result %d", - personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - } - c = c->prev; - } - - // clean up phase did not resume at the frame that the search phase said it - // would - return _URC_FATAL_PHASE2_ERROR; -} - - -static _Unwind_Reason_Code -unwind_phase2_forced(struct _Unwind_Exception *exception_object, - _Unwind_Stop_Fn stop, void *stop_parameter) { - // walk each frame until we reach where search phase said to stop - _Unwind_FunctionContext_t c = __Unwind_SjLj_GetTopOfFunctionStack(); - while (true) { - - // get next frame (skip over first which is _Unwind_RaiseException) - if (c == NULL) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_ojb=%p): __unw_step() reached " - "bottom => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_END_OF_STACK; - } - - // call stop function at each frame - _Unwind_Action action = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE); - _Unwind_Reason_Code stopResult = - (*stop)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)c, stop_parameter); - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "stop function returned %d", - (void *)exception_object, stopResult); - if (stopResult != _URC_NO_REASON) { - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "stopped by stop function", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - - // if there is a personality routine, tell it we are unwinding - if (c->personality != NULL) { - _Unwind_Personality_Fn p = (_Unwind_Personality_Fn)c->personality; - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "calling personality function %p", - (void *)exception_object, (void *)p); - _Unwind_Reason_Code personalityResult = - (*p)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)c); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned _URC_CONTINUE_UNWIND", - (void *)exception_object); - // destructors called, continue unwinding - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned _URC_INSTALL_CONTEXT", - (void *)exception_object); - // we may get control back if landing pad calls _Unwind_Resume() - __Unwind_SjLj_SetTopOfFunctionStack(c); - __builtin_longjmp(c->jbuf, 1); - break; - default: - // something went wrong - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " - "personality returned %d, " - "_URC_FATAL_PHASE2_ERROR", - (void *)exception_object, personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - } - c = c->prev; - } - - // call stop function one last time and tell it we've reached the end of the - // stack - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop " - "function with _UA_END_OF_STACK", - (void *)exception_object); - _Unwind_Action lastAction = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK); - (*stop)(1, lastAction, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)c, stop_parameter); - - // clean up phase did not resume at the frame that the search phase said it - // would - return _URC_FATAL_PHASE2_ERROR; -} - - -/// Called by __cxa_throw. Only returns if there is a fatal error -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_SjLj_RaiseException(struct _Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_SjLj_RaiseException(ex_obj=%p)", - (void *)exception_object); - - // mark that this is a non-forced unwind, so _Unwind_Resume() can do the right - // thing - exception_object->private_1 = 0; - exception_object->private_2 = 0; - - // phase 1: the search phase - _Unwind_Reason_Code phase1 = unwind_phase1(exception_object); - if (phase1 != _URC_NO_REASON) - return phase1; - - // phase 2: the clean up phase - return unwind_phase2(exception_object); -} - - - -/// When _Unwind_RaiseException() is in phase2, it hands control -/// to the personality function at each frame. The personality -/// may force a jump to a landing pad in that function, the landing -/// pad code may then call _Unwind_Resume() to continue with the -/// unwinding. Note: the call to _Unwind_Resume() is from compiler -/// generated user code. All other _Unwind_* routines are called -/// by the C++ runtime __cxa_* routines. -/// -/// Re-throwing an exception is implemented by having the code call -/// __cxa_rethrow() which in turn calls _Unwind_Resume_or_Rethrow() -_LIBUNWIND_EXPORT void -_Unwind_SjLj_Resume(struct _Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_SjLj_Resume(ex_obj=%p)", - (void *)exception_object); - - if (exception_object->private_1 != 0) - unwind_phase2_forced(exception_object, - (_Unwind_Stop_Fn) exception_object->private_1, - (void *)exception_object->private_2); - else - unwind_phase2(exception_object); - - // clients assume _Unwind_Resume() does not return, so all we can do is abort. - _LIBUNWIND_ABORT("_Unwind_SjLj_Resume() can't return"); -} - - -/// Called by __cxa_rethrow(). -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("__Unwind_SjLj_Resume_or_Rethrow(ex_obj=%p), " - "private_1=%" PRIuPTR, - (void *)exception_object, exception_object->private_1); - // If this is non-forced and a stopping place was found, then this is a - // re-throw. - // Call _Unwind_RaiseException() as if this was a new exception. - if (exception_object->private_1 == 0) { - return _Unwind_SjLj_RaiseException(exception_object); - // should return if there is no catch clause, so that __cxa_rethrow can call - // std::terminate() - } - - // Call through to _Unwind_Resume() which distinguishes between forced and - // regular exceptions. - _Unwind_SjLj_Resume(exception_object); - _LIBUNWIND_ABORT("__Unwind_SjLj_Resume_or_Rethrow() called " - "_Unwind_SjLj_Resume() which unexpectedly returned"); -} - - -/// Called by personality handler during phase 2 to get LSDA for current frame. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) { - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - _LIBUNWIND_TRACE_API("_Unwind_GetLanguageSpecificData(context=%p) " - "=> 0x%" PRIxPTR, - (void *)context, ufc->lsda); - return ufc->lsda; -} - - -/// Called by personality handler during phase 2 to get register values. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, - int index) { - _LIBUNWIND_TRACE_API("_Unwind_GetGR(context=%p, reg=%d)", (void *)context, - index); - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - return ufc->resumeParameters[index]; -} - - -/// Called by personality handler during phase 2 to alter register values. -_LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index, - uintptr_t new_value) { - _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%" PRIxPTR - ")", - (void *)context, index, new_value); - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - ufc->resumeParameters[index] = new_value; -} - - -/// Called by personality handler during phase 2 to get instruction pointer. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) { - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => 0x%" PRIxPTR, - (void *)context, ufc->resumeLocation + 1); - return ufc->resumeLocation + 1; -} - - -/// Called by personality handler during phase 2 to get instruction pointer. -/// ipBefore is a boolean that says if IP is already adjusted to be the call -/// site address. Normally IP is the return address. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context, - int *ipBefore) { - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - *ipBefore = 0; - _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p, %p) => 0x%" PRIxPTR, - (void *)context, (void *)ipBefore, - ufc->resumeLocation + 1); - return ufc->resumeLocation + 1; -} - - -/// Called by personality handler during phase 2 to alter instruction pointer. -_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context, - uintptr_t new_value) { - _LIBUNWIND_TRACE_API("_Unwind_SetIP(context=%p, value=0x%" PRIxPTR ")", - (void *)context, new_value); - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - ufc->resumeLocation = new_value - 1; -} - - -/// Called by personality handler during phase 2 to find the start of the -/// function. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetRegionStart(struct _Unwind_Context *context) { - // Not supported or needed for sjlj based unwinding - (void)context; - _LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p)", (void *)context); - return 0; -} - - -/// Called by personality handler during phase 2 if a foreign exception -/// is caught. -_LIBUNWIND_EXPORT void -_Unwind_DeleteException(struct _Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)", - (void *)exception_object); - if (exception_object->exception_cleanup != NULL) - (*exception_object->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT, - exception_object); -} - - - -/// Called by personality handler during phase 2 to get base address for data -/// relative encodings. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetDataRelBase(struct _Unwind_Context *context) { - // Not supported or needed for sjlj based unwinding - (void)context; - _LIBUNWIND_TRACE_API("_Unwind_GetDataRelBase(context=%p)", (void *)context); - _LIBUNWIND_ABORT("_Unwind_GetDataRelBase() not implemented"); -} - - -/// Called by personality handler during phase 2 to get base address for text -/// relative encodings. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetTextRelBase(struct _Unwind_Context *context) { - // Not supported or needed for sjlj based unwinding - (void)context; - _LIBUNWIND_TRACE_API("_Unwind_GetTextRelBase(context=%p)", (void *)context); - _LIBUNWIND_ABORT("_Unwind_GetTextRelBase() not implemented"); -} - - -/// Called by personality handler to get "Call Frame Area" for current frame. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetCFA(struct _Unwind_Context *context) { - _LIBUNWIND_TRACE_API("_Unwind_GetCFA(context=%p)", (void *)context); - if (context != NULL) { - _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context; - // Setjmp/longjmp based exceptions don't have a true CFA. - // Instead, the SP in the jmpbuf is the closest approximation. - return (uintptr_t) ufc->jbuf[2]; - } - return 0; -} - -#endif // defined(_LIBUNWIND_BUILD_SJLJ_APIS) diff --git a/src/native/external/llvm-libunwind/src/Unwind-wasm.c b/src/native/external/llvm-libunwind/src/Unwind-wasm.c deleted file mode 100644 index b0d6cd2d00fc59..00000000000000 --- a/src/native/external/llvm-libunwind/src/Unwind-wasm.c +++ /dev/null @@ -1,121 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// -// Implements Wasm exception handling proposal -// (https://github.com/WebAssembly/exception-handling) based C++ exceptions -// -//===----------------------------------------------------------------------===// - -#include - -#include "config.h" - -#ifdef __WASM_EXCEPTIONS__ - -#include "unwind.h" -#include - -_Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action actions, - uint64_t exceptionClass, - _Unwind_Exception *unwind_exception, - _Unwind_Context *context); - -struct _Unwind_LandingPadContext { - // Input information to personality function - uintptr_t lpad_index; // landing pad index - uintptr_t lsda; // LSDA address - - // Output information computed by personality function - uintptr_t selector; // selector value -}; - -// Communication channel between compiler-generated user code and personality -// function -thread_local struct _Unwind_LandingPadContext __wasm_lpad_context; - -/// Calls to this function are in landing pads in compiler-generated user code. -/// In other EH schemes, stack unwinding is done by libunwind library, which -/// calls the personality function for each frame it lands. On the other hand, -/// WebAssembly stack unwinding process is performed by a VM, and the -/// personality function cannot be called from there. So the compiler inserts a -/// call to this function in landing pads in the user code, which in turn calls -/// the personality function. -_Unwind_Reason_Code _Unwind_CallPersonality(void *exception_ptr) { - struct _Unwind_Exception *exception_object = - (struct _Unwind_Exception *)exception_ptr; - _LIBUNWIND_TRACE_API("_Unwind_CallPersonality(exception_object=%p)", - (void *)exception_object); - - // Reset the selector. - __wasm_lpad_context.selector = 0; - - // Call personality function. Wasm does not have two-phase unwinding, so we - // only do the cleanup phase. - return __gxx_personality_wasm0( - 1, _UA_SEARCH_PHASE, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)&__wasm_lpad_context); -} - -/// Called by __cxa_throw. -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_RaiseException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_RaiseException(exception_object=%p)", - (void *)exception_object); - // Use Wasm EH's 'throw' instruction. - __builtin_wasm_throw(0, exception_object); -} - -/// Called by __cxa_end_catch. -_LIBUNWIND_EXPORT void -_Unwind_DeleteException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)", - (void *)(exception_object)); - if (exception_object->exception_cleanup != NULL) - (*exception_object->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT, - exception_object); -} - -/// Called by personality handler to alter register values. -_LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index, - uintptr_t value) { - _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, index=%d, value=%lu)", - (void *)context, index, value); - // We only use this function to set __wasm_lpad_context.selector field, which - // is index 1 in the personality function. - if (index == 1) - ((struct _Unwind_LandingPadContext *)context)->selector = value; -} - -/// Called by personality handler to get instruction pointer. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) { - // The result will be used as a 1-based index after decrementing 1, so we - // increment 2 here - uintptr_t result = - ((struct _Unwind_LandingPadContext *)context)->lpad_index + 2; - _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => %lu", (void *)context, - result); - return result; -} - -/// Not used in Wasm. -_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {} - -/// Called by personality handler to get LSDA for current frame. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) { - uintptr_t result = ((struct _Unwind_LandingPadContext *)context)->lsda; - _LIBUNWIND_TRACE_API("_Unwind_GetLanguageSpecificData(context=%p) => 0x%lx", - (void *)context, result); - return result; -} - -/// Not used in Wasm. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *) { - return 0; -} - -#endif // defined(__WASM_EXCEPTIONS__) diff --git a/src/native/external/llvm-libunwind/src/UnwindLevel1-gcc-ext.c b/src/native/external/llvm-libunwind/src/UnwindLevel1-gcc-ext.c deleted file mode 100644 index 32c872ffade1fd..00000000000000 --- a/src/native/external/llvm-libunwind/src/UnwindLevel1-gcc-ext.c +++ /dev/null @@ -1,351 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// -// Implements gcc extensions to the C++ ABI Exception Handling Level 1. -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "libunwind_ext.h" -#include "libunwind.h" -#include "Unwind-EHABI.h" -#include "unwind.h" - -#if defined(_AIX) -#include -#endif - -#if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) - -#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) -#define PRIVATE_1 private_[0] -#elif defined(_LIBUNWIND_ARM_EHABI) -#define PRIVATE_1 unwinder_cache.reserved1 -#else -#define PRIVATE_1 private_1 -#endif - -/// Called by __cxa_rethrow(). -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API( - "_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR, - (void *)exception_object, (intptr_t)exception_object->PRIVATE_1); - - // If this is non-forced and a stopping place was found, then this is a - // re-throw. - // Call _Unwind_RaiseException() as if this was a new exception - if (exception_object->PRIVATE_1 == 0) { - return _Unwind_RaiseException(exception_object); - // Will return if there is no catch clause, so that __cxa_rethrow can call - // std::terminate(). - } - - // Call through to _Unwind_Resume() which distinguishes between forced and - // regular exceptions. - _Unwind_Resume(exception_object); - _LIBUNWIND_ABORT("_Unwind_Resume_or_Rethrow() called _Unwind_RaiseException()" - " which unexpectedly returned"); -} - -/// Called by personality handler during phase 2 to get base address for data -/// relative encodings. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetDataRelBase(struct _Unwind_Context *context) { - _LIBUNWIND_TRACE_API("_Unwind_GetDataRelBase(context=%p)", (void *)context); -#if defined(_AIX) - return unw_get_data_rel_base((unw_cursor_t *)context); -#else - (void)context; - _LIBUNWIND_ABORT("_Unwind_GetDataRelBase() not implemented"); -#endif -} - -/// Called by personality handler during phase 2 to get base address for text -/// relative encodings. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetTextRelBase(struct _Unwind_Context *context) { - (void)context; - _LIBUNWIND_TRACE_API("_Unwind_GetTextRelBase(context=%p)", (void *)context); - _LIBUNWIND_ABORT("_Unwind_GetTextRelBase() not implemented"); -} - - -/// Scans unwind information to find the function that contains the -/// specified code address "pc". -_LIBUNWIND_EXPORT void *_Unwind_FindEnclosingFunction(void *pc) { - _LIBUNWIND_TRACE_API("_Unwind_FindEnclosingFunction(pc=%p)", pc); -#if defined(_AIX) - if (pc == NULL) - return NULL; - - // Get the start address of the enclosing function from the function's - // traceback table. - uint32_t *p = (uint32_t *)pc; - - // Keep looking forward until a word of 0 is found. The traceback - // table starts at the following word. - while (*p) - ++p; - struct tbtable *TBTable = (struct tbtable *)(p + 1); - - // Get the address of the traceback table extension. - p = (uint32_t *)&TBTable->tb_ext; - - // Skip field parminfo if it exists. - if (TBTable->tb.fixedparms || TBTable->tb.floatparms) - ++p; - - if (TBTable->tb.has_tboff) - // *p contains the offset from the function start to traceback table. - return (void *)((uintptr_t)TBTable - *p - sizeof(uint32_t)); - return NULL; -#else - // This is slow, but works. - // We create an unwind cursor then alter the IP to be pc - unw_cursor_t cursor; - unw_context_t uc; - unw_proc_info_t info; - __unw_getcontext(&uc); - __unw_init_local(&cursor, &uc); - __unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t)pc); - if (__unw_get_proc_info(&cursor, &info) == UNW_ESUCCESS) - return (void *)(intptr_t) info.start_ip; - else - return NULL; -#endif -} - -/// Walk every frame and call trace function at each one. If trace function -/// returns anything other than _URC_NO_REASON, then walk is terminated. -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) { - unw_cursor_t cursor; - unw_context_t uc; - __unw_getcontext(&uc); - __unw_init_local(&cursor, &uc); - - _LIBUNWIND_TRACE_API("_Unwind_Backtrace(callback=%p)", - (void *)(uintptr_t)callback); - -#if defined(_LIBUNWIND_ARM_EHABI) - // Create a mock exception object for force unwinding. - _Unwind_Exception ex; - memset(&ex, '\0', sizeof(ex)); - memcpy(&ex.exception_class, "CLNGUNW", sizeof(ex.exception_class)); -#endif - - // walk each frame - while (true) { - _Unwind_Reason_Code result; - -#if !defined(_LIBUNWIND_ARM_EHABI) - // ask libunwind to get next frame (skip over first frame which is - // _Unwind_Backtrace()) - if (__unw_step(&cursor) <= 0) { - _LIBUNWIND_TRACE_UNWINDING(" _backtrace: ended because cursor reached " - "bottom of stack, returning %d", - _URC_END_OF_STACK); - return _URC_END_OF_STACK; - } -#else - // Get the information for this frame. - unw_proc_info_t frameInfo; - if (__unw_get_proc_info(&cursor, &frameInfo) != UNW_ESUCCESS) { - return _URC_END_OF_STACK; - } - - // Update the pr_cache in the mock exception object. - uint32_t *unwindInfo = (uint32_t *)frameInfo.unwind_info; - ex.pr_cache.fnstart = frameInfo.start_ip; - ex.pr_cache.ehtp = (_Unwind_EHT_Header *) unwindInfo; - ex.pr_cache.additional= frameInfo.flags; - - struct _Unwind_Context *context = (struct _Unwind_Context *)&cursor; - // Get and call the personality function to unwind the frame. - _Unwind_Personality_Fn handler = (_Unwind_Personality_Fn)frameInfo.handler; - if (handler == NULL) { - return _URC_END_OF_STACK; - } - if (handler(_US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND, &ex, context) != - _URC_CONTINUE_UNWIND) { - return _URC_END_OF_STACK; - } -#endif // defined(_LIBUNWIND_ARM_EHABI) - - // debugging - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionName[512]; - unw_proc_info_t frame; - unw_word_t offset; - __unw_get_proc_name(&cursor, functionName, 512, &offset); - __unw_get_proc_info(&cursor, &frame); - _LIBUNWIND_TRACE_UNWINDING( - " _backtrace: start_ip=0x%" PRIxPTR ", func=%s, lsda=0x%" PRIxPTR ", context=%p", - frame.start_ip, functionName, frame.lsda, - (void *)&cursor); - } - - // call trace function with this frame - result = (*callback)((struct _Unwind_Context *)(&cursor), ref); - if (result != _URC_NO_REASON) { - _LIBUNWIND_TRACE_UNWINDING( - " _backtrace: ended because callback returned %d", result); - return result; - } - } -} - - -/// Find DWARF unwind info for an address 'pc' in some function. -_LIBUNWIND_EXPORT const void *_Unwind_Find_FDE(const void *pc, - struct dwarf_eh_bases *bases) { - // This is slow, but works. - // We create an unwind cursor then alter the IP to be pc - unw_cursor_t cursor; - unw_context_t uc; - unw_proc_info_t info; - __unw_getcontext(&uc); - __unw_init_local(&cursor, &uc); - __unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(intptr_t)pc); - __unw_get_proc_info(&cursor, &info); - bases->tbase = (uintptr_t)info.extra; - bases->dbase = 0; // dbase not used on Mac OS X - bases->func = (uintptr_t)info.start_ip; - _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc, - (void *)(intptr_t) info.unwind_info); - return (void *)(intptr_t) info.unwind_info; -} - -/// Returns the CFA (call frame area, or stack pointer at start of function) -/// for the current context. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetCFA(struct _Unwind_Context *context) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_word_t result; - __unw_get_reg(cursor, UNW_REG_SP, &result); - _LIBUNWIND_TRACE_API("_Unwind_GetCFA(context=%p) => 0x%" PRIxPTR, - (void *)context, result); - return (uintptr_t)result; -} - - -/// Called by personality handler during phase 2 to get instruction pointer. -/// ipBefore is a boolean that says if IP is already adjusted to be the call -/// site address. Normally IP is the return address. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context, - int *ipBefore) { - _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p)", (void *)context); - int isSignalFrame = __unw_is_signal_frame((unw_cursor_t *)context); - // Negative means some kind of error (probably UNW_ENOINFO), but we have no - // good way to report that, and this maintains backward compatibility with the - // implementation that hard-coded zero in every case, even signal frames. - if (isSignalFrame <= 0) - *ipBefore = 0; - else - *ipBefore = 1; - return _Unwind_GetIP(context); -} - -#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) - -/// Called by programs with dynamic code generators that want -/// to register a dynamically generated FDE. -/// This function has existed on Mac OS X since 10.4, but -/// was broken until 10.6. -_LIBUNWIND_EXPORT void __register_frame(const void *fde) { - _LIBUNWIND_TRACE_API("__register_frame(%p)", fde); - __unw_add_dynamic_fde((unw_word_t)(uintptr_t)fde); -} - - -/// Called by programs with dynamic code generators that want -/// to unregister a dynamically generated FDE. -/// This function has existed on Mac OS X since 10.4, but -/// was broken until 10.6. -_LIBUNWIND_EXPORT void __deregister_frame(const void *fde) { - _LIBUNWIND_TRACE_API("__deregister_frame(%p)", fde); - __unw_remove_dynamic_fde((unw_word_t)(uintptr_t)fde); -} - - -// The following register/deregister functions are gcc extensions. -// They have existed on Mac OS X, but have never worked because Mac OS X -// before 10.6 used keymgr to track known FDEs, but these functions -// never got updated to use keymgr. -// For now, we implement these as do-nothing functions to keep any existing -// applications working. We also add the not in 10.6 symbol so that nwe -// application won't be able to use them. - -#if defined(_LIBUNWIND_SUPPORT_FRAME_APIS) -_LIBUNWIND_EXPORT void __register_frame_info_bases(const void *fde, void *ob, - void *tb, void *db) { - (void)fde; - (void)ob; - (void)tb; - (void)db; - _LIBUNWIND_TRACE_API("__register_frame_info_bases(%p,%p, %p, %p)", - fde, ob, tb, db); - // do nothing, this function never worked in Mac OS X -} - -_LIBUNWIND_EXPORT void __register_frame_info(const void *fde, void *ob) { - (void)fde; - (void)ob; - _LIBUNWIND_TRACE_API("__register_frame_info(%p, %p)", fde, ob); - // do nothing, this function never worked in Mac OS X -} - -_LIBUNWIND_EXPORT void __register_frame_info_table_bases(const void *fde, - void *ob, void *tb, - void *db) { - (void)fde; - (void)ob; - (void)tb; - (void)db; - _LIBUNWIND_TRACE_API("__register_frame_info_table_bases" - "(%p,%p, %p, %p)", fde, ob, tb, db); - // do nothing, this function never worked in Mac OS X -} - -_LIBUNWIND_EXPORT void __register_frame_info_table(const void *fde, void *ob) { - (void)fde; - (void)ob; - _LIBUNWIND_TRACE_API("__register_frame_info_table(%p, %p)", fde, ob); - // do nothing, this function never worked in Mac OS X -} - -_LIBUNWIND_EXPORT void __register_frame_table(const void *fde) { - (void)fde; - _LIBUNWIND_TRACE_API("__register_frame_table(%p)", fde); - // do nothing, this function never worked in Mac OS X -} - -_LIBUNWIND_EXPORT void *__deregister_frame_info(const void *fde) { - (void)fde; - _LIBUNWIND_TRACE_API("__deregister_frame_info(%p)", fde); - // do nothing, this function never worked in Mac OS X - return NULL; -} - -_LIBUNWIND_EXPORT void *__deregister_frame_info_bases(const void *fde) { - (void)fde; - _LIBUNWIND_TRACE_API("__deregister_frame_info_bases(%p)", fde); - // do nothing, this function never worked in Mac OS X - return NULL; -} -#endif // defined(_LIBUNWIND_SUPPORT_FRAME_APIS) - -#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) - -#endif // defined(_LIBUNWIND_BUILD_ZERO_COST_APIS) diff --git a/src/native/external/llvm-libunwind/src/UnwindLevel1.c b/src/native/external/llvm-libunwind/src/UnwindLevel1.c deleted file mode 100644 index 7368b3cb803362..00000000000000 --- a/src/native/external/llvm-libunwind/src/UnwindLevel1.c +++ /dev/null @@ -1,645 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// -// Implements C++ ABI Exception Handling Level 1 as documented at: -// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html -// using libunwind -// -//===----------------------------------------------------------------------===// - -// ARM EHABI does not specify _Unwind_{Get,Set}{GR,IP}(). Thus, we are -// defining inline functions to delegate the function calls to -// _Unwind_VRS_{Get,Set}(). However, some applications might declare the -// function protetype directly (instead of including ), thus we need -// to export these functions from libunwind.so as well. -#define _LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE 1 - -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "libunwind.h" -#include "libunwind_ext.h" -#include "shadow_stack_unwind.h" -#include "unwind.h" - -#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ - !defined(__wasm__) - -#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND - -// When shadow stack is enabled, a separate stack containing only return -// addresses would be maintained. On function return, the return address would -// be compared to the popped address from shadow stack to ensure the return -// target is not tempered with. When unwinding, we're skipping the normal return -// procedure for multiple frames and thus need to pop the return addresses of -// the skipped frames from shadow stack to avoid triggering an exception (using -// `_LIBUNWIND_POP_SHSTK_SSP()`). Also, some architectures, like the x86-family -// CET, push the return adddresses onto shadow stack with common call -// instructions, so for these architectures, normal function calls should be -// avoided when invoking the `jumpto()` function. To do this, we use inline -// assemblies to "goto" the `jumpto()` for these architectures. -#if !defined(_LIBUNWIND_USE_CET) && !defined(_LIBUNWIND_USE_GCS) -#define __unw_phase2_resume(cursor, payload) \ - do { \ - __unw_resume_with_frames_walked((cursor), (payload)); \ - } while (0) -#elif defined(_LIBUNWIND_TARGET_I386) -#define __shstk_step_size (4) -#define __unw_phase2_resume(cursor, payload) \ - do { \ - _LIBUNWIND_POP_SHSTK_SSP((payload)); \ - void *shstkRegContext = __libunwind_shstk_get_registers((cursor)); \ - void *shstkJumpAddress = __libunwind_shstk_get_jump_target(); \ - __asm__ volatile("push %%edi\n\t" \ - "sub $4, %%esp\n\t" \ - "jmp *%%edx\n\t" ::"D"(shstkRegContext), \ - "d"(shstkJumpAddress)); \ - } while (0) -#elif defined(_LIBUNWIND_TARGET_X86_64) -#define __shstk_step_size (8) -#define __unw_phase2_resume(cursor, payload) \ - do { \ - _LIBUNWIND_POP_SHSTK_SSP((payload)); \ - void *shstkRegContext = __libunwind_shstk_get_registers((cursor)); \ - void *shstkJumpAddress = __libunwind_shstk_get_jump_target(); \ - __asm__ volatile("jmpq *%%rdx\n\t" ::"D"(shstkRegContext), \ - "d"(shstkJumpAddress)); \ - } while (0) -#elif defined(_LIBUNWIND_TARGET_AARCH64) -#define __shstk_step_size (8) -#define __unw_phase2_resume(cursor, payload) \ - do { \ - _LIBUNWIND_POP_SHSTK_SSP((payload)); \ - void *shstkRegContext = __libunwind_shstk_get_registers((cursor)); \ - void *shstkJumpAddress = __libunwind_shstk_get_jump_target(); \ - __asm__ volatile("mov x0, %0\n\t" \ - "mov x1, #0\n\t" \ - "br %1\n\t" \ - : \ - : "r"(shstkRegContext), "r"(shstkJumpAddress) \ - : "x0", "x1"); \ - } while (0) -#endif - -// We need this helper function as the semantics of casting between integers and -// function pointers mean that we end up with a function pointer without the -// correct signature. Instead we assign to an integer with a matching schema, -// and then memmove the result into a variable of the correct type. This memmove -// is possible as `_Unwind_Personality_Fn` is a standard function pointer, and -// as such is not address diversified. -static _Unwind_Personality_Fn get_handler_function(unw_proc_info_t *frameInfo) { - uintptr_t __unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, - 0, - ptrauth_function_pointer_type_discriminator(_Unwind_Personality_Fn)) - reauthenticatedIntegerHandler = frameInfo->handler; - _Unwind_Personality_Fn handler; - memmove(&handler, (void *)&reauthenticatedIntegerHandler, - sizeof(_Unwind_Personality_Fn)); - return handler; -} - -static _Unwind_Reason_Code -unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { - __unw_init_local(cursor, uc); - - // Walk each frame looking for a place to stop. - while (true) { - // Ask libunwind to get next frame (skip over first which is - // _Unwind_RaiseException). - int stepResult = __unw_step(cursor); - if (stepResult == 0) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): __unw_step() reached " - "bottom => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_END_OF_STACK; - } else if (stepResult < 0) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): __unw_step failed => " - "_URC_FATAL_PHASE1_ERROR", - (void *)exception_object); - return _URC_FATAL_PHASE1_ERROR; - } - - // See if frame has code to run (has personality routine). - unw_proc_info_t frameInfo; - unw_word_t sp; - if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): __unw_get_proc_info " - "failed => _URC_FATAL_PHASE1_ERROR", - (void *)exception_object); - return _URC_FATAL_PHASE1_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - unw_word_t pc; - __unw_get_reg(cursor, UNW_REG_IP, &pc); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): pc=0x%" PRIxPTR ", start_ip=0x%" PRIxPTR - ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR "", - (void *)exception_object, pc, frameInfo.start_ip, functionName, - frameInfo.lsda, frameInfo.handler); - } -#endif - - // If there is a personality routine, ask it if it will want to stop at - // this frame. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = get_handler_function(&frameInfo); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): calling personality function %p", - (void *)exception_object, (void *)(uintptr_t)p); - _Unwind_Reason_Code personalityResult = - (*p)(1, _UA_SEARCH_PHASE, exception_object->exception_class, - exception_object, (struct _Unwind_Context *)(cursor)); - switch (personalityResult) { - case _URC_HANDLER_FOUND: - // found a catch clause or locals that need destructing in this frame - // stop search and remember stack pointer at the frame - __unw_get_reg(cursor, UNW_REG_SP, &sp); - exception_object->private_2 = (uintptr_t)sp; - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): _URC_HANDLER_FOUND", - (void *)exception_object); - return _URC_NO_REASON; - - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): _URC_CONTINUE_UNWIND", - (void *)exception_object); - // continue unwinding - break; - - default: - // something went wrong - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase1(ex_obj=%p): _URC_FATAL_PHASE1_ERROR", - (void *)exception_object); - return _URC_FATAL_PHASE1_ERROR; - } - } - } - return _URC_NO_REASON; -} - -#if defined(_LIBUNWIND_USE_GCS) -// Enable the GCS target feature to permit gcspop instructions to be used. -__attribute__((target("+gcs"))) -#else -_LIBUNWIND_TRACE_NO_INLINE -#endif -static _Unwind_Reason_Code -unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, - _Unwind_Exception *exception_object) { - __unw_init_local(cursor, uc); - - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_obj=%p)", - (void *)exception_object); - - // uc is initialized by __unw_getcontext in the parent frame. The first stack - // frame walked is unwind_phase2. - unsigned framesWalked = 1; -#if defined(_LIBUNWIND_USE_CET) - unsigned long shadowStackTop = _get_ssp(); -#elif defined(_LIBUNWIND_USE_GCS) - unsigned long shadowStackTop = 0; - if (__chkfeat(_CHKFEAT_GCS)) - shadowStackTop = (unsigned long)__gcspr(); -#endif - // Walk each frame until we reach where search phase said to stop. - while (true) { - - // Ask libunwind to get next frame (skip over first which is - // _Unwind_RaiseException). - int stepResult = __unw_step_stage2(cursor); - if (stepResult == 0) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_obj=%p): __unw_step_stage2() reached " - "bottom => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_END_OF_STACK; - } else if (stepResult < 0) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_obj=%p): __unw_step_stage2 failed => " - "_URC_FATAL_PHASE1_ERROR", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - - // Get info about this frame. - unw_word_t sp; - unw_proc_info_t frameInfo; - __unw_get_reg(cursor, UNW_REG_SP, &sp); - if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_obj=%p): __unw_get_proc_info " - "failed => _URC_FATAL_PHASE1_ERROR", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_obj=%p): start_ip=0x%" PRIxPTR - ", func=%s, sp=0x%" PRIxPTR ", lsda=0x%" PRIxPTR - ", personality=0x%" PRIxPTR, - (void *)exception_object, frameInfo.start_ip, - functionName, sp, frameInfo.lsda, - frameInfo.handler); - } -#endif - -// In shadow stack enabled environment, we check return address stored in normal -// stack against return address stored in shadow stack, if the 2 addresses don't -// match, it means return address in normal stack has been corrupted, we return -// _URC_FATAL_PHASE2_ERROR. -#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS) - if (shadowStackTop != 0) { - unw_word_t retInNormalStack; - __unw_get_reg(cursor, UNW_REG_IP, &retInNormalStack); - unsigned long retInShadowStack = - *(unsigned long *)(shadowStackTop + __shstk_step_size * framesWalked); - if (retInNormalStack != retInShadowStack) - return _URC_FATAL_PHASE2_ERROR; - } -#endif - ++framesWalked; - // If there is a personality routine, tell it we are unwinding. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = get_handler_function(&frameInfo); - _Unwind_Action action = _UA_CLEANUP_PHASE; - if (sp == exception_object->private_2) { - // Tell personality this was the frame it marked in phase 1. - action = (_Unwind_Action)(_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME); - } - _Unwind_Reason_Code personalityResult = - (*p)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(cursor)); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - // Continue unwinding - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_obj=%p): _URC_CONTINUE_UNWIND", - (void *)exception_object); - if (sp == exception_object->private_2) { - // Phase 1 said we would stop at this frame, but we did not... - _LIBUNWIND_ABORT("during phase1 personality function said it would " - "stop here, but now in phase2 it did not stop here"); - } - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2(ex_obj=%p): _URC_INSTALL_CONTEXT", - (void *)exception_object); - // Personality routine says to transfer control to landing pad. - // We may get control back if landing pad calls _Unwind_Resume(). - if (_LIBUNWIND_TRACING_UNWINDING) { - unw_word_t pc; - __unw_get_reg(cursor, UNW_REG_IP, &pc); - __unw_get_reg(cursor, UNW_REG_SP, &sp); - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_obj=%p): re-entering " - "user code with ip=0x%" PRIxPTR - ", sp=0x%" PRIxPTR, - (void *)exception_object, pc, sp); - } - - __unw_phase2_resume(cursor, framesWalked); - // __unw_phase2_resume() only returns if there was an error. - return _URC_FATAL_PHASE2_ERROR; - default: - // Personality routine returned an unknown result code. - _LIBUNWIND_DEBUG_LOG("personality function returned unknown result %d", - personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - } - } - - // Clean up phase did not resume at the frame that the search phase - // said it would... - return _URC_FATAL_PHASE2_ERROR; -} - -#if defined(_LIBUNWIND_USE_GCS) -// Enable the GCS target feature to permit gcspop instructions to be used. -__attribute__((target("+gcs"))) -#else -_LIBUNWIND_TRACE_NO_INLINE -#endif -static _Unwind_Reason_Code -unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor, - _Unwind_Exception *exception_object, _Unwind_Stop_Fn stop, - void *stop_parameter) { - __unw_init_local(cursor, uc); - - // uc is initialized by __unw_getcontext in the parent frame. The first stack - // frame walked is unwind_phase2_forced. - unsigned framesWalked = 1; - // Walk each frame until we reach where search phase said to stop - while (__unw_step_stage2(cursor) > 0) { - - // Update info about this frame. - unw_proc_info_t frameInfo; - if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_obj=%p): __unw_get_proc_info " - "failed => _URC_END_OF_STACK", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - -#ifndef NDEBUG - // When tracing, print state information. - if (_LIBUNWIND_TRACING_UNWINDING) { - char functionBuf[512]; - const char *functionName = functionBuf; - unw_word_t offset; - if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), - &offset) != UNW_ESUCCESS) || - (frameInfo.start_ip + offset > frameInfo.end_ip)) - functionName = ".anonymous."; - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_obj=%p): start_ip=0x%" PRIxPTR - ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR, - (void *)exception_object, frameInfo.start_ip, functionName, - frameInfo.lsda, frameInfo.handler); - } -#endif - - // Call stop function at each frame. - _Unwind_Action action = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE); - _Unwind_Reason_Code stopResult = - (*stop)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(cursor), stop_parameter); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_obj=%p): stop function returned %d", - (void *)exception_object, stopResult); - if (stopResult != _URC_NO_REASON) { - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_obj=%p): stopped by stop function", - (void *)exception_object); - return _URC_FATAL_PHASE2_ERROR; - } - - ++framesWalked; - // If there is a personality routine, tell it we are unwinding. - if (frameInfo.handler != 0) { - _Unwind_Personality_Fn p = get_handler_function(&frameInfo); - _LIBUNWIND_TRACE_UNWINDING( - "unwind_phase2_forced(ex_obj=%p): calling personality function %p", - (void *)exception_object, (void *)(uintptr_t)p); - _Unwind_Reason_Code personalityResult = - (*p)(1, action, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(cursor)); - switch (personalityResult) { - case _URC_CONTINUE_UNWIND: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_obj=%p): " - "personality returned " - "_URC_CONTINUE_UNWIND", - (void *)exception_object); - // Destructors called, continue unwinding - break; - case _URC_INSTALL_CONTEXT: - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_obj=%p): " - "personality returned " - "_URC_INSTALL_CONTEXT", - (void *)exception_object); - // We may get control back if landing pad calls _Unwind_Resume(). - __unw_phase2_resume(cursor, framesWalked); - break; - default: - // Personality routine returned an unknown result code. - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_obj=%p): " - "personality returned %d, " - "_URC_FATAL_PHASE2_ERROR", - (void *)exception_object, personalityResult); - return _URC_FATAL_PHASE2_ERROR; - } - } - } - - // Call stop function one last time and tell it we've reached the end - // of the stack. - _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_obj=%p): calling stop " - "function with _UA_END_OF_STACK", - (void *)exception_object); - _Unwind_Action lastAction = - (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK); - (*stop)(1, lastAction, exception_object->exception_class, exception_object, - (struct _Unwind_Context *)(cursor), stop_parameter); - - // Clean up phase did not resume at the frame that the search phase said it - // would. - return _URC_FATAL_PHASE2_ERROR; -} - -/// Called by __cxa_throw. Only returns if there is a fatal error. -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_RaiseException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)", - (void *)exception_object); - unw_context_t uc; - unw_cursor_t cursor; - __unw_getcontext(&uc); - - // Mark that this is a non-forced unwind, so _Unwind_Resume() - // can do the right thing. - exception_object->private_1 = 0; - exception_object->private_2 = 0; - - // phase 1: the search phase - _Unwind_Reason_Code phase1 = unwind_phase1(&uc, &cursor, exception_object); - if (phase1 != _URC_NO_REASON) - return phase1; - - // phase 2: the clean up phase - return unwind_phase2(&uc, &cursor, exception_object); -} - - - -/// When _Unwind_RaiseException() is in phase2, it hands control -/// to the personality function at each frame. The personality -/// may force a jump to a landing pad in that function, the landing -/// pad code may then call _Unwind_Resume() to continue with the -/// unwinding. Note: the call to _Unwind_Resume() is from compiler -/// generated user code. All other _Unwind_* routines are called -/// by the C++ runtime __cxa_* routines. -/// -/// Note: re-throwing an exception (as opposed to continuing the unwind) -/// is implemented by having the code call __cxa_rethrow() which -/// in turn calls _Unwind_Resume_or_Rethrow(). -_LIBUNWIND_EXPORT void -_Unwind_Resume(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)", (void *)exception_object); - unw_context_t uc; - unw_cursor_t cursor; - __unw_getcontext(&uc); - - if (exception_object->private_1 != 0) - unwind_phase2_forced(&uc, &cursor, exception_object, - (_Unwind_Stop_Fn) exception_object->private_1, - (void *)exception_object->private_2); - else - unwind_phase2(&uc, &cursor, exception_object); - - // Clients assume _Unwind_Resume() does not return, so all we can do is abort. - _LIBUNWIND_ABORT("_Unwind_Resume() can't return"); -} - - - -/// Not used by C++. -/// Unwinds stack, calling "stop" function at each frame. -/// Could be used to implement longjmp(). -_LIBUNWIND_EXPORT _Unwind_Reason_Code -_Unwind_ForcedUnwind(_Unwind_Exception *exception_object, - _Unwind_Stop_Fn stop, void *stop_parameter) { - _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)", - (void *)exception_object, (void *)(uintptr_t)stop); - unw_context_t uc; - unw_cursor_t cursor; - __unw_getcontext(&uc); - - // Mark that this is a forced unwind, so _Unwind_Resume() can do - // the right thing. - exception_object->private_1 = (uintptr_t) stop; - exception_object->private_2 = (uintptr_t) stop_parameter; - - // do it - return unwind_phase2_forced(&uc, &cursor, exception_object, stop, stop_parameter); -} - - -/// Called by personality handler during phase 2 to get LSDA for current frame. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_proc_info_t frameInfo; - uintptr_t result = 0; - if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) - result = (uintptr_t)frameInfo.lsda; - _LIBUNWIND_TRACE_API( - "_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIxPTR, - (void *)context, result); -#if !defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND) - if (result != 0) { - if (*((uint8_t *)result) != 0xFF) - _LIBUNWIND_DEBUG_LOG("lsda at 0x%" PRIxPTR " does not start with 0xFF", - result); - } -#endif - return result; -} - - -/// Called by personality handler during phase 2 to find the start of the -/// function. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetRegionStart(struct _Unwind_Context *context) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_proc_info_t frameInfo; - uintptr_t result = 0; - if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) - result = (uintptr_t)frameInfo.start_ip; - _LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p) => 0x%" PRIxPTR, - (void *)context, result); - return result; -} - -#endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND - -/// Called by personality handler during phase 2 if a foreign exception -// is caught. -_LIBUNWIND_EXPORT void -_Unwind_DeleteException(_Unwind_Exception *exception_object) { - _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)", - (void *)exception_object); - if (exception_object->exception_cleanup != NULL) - (*exception_object->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT, - exception_object); -} - -/// Called by personality handler during phase 2 to get register values. -_LIBUNWIND_EXPORT uintptr_t -_Unwind_GetGR(struct _Unwind_Context *context, int index) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_word_t result; - __unw_get_reg(cursor, index, &result); - _LIBUNWIND_TRACE_API("_Unwind_GetGR(context=%p, reg=%d) => 0x%" PRIxPTR, - (void *)context, index, result); - return (uintptr_t)result; -} - -/// Called by personality handler during phase 2 to alter register values. -_LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index, - uintptr_t value) { - _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%0" PRIxPTR - ")", - (void *)context, index, value); - unw_cursor_t *cursor = (unw_cursor_t *)context; - __unw_set_reg(cursor, index, value); -} - -/// Called by personality handler during phase 2 to get instruction pointer. -_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) { - unw_cursor_t *cursor = (unw_cursor_t *)context; - unw_word_t result; - __unw_get_reg(cursor, UNW_REG_IP, &result); - -#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING) - // If we are in an arm64e frame, then the PC should have been signed with the - // sp - { - unw_word_t sp; - __unw_get_reg(cursor, UNW_REG_SP, &sp); - result = (unw_word_t)ptrauth_auth_data((void *)result, - ptrauth_key_return_address, sp); - } -#endif - - _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => 0x%" PRIxPTR, - (void *)context, result); - return (uintptr_t)result; -} - -/// Called by personality handler during phase 2 to alter instruction pointer, -/// such as setting where the landing pad is, so _Unwind_Resume() will -/// start executing in the landing pad. -_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context, - uintptr_t value) { - _LIBUNWIND_TRACE_API("_Unwind_SetIP(context=%p, value=0x%0" PRIxPTR ")", - (void *)context, value); - unw_cursor_t *cursor = (unw_cursor_t *)context; - __unw_set_reg(cursor, UNW_REG_IP, value); -} - -#endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) diff --git a/src/native/external/llvm-libunwind/src/Unwind_AIXExtras.cpp b/src/native/external/llvm-libunwind/src/Unwind_AIXExtras.cpp deleted file mode 100644 index 97b6c3e5e01aea..00000000000000 --- a/src/native/external/llvm-libunwind/src/Unwind_AIXExtras.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===--------------------- Unwind_AIXExtras.cpp -------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// -//===----------------------------------------------------------------------===// - -// This file is only used for AIX. -#if defined(_AIX) - -#include "AddressSpace.hpp" -#include "config.h" -#include "libunwind_ext.h" -#include - -namespace libunwind { -// getFuncNameFromTBTable -// Get the function name from its traceback table. -char *getFuncNameFromTBTable(uintptr_t Pc, uint16_t &NameLen, - unw_word_t *Offset) { - uint32_t *p = reinterpret_cast(Pc); - *Offset = 0; - - // Keep looking forward until a word of 0 is found. The traceback - // table starts at the following word. - while (*p) - p++; - tbtable *TBTable = reinterpret_cast(p + 1); - - if (!TBTable->tb.name_present) - return NULL; - - // Get to the name of the function. - p = reinterpret_cast(&TBTable->tb_ext); - - // Skip field parminfo if it exists. - if (TBTable->tb.fixedparms || TBTable->tb.floatparms) - p++; - - // If the tb_offset field exists, get the offset from the start of - // the function to pc. Skip the field. - if (TBTable->tb.has_tboff) { - unw_word_t StartIp = - reinterpret_cast(TBTable) - *p - sizeof(uint32_t); - *Offset = Pc - StartIp; - p++; - } - - // Skip field hand_mask if it exists. - if (TBTable->tb.int_hndl) - p++; - - // Skip fields ctl_info and ctl_info_disp if they exist. - if (TBTable->tb.has_ctl) { - p += 1 + *p; - } - - NameLen = *(reinterpret_cast(p)); - return reinterpret_cast(p) + sizeof(uint16_t); -} -} // namespace libunwind -#endif // defined(_AIX) diff --git a/src/native/external/llvm-libunwind/test/CMakeLists.txt b/src/native/external/llvm-libunwind/test/CMakeLists.txt deleted file mode 100644 index 2559ab34f9d5b7..00000000000000 --- a/src/native/external/llvm-libunwind/test/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -include(AddLLVM) # for add_lit_testsuite -include(HandleLitArguments) -macro(pythonize_bool var) - if (${var}) - set(${var} True) - else() - set(${var} False) - endif() -endmacro() - -# Install targets required to run libunwind tests into a temporary location. -# -# This ensures that we run the tests against the final installed products, which -# is closer to what we actually ship than the contents of the build tree. -set(LIBUNWIND_TESTING_INSTALL_PREFIX "${LIBUNWIND_BINARY_DIR}/test-suite-install") -set(libunwind_test_suite_install_targets unwind-headers unwind) -if ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES) - list(APPEND libunwind_test_suite_install_targets cxx-headers cxx cxx-modules cxxabi-headers cxxabi) -endif() -foreach(target IN LISTS libunwind_test_suite_install_targets) - add_custom_target(libunwind-test-suite-install-${target} DEPENDS "${target}" - COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" - --prefix "${LIBUNWIND_TESTING_INSTALL_PREFIX}" - --component "${target}") - add_dependencies(unwind-test-depends libunwind-test-suite-install-${target}) -endforeach() - -pythonize_bool(LIBUNWIND_ENABLE_CET) -pythonize_bool(LIBUNWIND_ENABLE_GCS) -pythonize_bool(LIBUNWIND_ENABLE_THREADS) -pythonize_bool(LIBUNWIND_USES_ARM_EHABI) - -set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not edit!") -set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n") - -serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler "${CMAKE_CXX_COMPILER}") - -if (LIBUNWIND_EXECUTOR) - message(DEPRECATION "LIBUNWIND_EXECUTOR is deprecated, please add executor=... to LIBUNWIND_TEST_PARAMS") - serialize_lit_string_param(SERIALIZED_LIT_PARAMS executor "${LIBUNWIND_EXECUTOR}") -endif() - -serialize_lit_param(SERIALIZED_LIT_PARAMS enable_experimental False) - -if (LLVM_USE_SANITIZER) - serialize_lit_string_param(SERIALIZED_LIT_PARAMS use_sanitizer "${LLVM_USE_SANITIZER}") -endif() - -if (CMAKE_CXX_COMPILER_TARGET) - serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}") -else() - serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${LLVM_DEFAULT_TARGET_TRIPLE}") -endif() - -serialize_lit_params_list(SERIALIZED_LIT_PARAMS LIBUNWIND_TEST_PARAMS) - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg" - @ONLY) - -configure_lit_site_cfg( - "${LIBUNWIND_TEST_CONFIG}" - ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg - MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py") - -add_lit_testsuite(check-unwind "Running libunwind tests" - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS unwind-test-depends) diff --git a/src/native/external/llvm-libunwind/test/aarch64_vg_unwind.pass.cpp b/src/native/external/llvm-libunwind/test/aarch64_vg_unwind.pass.cpp deleted file mode 100644 index d0c623b155092d..00000000000000 --- a/src/native/external/llvm-libunwind/test/aarch64_vg_unwind.pass.cpp +++ /dev/null @@ -1,69 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// REQUIRES: target={{aarch64-.+}} -// UNSUPPORTED: target={{.*-windows.*}} - -#include -#include -#include - -// Basic test of VG (Vector Granule) unwinding. This is meant to mimic SVE/SME -// unwind info without requiring those features for this test. - -#define VG_REGNUM 46 - -__attribute__((noinline)) void baz() { - // The previous value of VG is 2 - asm(".cfi_escape 0x16, 0x2e, 0x01, 0x32"); - - unw_context_t context; - unw_cursor_t cursor; - unw_getcontext(&context); - unw_init_local(&cursor, &context); - - // Note: At this point VG is not defined (until we unw_step). - - uint16_t expected_vgs[]{/*qux*/ 2, /*bar*/ 2, /*foo*/ 8, /*main*/ 2}; - for (uint16_t expected_vg : expected_vgs) { - unw_step(&cursor); - unw_word_t vg; - unw_get_reg(&cursor, VG_REGNUM, &vg); - if (vg != expected_vg) - exit(1); - } - exit(0); -} - -__attribute__((noinline)) void qux() { baz(); } - -__attribute__((noinline)) void bar() { - // The previous value of VG is 8 - asm(".cfi_escape 0x16, 0x2e, 0x01, 0x38"); - // The previous value of W21 is VG (used to force an evaluation of VG). - asm(".cfi_escape 0x16, 0x15, 0x03, 0x92, 0x2e, 0x00"); - - // smstop sm - qux(); - // smstart sm -} -__attribute__((noinline)) void foo() { - // The previous value of VG is 2 - asm(".cfi_escape 0x16, 0x2e, 0x01, 0x32"); - // The previous value of W21 is VG (used to force an evaluation of VG). - asm(".cfi_escape 0x16, 0x15, 0x03, 0x92, 0x2e, 0x00"); - - // smstart sm - bar(); - // smstop sm -} - -int main(int, char **) { - foo(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/aarch64_za_unwind.pass.cpp b/src/native/external/llvm-libunwind/test/aarch64_za_unwind.pass.cpp deleted file mode 100644 index 9f6b106a21fecb..00000000000000 --- a/src/native/external/llvm-libunwind/test/aarch64_za_unwind.pass.cpp +++ /dev/null @@ -1,118 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// REQUIRES: target={{aarch64-.+}} -// UNSUPPORTED: target={{.*-windows.*}} - -#include -#include -#include -#include -#include -#include - -// Basic test of unwinding with SME lazy saves. This tests libunwind disables ZA -// (and commits a lazy save of ZA) before resuming from unwinding. - -// Note: This test requires SME (and is setup to pass on targets without SME). - -static bool checkHasSME() { - constexpr int hwcap2_sme = (1 << 23); - unsigned long hwcap2 = getauxval(AT_HWCAP2); - return (hwcap2 & hwcap2_sme) != 0; -} - -struct TPIDR2Block { - void *za_save_buffer; - uint64_t num_save_slices; -}; - -__attribute__((noinline)) void private_za() { - // Note: Lazy save active on entry to function. - unw_context_t context; - unw_cursor_t cursor; - - unw_getcontext(&context); - unw_init_local(&cursor, &context); - unw_step(&cursor); - unw_resume(&cursor); -} - -bool isZAOn() { - register uint64_t svcr asm("x20"); - asm(".inst 0xd53b4254" : "=r"(svcr)); - return (svcr & 0b10) != 0; -} - -__attribute__((noinline)) void za_function_with_lazy_save() { - register uint64_t tmp asm("x8"); - - // SMSTART ZA (should zero ZA) - asm(".inst 0xd503457f"); - - // RDSVL x8, #1 (read streaming vector length) - asm(".inst 0x04bf5828" : "=r"(tmp)); - - // Allocate and fill ZA save buffer with 0xAA. - size_t buffer_size = tmp * tmp; - uint8_t *za_save_buffer = (uint8_t *)alloca(buffer_size); - memset(za_save_buffer, 0xAA, buffer_size); - - TPIDR2Block block = {za_save_buffer, tmp}; - tmp = reinterpret_cast(&block); - - // MRS TPIDR2_EL0, x8 (setup lazy save of ZA) - asm(".inst 0xd51bd0a8" ::"r"(tmp)); - - // ZA should be on before unwinding. - if (!isZAOn()) { - fprintf(stderr, __FILE__ ": fail (ZA not on before call)\n"); - abort(); - } else { - fprintf(stderr, __FILE__ ": pass (ZA on before call)\n"); - } - - private_za(); - - // ZA should be off after unwinding. - if (isZAOn()) { - fprintf(stderr, __FILE__ ": fail (ZA on after unwinding)\n"); - abort(); - } else { - fprintf(stderr, __FILE__ ": pass (ZA off after unwinding)\n"); - } - - // MRS x8, TPIDR2_EL0 (read TPIDR2_EL0) - asm(".inst 0xd53bd0a8" : "=r"(tmp)); - // ZA should have been saved (TPIDR2_EL0 zero). - if (tmp != 0) { - fprintf(stderr, __FILE__ ": fail (TPIDR2_EL0 non-null after unwinding)\n"); - abort(); - } else { - fprintf(stderr, __FILE__ ": pass (TPIDR2_EL0 null after unwinding)\n"); - } - - // ZA (all zero) should have been saved to the buffer. - for (unsigned i = 0; i < buffer_size; ++i) { - if (za_save_buffer[i] != 0) { - fprintf(stderr, - __FILE__ ": fail (za_save_buffer non-zero after unwinding)\n"); - abort(); - } - } - fprintf(stderr, __FILE__ ": pass (za_save_buffer zero'd after unwinding)\n"); -} - -int main(int, char **) { - if (!checkHasSME()) { - fprintf(stderr, __FILE__ ": pass (no SME support)\n"); - return 0; // Pass (SME is required for this test to run). - } - za_function_with_lazy_save(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/aix_runtime_link.pass.cpp b/src/native/external/llvm-libunwind/test/aix_runtime_link.pass.cpp deleted file mode 100644 index deb192c07981eb..00000000000000 --- a/src/native/external/llvm-libunwind/test/aix_runtime_link.pass.cpp +++ /dev/null @@ -1,20 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Test that libunwind loads successfully independently of libc++abi with -// runtime linking on AIX. - -// REQUIRES: target={{.+}}-aix{{.*}} -// ADDITIONAL_COMPILE_FLAGS: -Wl,-brtl - -#include -extern "C" int printf(const char *, ...); -int main(void) { - void *fp = (void *)&_Unwind_Backtrace; - printf("%p\n", fp); -} diff --git a/src/native/external/llvm-libunwind/test/aix_signal_unwind.pass.sh.S b/src/native/external/llvm-libunwind/test/aix_signal_unwind.pass.sh.S deleted file mode 100644 index 056575745ea187..00000000000000 --- a/src/native/external/llvm-libunwind/test/aix_signal_unwind.pass.sh.S +++ /dev/null @@ -1,246 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Test that _Unwind_Backtrace() walks up from a signal handler and produces -// a correct traceback when the function raising the signal does not save -// the link register or does not store the stack back chain. - -// REQUIRES: target={{.+}}-aix{{.*}} - -// Test when the function raising the signal does not save the link register -// RUN: %{cxx} -x c++ %s -o %t.exe -DCXX_CODE %{flags} %{compile_flags} -// RUN: %{exec} %t.exe - -// Test when the function raising the signal does not store stack back chain. -// RUN: %{cxx} -x c++ -c %s -o %t1.o -DCXX_CODE -DNOBACKCHAIN %{flags} \ -// RUN: %{compile_flags} -// RUN: %{cxx} -c %s -o %t2.o %{flags} %{compile_flags} -// RUN: %{cxx} -o %t1.exe %t1.o %t2.o %{flags} %{link_flags} -// RUN: %{exec} %t1.exe - -#ifdef CXX_CODE - -#undef NDEBUG -#include -#include -#include -#include -#include -#include -#include - -#define NAME_ARRAY_SIZE 10 -#define NAMES_EXPECTED 6 - -const char* namesExpected[] = {"handler", "abc", "bar", "foo", "main", - "__start"}; -char *namesObtained[NAME_ARRAY_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -int funcIndex = 0; - -// Get the function name from traceback table. -char *getFuncName(uintptr_t pc, uint16_t *nameLen) { - uint32_t *p = reinterpret_cast(pc); - - // Keep looking forward until a word of 0 is found. The traceback - // table starts at the following word. - while (*p) - ++p; - tbtable *TBTable = reinterpret_cast(p + 1); - - if (!TBTable->tb.name_present) - return NULL; - - // Get to the optional portion of the traceback table. - p = reinterpret_cast(&TBTable->tb_ext); - - // Skip field parminfo if it exists. - if (TBTable->tb.fixedparms || TBTable->tb.floatparms) - ++p; - - // Skip field tb_offset if it exists. - if (TBTable->tb.has_tboff) - ++p; - - // Skip field hand_mask if it exists. - if (TBTable->tb.int_hndl) - ++p; - - // Skip fields ctl_info and ctl_info_disp if they exist. - if (TBTable->tb.has_ctl) - p += 1 + *p; - - *nameLen = *reinterpret_cast(p); - return reinterpret_cast(p) + sizeof(uint16_t); -} - -_Unwind_Reason_Code callBack(struct _Unwind_Context *uc, void *arg) { - (void)arg; - uint16_t nameLen; - uintptr_t ip = _Unwind_GetIP(uc); - if (funcIndex < NAME_ARRAY_SIZE) - namesObtained[funcIndex++] = strndup(getFuncName(ip, &nameLen), nameLen); - return _URC_NO_REASON; -} - -extern "C" void handler(int signum) { - (void)signum; - // Walk stack frames for traceback. - _Unwind_Backtrace(callBack, NULL); - - // Verify the traceback. - assert(funcIndex <= NAMES_EXPECTED && "Obtained names more than expected"); - for (int i = 0; i < funcIndex; ++i) { - assert(!strcmp(namesExpected[i], namesObtained[i]) && - "Function names do not match"); - free(namesObtained[i]); - } - exit(0); -} - -#ifdef NOBACKCHAIN -// abc() is in assembly. It raises signal SIGSEGV and does not store -// the stack back chain. -extern "C" void abc(); - -#else -volatile int *null = 0; - -// abc() raises signal SIGSEGV and does not save the link register. -extern "C" __attribute__((noinline)) void abc() { - // Produce a SIGSEGV. - *null = 0; -} -#endif - -extern "C" __attribute__((noinline)) void bar() { - abc(); -} - -extern "C" __attribute__((noinline)) void foo() { - bar(); -} - -int main(int, char**) { - // Set signal handler for SIGSEGV. - signal(SIGSEGV, handler); - foo(); - return 0; -} - -#else // Assembly code for abc(). -// This assembly code is similar to the following C code but it saves the -// link register. -// -// int *badp = 0; -// void abc() { -// *badp = 0; -// } - -#ifdef __64BIT__ - .csect [PR],5 - .file "abc.c" - .globl abc[DS] # -- Begin function abc - .globl .abc - .align 4 - .csect abc[DS],3 - .vbyte 8, .abc # @abc - .vbyte 8, TOC[TC0] - .vbyte 8, 0 - .csect [PR],5 -.abc: -# %bb.0: # %entry - mflr 0 - std 0, 16(1) - ld 3, L..C0(2) # @badp - bl $+4 - ld 4, 0(3) - li 3, 0 - stw 3, 0(4) - ld 0, 16(1) - mtlr 0 - blr -L..abc0: - .vbyte 4, 0x00000000 # Traceback table begin - .byte 0x00 # Version = 0 - .byte 0x09 # Language = CPlusPlus - .byte 0x20 # -IsGlobalLinkage, -IsOutOfLineEpilogOrPrologue - # +HasTraceBackTableOffset, -IsInternalProcedure - # -HasControlledStorage, -IsTOCless - # -IsFloatingPointPresent - # -IsFloatingPointOperationLogOrAbortEnabled - .byte 0x61 # -IsInterruptHandler, +IsFunctionNamePresent, +IsAllocaUsed - # OnConditionDirective = 0, -IsCRSaved, +IsLRSaved - .byte 0x00 # -IsBackChainStored, -IsFixup, NumOfFPRsSaved = 0 - .byte 0x01 # -HasExtensionTable, -HasVectorInfo, NumOfGPRsSaved = 1 - .byte 0x00 # NumberOfFixedParms = 0 - .byte 0x01 # NumberOfFPParms = 0, +HasParmsOnStack - .vbyte 4, L..abc0-.abc # Function size - .vbyte 2, 0x0003 # Function name len = 3 - .byte "abc" # Function Name - .byte 0x1f # AllocaUsed - # -- End function - .csect badp[RW],3 - .globl badp[RW] # @badp - .align 3 - .vbyte 8, 0 - .toc -L..C0: - .tc badp[TC],badp[RW] -#else - .csect [PR],5 - .file "abc.c" - .globl abc[DS] # -- Begin function abc - .globl .abc - .align 4 - .csect abc[DS],2 - .vbyte 4, .abc # @abc - .vbyte 4, TOC[TC0] - .vbyte 4, 0 - .csect [PR],5 -.abc: -# %bb.0: # %entry - mflr 0 - stw 0, 8(1) - lwz 3, L..C0(2) # @badp - bl $+4 - lwz 4, 0(3) - li 3, 0 - stw 3, 0(4) - lwz 0, 8(1) - mtlr 0 - blr -L..abc0: - .vbyte 4, 0x00000000 # Traceback table begin - .byte 0x00 # Version = 0 - .byte 0x09 # Language = CPlusPlus - .byte 0x20 # -IsGlobalLinkage, -IsOutOfLineEpilogOrPrologue - # +HasTraceBackTableOffset, -IsInternalProcedure - # -HasControlledStorage, -IsTOCless - # -IsFloatingPointPresent - # -IsFloatingPointOperationLogOrAbortEnabled - .byte 0x61 # -IsInterruptHandler, +IsFunctionNamePresent, +IsAllocaUsed - # OnConditionDirective = 0, -IsCRSaved, +IsLRSaved - .byte 0x00 # -IsBackChainStored, -IsFixup, NumOfFPRsSaved = 0 - .byte 0x01 # -HasExtensionTable, -HasVectorInfo, NumOfGPRsSaved = 1 - .byte 0x00 # NumberOfFixedParms = 0 - .byte 0x01 # NumberOfFPParms = 0, +HasParmsOnStack - .vbyte 4, L..abc0-.abc # Function size - .vbyte 2, 0x0003 # Function name len = 3 - .byte "abc" # Function Name - .byte 0x1f # AllocaUsed - # -- End function - .csect badp[RW],2 - .globl badp[RW] # @badp - .align 2 - .vbyte 4, 0 - .toc -L..C0: - .tc badp[TC],badp[RW] -#endif // __64BIT__ -#endif // CXX_CODE diff --git a/src/native/external/llvm-libunwind/test/alignment.compile.pass.cpp b/src/native/external/llvm-libunwind/test/alignment.compile.pass.cpp deleted file mode 100644 index 4606dc5e538555..00000000000000 --- a/src/native/external/llvm-libunwind/test/alignment.compile.pass.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// The Itanium ABI requires that _Unwind_Exception objects are "double-word -// aligned". - -#include - -// EHABI : 8-byte aligned -// itanium: largest supported alignment for the system -#if defined(_LIBUNWIND_ARM_EHABI) -static_assert(alignof(_Unwind_Control_Block) == 8, - "_Unwind_Control_Block must be double-word aligned"); -#else -struct MaxAligned {} __attribute__((__aligned__)); -static_assert(alignof(_Unwind_Exception) == alignof(MaxAligned), - "_Unwind_Exception must be maximally aligned"); -#endif diff --git a/src/native/external/llvm-libunwind/test/bad_unwind_info.pass.cpp b/src/native/external/llvm-libunwind/test/bad_unwind_info.pass.cpp deleted file mode 100644 index 332b661d2e98f1..00000000000000 --- a/src/native/external/llvm-libunwind/test/bad_unwind_info.pass.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Ensure that libunwind doesn't crash on invalid info; the Linux aarch64 -// sigreturn frame check would previously attempt to access invalid memory in -// this scenario. -// REQUIRES: target={{(aarch64|s390x|x86_64)-.+}} -// UNSUPPORTED: target={{.*-windows.*}} -// UNSUPPORTED: target={{.*-apple.*}} - -// GCC doesn't support __attribute__((naked)) on AArch64. -// UNSUPPORTED: gcc - -// Inline assembly is incompatible with MSAN. -// UNSUPPORTED: msan - -#undef NDEBUG -#include -#include -#include - -__attribute__((naked)) void bad_unwind_info() { -#if defined(__aarch64__) - __asm__("// not using 0 because unwinder was already resilient to that\n" - "mov x8, #4\n" - "stp x30, x8, [sp, #-16]!\n" - ".cfi_def_cfa_offset 16\n" - "// purposely use incorrect offset for x30\n" - ".cfi_offset x30, -8\n" - "bl stepper\n" - "ldr x30, [sp], #16\n" - ".cfi_def_cfa_offset 0\n" - ".cfi_restore x30\n" - "ret\n"); -#elif defined(__s390x__) - __asm__("stmg %r14,%r15,112(%r15)\n" - "mvghi 104(%r15),4\n" - "# purposely use incorrect offset for %r14\n" - ".cfi_offset 14, -56\n" - ".cfi_offset 15, -40\n" - "lay %r15,-160(%r15)\n" - ".cfi_def_cfa_offset 320\n" - "brasl %r14,stepper\n" - "lmg %r14,%r15,272(%r15)\n" - ".cfi_restore 15\n" - ".cfi_restore 14\n" - ".cfi_def_cfa_offset 160\n" - "br %r14\n"); -#elif defined(__x86_64__) - __asm__("pushq %rbx\n" - ".cfi_def_cfa_offset 16\n" - "movq 8(%rsp), %rbx\n" - "# purposely corrupt return value on stack\n" - "movq $4, 8(%rsp)\n" - "callq stepper\n" - "movq %rbx, 8(%rsp)\n" - "popq %rbx\n" - ".cfi_def_cfa_offset 8\n" - "ret\n"); -#else -#error This test is only supported on aarch64, s390x, or x86-64 -#endif -} - -extern "C" void stepper() { - unw_cursor_t cursor; - unw_context_t uc; - unw_getcontext(&uc); - unw_init_local(&cursor, &uc); - // stepping to bad_unwind_info should succeed - assert(unw_step(&cursor) > 0); - // stepping past bad_unwind_info should fail but not crash - assert(unw_step(&cursor) <= 0); -} - -int main(int, char **) { - bad_unwind_info(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/configs/apple-libunwind-system.cfg.in b/src/native/external/llvm-libunwind/test/configs/apple-libunwind-system.cfg.in deleted file mode 100644 index 252448a756be9c..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/apple-libunwind-system.cfg.in +++ /dev/null @@ -1,41 +0,0 @@ -# Testing configuration for back-deployment against the system-provided libunwind. -# -# Under this configuration, we compile and link all the test suite against the just-built -# libunwind, but we run against the system libunwind. - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config, libcxx.test.dsl - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -config.substitutions.append(('%{flags}', - '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else '' -)) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{include}' -)) -config.substitutions.append(('%{link_flags}', - '-nostdlib++ -L %{lib} -lc++ -lunwind' -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} -- ' -)) - -config.stdlib = 'apple-libc++' -config.using_system_stdlib = True - -# TODO: This is a giant hack, but we need to change the install_name of libunwind.dylib because the -# upstream configuration can't currently produce a libunwind.dylib that is compatible with the -# Apple system one. -import subprocess -subprocess.check_call(['install_name_tool', '-id', '/usr/lib/system/libunwind.dylib', '@LIBUNWIND_TESTING_INSTALL_PREFIX@/lib/libunwind.dylib']) - -import os, site -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in b/src/native/external/llvm-libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in deleted file mode 100644 index 6ffdd70c6177e7..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/armv7m-picolibc-libunwind.cfg.in +++ /dev/null @@ -1,39 +0,0 @@ -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -libc_linker_script = '@CMAKE_INSTALL_PREFIX@/lib/picolibcpp.ld' - -config.substitutions.append(('%{flags}', '--sysroot=@CMAKE_INSTALL_PREFIX@')) - -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{include}' -)) -config.substitutions.append(('%{link_flags}', - '-fuse-ld=lld -nostdlib -nostdlib++ -L %{lib} -lunwind' - ' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost' + - ' -T {}'.format(libc_linker_script) + - ' -Wl,--defsym=__flash=0x0' - ' -Wl,--defsym=__flash_size=0x400000' - ' -Wl,--defsym=__ram=0x21000000' - ' -Wl,--defsym=__ram_size=0x1000000' - ' -Wl,--defsym=__stack_size=0x1000' -)) - -config.executor = ( - '@LIBUNWIND_LIBCXX_PATH@/utils/qemu_baremetal.py' - ' --qemu @QEMU_SYSTEM_ARM@' - ' --machine mps2-an385' - ' --cpu cortex-m3') -config.substitutions.append(('%{exec}', - '%{executor}' - ' --execdir %{temp}' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/cmake-bridge.cfg.in b/src/native/external/llvm-libunwind/test/configs/cmake-bridge.cfg.in deleted file mode 100644 index e40497bfa99766..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/cmake-bridge.cfg.in +++ /dev/null @@ -1,46 +0,0 @@ -@AUTO_GEN_COMMENT@ - -@SERIALIZED_LIT_PARAMS@ - -# -# This file performs the bridge between the CMake configuration and the Lit -# configuration files by setting up the LitConfig object and various Lit -# substitutions from CMake variables. -# -# Individual configuration files can take advantage of this bridge by -# loading the file and then setting up the remaining Lit substitutions. -# - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.format -from lit.util import which - -# Basic configuration of the test suite -config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@') -config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test') -config.test_format = libcxx.test.format.CxxStandardLibraryTest() -config.recursiveExpansionLimit = 10 -config.test_exec_root = os.path.join('@LIBUNWIND_BINARY_DIR@', 'test') - -# Add a few features that are common to all the configurations -if @LIBUNWIND_USES_ARM_EHABI@: - config.available_features.add('libunwind-arm-ehabi') -if not @LIBUNWIND_ENABLE_THREADS@: - config.available_features.add('libunwind-no-threads') - -# Add substitutions for bootstrapping the test suite configuration -config.substitutions.append(('%{install-prefix}', '@LIBUNWIND_TESTING_INSTALL_PREFIX@')) -config.substitutions.append(('%{include}', '@LIBUNWIND_TESTING_INSTALL_PREFIX@/include')) -config.substitutions.append(('%{lib}', '@LIBUNWIND_TESTING_INSTALL_PREFIX@/@LIBUNWIND_INSTALL_LIBRARY_DIR@')) -config.substitutions.append(('%{benchmark_flags}', '')) - -# Check for objcopy tools -objcopy_path = which('llvm-objcopy', '@LLVM_BUILD_BINARY_DIR@/bin') -if not objcopy_path: - objcopy_path = which('llvm-objcopy') -if not objcopy_path: - objcopy_path = which('objcopy') -if objcopy_path: - config.substitutions.append(('%{objcopy}', objcopy_path)) - config.available_features.add('objcopy-available') diff --git a/src/native/external/llvm-libunwind/test/configs/ibm-libunwind-shared.cfg.in b/src/native/external/llvm-libunwind/test/configs/ibm-libunwind-shared.cfg.in deleted file mode 100644 index 99f4a9061d19a7..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/ibm-libunwind-shared.cfg.in +++ /dev/null @@ -1,31 +0,0 @@ -# Configuration file for running the libunwind tests on AIX. -# - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -import lit.util -if lit.util.isAIXTriple(config.target_triple): - # Add the AIX version to the triple here because there currently isn't a good - # way to retrieve the AIX version in the driver. - config.target_triple = lit.util.addAIXVersion(config.target_triple) - -config.substitutions.append(('%{flags}', '')) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{include}' -)) -config.substitutions.append(('%{link_flags}', - '-nostdlib++ -L %{lib} -lunwind -ldl -Wl,-bbigtoc' -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} --env LIBPATH=%{lib} -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-merged.cfg.in b/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-merged.cfg.in deleted file mode 100644 index 34950f6ea29360..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-merged.cfg.in +++ /dev/null @@ -1,49 +0,0 @@ -# -# Configuration file for running the libunwind tests against a libc++ shared library -# into which the unwinder was merged. -# - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -compile_flags = [] -link_flags = [] - -if @LIBUNWIND_ENABLE_CET@: - compile_flags.append('-fcf-protection=full') - -if @LIBUNWIND_ENABLE_GCS@: - compile_flags.append('-mbranch-protection=standard') - -# On ELF platforms, link tests with -Wl,--export-dynamic if supported by the linker. -if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'): - link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@') - -if '@CMAKE_DL_LIBS@': - link_flags.append('-l@CMAKE_DL_LIBS@') - -# Stack unwinding tests need unwinding tables and these are not generated by default on all targets. -compile_flags.append('-funwind-tables') - -local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@' -config.substitutions.append(('%{flags}', - '-isysroot {}'.format(local_sysroot) if local_sysroot else '' -)) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags)) -)) -config.substitutions.append(('%{link_flags}', - '-L %{{lib}} -Wl,-rpath,%{{lib}} -lc++ {}'.format(' '.join(link_flags)) -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in b/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in deleted file mode 100644 index 1e77638b8cee3f..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-shared-mingw.cfg.in +++ /dev/null @@ -1,25 +0,0 @@ -# This testing configuration handles running the test suite against LLVM's libunwind -# using a DLL with MinGW/Clang on Windows. - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -config.substitutions.append(('%{flags}', '')) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{include} -funwind-tables' -)) -config.substitutions.append(('%{link_flags}', - '-L %{lib} -lunwind' -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} --prepend_env PATH=%{install-prefix}/bin -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-shared.cfg.in b/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-shared.cfg.in deleted file mode 100644 index 61d6b61cbae297..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-shared.cfg.in +++ /dev/null @@ -1,48 +0,0 @@ -# -# Configuration file for running the libunwind tests against the shared library. -# - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -compile_flags = [] -link_flags = [] - -if @LIBUNWIND_ENABLE_CET@: - compile_flags.append('-fcf-protection=full') - -if @LIBUNWIND_ENABLE_GCS@: - compile_flags.append('-mbranch-protection=standard') - -# On ELF platforms, link tests with -Wl,--export-dynamic if supported by the linker. -if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'): - link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@') - -if '@CMAKE_DL_LIBS@': - link_flags.append('-l@CMAKE_DL_LIBS@') - -# Stack unwinding tests need unwinding tables and these are not generated by default on all targets. -compile_flags.append('-funwind-tables') - -local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@' -config.substitutions.append(('%{flags}', - '-isysroot {}'.format(local_sysroot) if local_sysroot else '' -)) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags)) -)) -config.substitutions.append(('%{link_flags}', - '-L %{{lib}} -Wl,-rpath,%{{lib}} -lunwind {}'.format(' '.join(link_flags)) -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-static-mingw.cfg.in b/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-static-mingw.cfg.in deleted file mode 100644 index 37d20a7c9a4494..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-static-mingw.cfg.in +++ /dev/null @@ -1,25 +0,0 @@ -# This testing configuration handles running the test suite against LLVM's libunwind -# using a static library with MinGW/Clang on Windows. - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -config.substitutions.append(('%{flags}', '')) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{include} -funwind-tables' -)) -config.substitutions.append(('%{link_flags}', - '-L %{lib} -lunwind' -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} --prepend_env PATH=%{lib} -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-static.cfg.in b/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-static.cfg.in deleted file mode 100644 index 194fa4f18f0e57..00000000000000 --- a/src/native/external/llvm-libunwind/test/configs/llvm-libunwind-static.cfg.in +++ /dev/null @@ -1,51 +0,0 @@ -# -# Configuration file for running the libunwind tests against the static library. -# - -lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') - -compile_flags = [] -link_flags = [] - -if @LIBUNWIND_ENABLE_THREADS@: - link_flags.append('-lpthread') - -if @LIBUNWIND_ENABLE_CET@: - compile_flags.append('-fcf-protection=full') - -if @LIBUNWIND_ENABLE_GCS@: - compile_flags.append('-mbranch-protection=standard') - -# On ELF platforms, link tests with -Wl,--export-dynamic if supported by the linker. -if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'): - link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@') - -if '@CMAKE_DL_LIBS@': - link_flags.append('-l@CMAKE_DL_LIBS@') - -# Stack unwinding tests need unwinding tables and these are not generated by default on all targets. -compile_flags.append('-funwind-tables') - -local_sysroot = '@CMAKE_OSX_SYSROOT@' or '@CMAKE_SYSROOT@' -config.substitutions.append(('%{flags}', - '-isysroot {}'.format(local_sysroot) if local_sysroot else '' -)) -config.substitutions.append(('%{compile_flags}', - '-nostdinc++ -I %{{include}} {}'.format(' '.join(compile_flags)) -)) -config.substitutions.append(('%{link_flags}', - '%{{lib}}/libunwind.a {}'.format(' '.join(link_flags)) -)) -config.substitutions.append(('%{exec}', - '%{executor} --execdir %{temp} -- ' -)) - -import os, site -site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils')) -import libcxx.test.params, libcxx.test.config -libcxx.test.config.configure( - libcxx.test.params.DEFAULT_PARAMETERS, - libcxx.test.features.DEFAULT_FEATURES, - config, - lit_config -) diff --git a/src/native/external/llvm-libunwind/test/eh_frame_fde_pc_range.pass.cpp b/src/native/external/llvm-libunwind/test/eh_frame_fde_pc_range.pass.cpp deleted file mode 100644 index 32ddb769e6dcea..00000000000000 --- a/src/native/external/llvm-libunwind/test/eh_frame_fde_pc_range.pass.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Manually marking the .eh_frame_hdr as DW_EH_PE_omit to make libunwind to do -// the linear search. -// Assuming the begining of the function is at the start of the FDE range. - -// clang-format off - -// REQUIRES: target={{x86_64-.+}} -// REQUIRES: objcopy-available -// UNSUPPORTED: target={{.*-windows.*}} -// UNSUPPORTED: target={{.*-apple.*}} - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -// RUN: %{build} -// RUN: %{objcopy} --dump-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe -// RUN: printf '\377' | dd of=%t_ehf_hdr.bin bs=1 seek=2 count=2 conv=notrunc status=none -// RUN: %{objcopy} --update-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe -// RUN: %{exec} %t.exe - -// clang-format on - -#include -#include -#include -#include -#include - -void f() { - printf("123\n"); - void *pc = __builtin_return_address(0); - void *fpc = (void *)&f; - void *fpc1 = (void *)((uintptr_t)fpc + 1); - - struct dwarf_eh_bases bases; - const void *fde_pc = _Unwind_Find_FDE(pc, &bases); - const void *fde_fpc = _Unwind_Find_FDE(fpc, &bases); - const void *fde_fpc1 = _Unwind_Find_FDE(fpc1, &bases); - printf("fde_pc = %p\n", fde_pc); - printf("fde_fpc = %p\n", fde_fpc); - printf("fde_fpc1 = %p\n", fde_fpc1); - fflush(stdout); - assert(fde_pc != NULL); - assert(fde_fpc != NULL); - assert(fde_fpc1 != NULL); - assert(fde_fpc == fde_fpc1); -} - -int main(int, char **) { - f(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/floatregister.pass.cpp b/src/native/external/llvm-libunwind/test/floatregister.pass.cpp deleted file mode 100644 index 6be3e1f3f7385f..00000000000000 --- a/src/native/external/llvm-libunwind/test/floatregister.pass.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// REQUIRES: target={{aarch64-.+}} -// UNSUPPORTED: target={{.*-windows.*}} - -// Basic test for float registers number are accepted. - -#include -#include -#include - -// Using __attribute__((section("main_func"))) is ELF specific, but then -// this entire test is marked as requiring Linux, so we should be good. -// -// We don't use dladdr() because on musl it's a no-op when statically linked. -extern char __start_main_func; -extern char __stop_main_func; - -_Unwind_Reason_Code frame_handler(struct _Unwind_Context *ctx, void *arg) { - (void)arg; - - // Unwind until the main is reached, above frames depend on the platform and - // architecture. - uintptr_t ip = _Unwind_GetIP(ctx); - if (ip >= (uintptr_t)&__start_main_func && - ip < (uintptr_t)&__stop_main_func) { - _Exit(0); - } - - return _URC_NO_REASON; -} - -__attribute__((noinline)) void foo() { - // Provide some CFI directives that instructs the unwinder where given - // float register is. -#if defined(__aarch64__) - // DWARF register number for V0-V31 registers are 64-95. - // Previous value of V0 is saved at offset 0 from CFA. - asm volatile(".cfi_offset 64, 0"); - // From now on the previous value of register can't be restored anymore. - asm volatile(".cfi_undefined 65"); - asm volatile(".cfi_undefined 95"); - // Previous value of V2 is in V30. - asm volatile(".cfi_register 66, 94"); -#endif - _Unwind_Backtrace(frame_handler, NULL); -} - -__attribute__((section("main_func"))) int main(int, char **) { - foo(); - return -2; -} diff --git a/src/native/external/llvm-libunwind/test/forceunwind.pass.cpp b/src/native/external/llvm-libunwind/test/forceunwind.pass.cpp deleted file mode 100644 index e5437c31a0f656..00000000000000 --- a/src/native/external/llvm-libunwind/test/forceunwind.pass.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: target={{.*-apple.*}} -// UNSUPPORTED: target={{.*-aix.*}} -// UNSUPPORTED: target={{.*-windows.*}} - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -// Basic test for _Unwind_ForcedUnwind. -// See libcxxabi/test/forced_unwind* tests too. - -#undef NDEBUG -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Using __attribute__((section("main_func"))) is Linux specific, but then -// this entire test is marked as requiring Linux, so we should be good. -// -// We don't use dladdr() because on musl it's a no-op when statically linked. -extern char __start_main_func; -extern char __stop_main_func; - -void foo(); -_Unwind_Exception ex; - -_Unwind_Reason_Code stop(int version, _Unwind_Action actions, - _Unwind_Exception_Class exceptionClass, - _Unwind_Exception *exceptionObject, - struct _Unwind_Context *context, - void *stop_parameter) { - assert(version == 1); - assert((actions & _UA_FORCE_UNWIND) != 0); - (void)exceptionClass; - assert(exceptionObject == &ex); - assert(stop_parameter == &foo); - - // Unwind until the main is reached, above frames depend on the platform and - // architecture. - uintptr_t ip = _Unwind_GetIP(context); - if (ip >= (uintptr_t)&__start_main_func && - ip < (uintptr_t)&__stop_main_func) { - _Exit(0); - } - - return _URC_NO_REASON; -} - -__attribute__((noinline)) void foo() { - - // Arm EHABI defines struct _Unwind_Control_Block as exception - // object. Ensure struct _Unwind_Exception* work there too, - // because _Unwind_Exception in this case is just an alias. - struct _Unwind_Exception *e = &ex; -#if defined(_LIBUNWIND_ARM_EHABI) - // Create a mock exception object. - memset(e, '\0', sizeof(*e)); - memcpy(&e->exception_class, "CLNGUNW", sizeof(e->exception_class)); -#endif - _Unwind_ForcedUnwind(e, stop, (void *)&foo); -} - -__attribute__((section("main_func"))) int main(int, char **) { - foo(); - return -2; -} diff --git a/src/native/external/llvm-libunwind/test/frameheadercache_test.pass.cpp b/src/native/external/llvm-libunwind/test/frameheadercache_test.pass.cpp deleted file mode 100644 index 6b648e72849149..00000000000000 --- a/src/native/external/llvm-libunwind/test/frameheadercache_test.pass.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// The other libunwind tests don't test internal interfaces, so the include path -// is a little wonky. -#include "../src/config.h" - -// Only run this test under supported configurations. - -#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ - defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) - -#include -#include - -// This file defines several of the data structures needed here, -// and includes FrameHeaderCache.hpp as well. -#include "../src/AddressSpace.hpp" - -#define kBaseAddr 0xFFF000 -#define kTextSegmentLength 0xFF - -using namespace libunwind; - -int main(int, char**) { - FrameHeaderCache FHC; - struct dl_phdr_info PInfo; - memset(&PInfo, 0, sizeof(PInfo)); - // The cache itself should only care about these two fields--they - // tell the cache to invalidate or not; everything else is handled - // by AddressSpace.hpp. - PInfo.dlpi_adds = 6; - PInfo.dlpi_subs = 7; - - UnwindInfoSections UIS; - UIS.dso_base = kBaseAddr; - UIS.text_segment_length = kTextSegmentLength; - dl_iterate_cb_data CBData; - // Unused by the cache. - CBData.addressSpace = nullptr; - CBData.sects = &UIS; - CBData.targetAddr = kBaseAddr + 1; - - // Nothing present, shouldn't find. - if (FHC.find(&PInfo, 0, &CBData)) - abort(); - FHC.add(&UIS); - // Just added. Should find. - if (!FHC.find(&PInfo, 0, &CBData)) - abort(); - // Cache is invalid. Shouldn't find. - PInfo.dlpi_adds++; - if (FHC.find(&PInfo, 0, &CBData)) - abort(); - - FHC.add(&UIS); - CBData.targetAddr = kBaseAddr - 1; - // Shouldn't find something outside of the addresses. - if (FHC.find(&PInfo, 0, &CBData)) - abort(); - // Add enough things to the cache that the entry is evicted. - for (int i = 0; i < 9; i++) { - UIS.dso_base = kBaseAddr + (kTextSegmentLength * i); - FHC.add(&UIS); - } - CBData.targetAddr = kBaseAddr; - // Should have been evicted. - if (FHC.find(&PInfo, 0, &CBData)) - abort(); - return 0; -} - -#else -int main(int, char**) { return 0;} -#endif diff --git a/src/native/external/llvm-libunwind/test/libunwind_01.pass.cpp b/src/native/external/llvm-libunwind/test/libunwind_01.pass.cpp deleted file mode 100644 index 838df6b5897204..00000000000000 --- a/src/native/external/llvm-libunwind/test/libunwind_01.pass.cpp +++ /dev/null @@ -1,168 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// TODO: Investigate this failure on x86_64 macOS back deployment -// XFAIL: stdlib=system && target=x86_64-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}} - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -#include -#include -#include -#include - -void backtrace(int lower_bound) { - unw_context_t context; - unw_getcontext(&context); - - unw_cursor_t cursor; - unw_init_local(&cursor, &context); - - char buffer[1024]; - unw_word_t offset = 0; - - int n = 0; - do { - n++; - if (unw_get_proc_name(&cursor, buffer, sizeof(buffer), &offset) == 0) { - fprintf(stderr, "Frame %d: %s+%p\n", n, buffer, (void*)offset); - } else { - fprintf(stderr, "Frame %d: Could not get name for cursor\n", n); - } - if (n > 100) { - abort(); - } - } while (unw_step(&cursor) > 0); - - if (n < lower_bound) { - abort(); - } -} - -__attribute__((noinline)) void test1(int i) { - fprintf(stderr, "starting %s\n", __func__); - backtrace(i); - fprintf(stderr, "finished %s\n", __func__); // ensure return address is saved -} - -__attribute__((noinline)) void test2(int i, int j) { - fprintf(stderr, "starting %s\n", __func__); - backtrace(i); - test1(j); - fprintf(stderr, "finished %s\n", __func__); // ensure return address is saved -} - -__attribute__((noinline)) void test3(int i, int j, int k) { - fprintf(stderr, "starting %s\n", __func__); - backtrace(i); - test2(j, k); - fprintf(stderr, "finished %s\n", __func__); // ensure return address is saved -} - -void test_no_info() { - unw_context_t context; - unw_getcontext(&context); - - unw_cursor_t cursor; - unw_init_local(&cursor, &context); - - unw_proc_info_t info; - int ret = unw_get_proc_info(&cursor, &info); - if (ret != UNW_ESUCCESS) - abort(); - - // Set the IP to an address clearly outside any function. - unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)0); - - ret = unw_get_proc_info(&cursor, &info); - if (ret != UNW_ENOINFO) - abort(); -} - -void test_reg_names() { - unw_context_t context; - unw_getcontext(&context); - - unw_cursor_t cursor; - unw_init_local(&cursor, &context); - - int max_reg_num = -100; -#if defined(__i386__) - max_reg_num = 7; -#elif defined(__x86_64__) - max_reg_num = 32; -#endif - - const char prefix[] = "unknown"; - for (int i = -2; i < max_reg_num; ++i) { - if (strncmp(prefix, unw_regname(&cursor, i), sizeof(prefix) - 1) == 0) - abort(); - } - - if (strncmp(prefix, unw_regname(&cursor, max_reg_num + 1), - sizeof(prefix) - 1) != 0) - abort(); -} - -#if defined(__x86_64__) -void test_reg_get_set() { - unw_context_t context; - unw_getcontext(&context); - - unw_cursor_t cursor; - unw_init_local(&cursor, &context); - - for (int i = 0; i < 17; ++i) { - const unw_word_t set_value = 7; - if (unw_set_reg(&cursor, i, set_value) != UNW_ESUCCESS) - abort(); - - unw_word_t get_value = 0; - if (unw_get_reg(&cursor, i, &get_value) != UNW_ESUCCESS) - abort(); - - if (set_value != get_value) - abort(); - } -} - -void test_fpreg_get_set() { - unw_context_t context; - unw_getcontext(&context); - - unw_cursor_t cursor; - unw_init_local(&cursor, &context); - - // get/set is not implemented for x86_64 fpregs. - for (int i = 17; i < 33; ++i) { - const unw_fpreg_t set_value = 7; - if (unw_set_fpreg(&cursor, i, set_value) != UNW_EBADREG) - abort(); - - unw_fpreg_t get_value = 0; - if (unw_get_fpreg(&cursor, i, &get_value) != UNW_EBADREG) - abort(); - } -} -#else -void test_reg_get_set() {} -void test_fpreg_get_set() {} -#endif - -int main(int, char**) { - test1(3); - test2(3, 4); - test3(3, 4, 5); - test_no_info(); - test_reg_names(); - test_reg_get_set(); - test_fpreg_get_set(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/libunwind_02.pass.cpp b/src/native/external/llvm-libunwind/test/libunwind_02.pass.cpp deleted file mode 100644 index 9fd8e5d7159c96..00000000000000 --- a/src/native/external/llvm-libunwind/test/libunwind_02.pass.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -// This test fails on older llvm, when built with picolibc. -// XFAIL: clang-16 && LIBCXX-PICOLIBC-FIXME - -#undef NDEBUG -#include -#include -#include - -#define EXPECTED_NUM_FRAMES 50 -#define NUM_FRAMES_UPPER_BOUND 100 - -__attribute__((noinline)) _Unwind_Reason_Code callback(_Unwind_Context *context, - void *cnt) { - (void)context; - int *i = (int *)cnt; - ++*i; - if (*i > NUM_FRAMES_UPPER_BOUND) { - abort(); - } - return _URC_NO_REASON; -} - -__attribute__((noinline)) void test_backtrace() { - int n = 0; - _Unwind_Backtrace(&callback, &n); - if (n < EXPECTED_NUM_FRAMES) { - abort(); - } -} - -// These functions are effectively the same, but we have to be careful to avoid -// unwanted optimizations that would mess with the number of frames we expect. -// Surprisingly, slapping `noinline` is not sufficient -- we also have to avoid -// writing the function in a way that the compiler can easily spot tail -// recursion. -__attribute__((noinline)) int test1(int i); -__attribute__((noinline)) int test2(int i); - -__attribute__((noinline)) int test1(int i) { - if (i == 0) { - test_backtrace(); - return 0; - } else { - return i + test2(i - 1); - } -} - -__attribute__((noinline)) int test2(int i) { - if (i == 0) { - test_backtrace(); - return 0; - } else { - return i + test1(i - 1); - } -} - -int main(int, char**) { - int total = test1(50); - assert(total == 1275); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/lit.cfg.py b/src/native/external/llvm-libunwind/test/lit.cfg.py deleted file mode 100644 index 51e85e489db01f..00000000000000 --- a/src/native/external/llvm-libunwind/test/lit.cfg.py +++ /dev/null @@ -1,12 +0,0 @@ -# All the Lit configuration is handled in the site configs -- this file is only -# left as a canary to catch invocations of Lit that do not go through llvm-lit. -# -# Invocations that go through llvm-lit will automatically use the right Lit -# site configuration inside the build directory. - -lit_config.fatal( - "You seem to be running Lit directly -- you should be running Lit through " - "/bin/llvm-lit, which will ensure that the right Lit configuration " - "file is used. See https://libcxx.llvm.org/TestingLibcxx.html#usage for " - "how to run the libunwind tests." -) diff --git a/src/native/external/llvm-libunwind/test/remember_state_leak.pass.sh.s b/src/native/external/llvm-libunwind/test/remember_state_leak.pass.sh.s deleted file mode 100644 index 69be3f95955153..00000000000000 --- a/src/native/external/llvm-libunwind/test/remember_state_leak.pass.sh.s +++ /dev/null @@ -1,71 +0,0 @@ -#===------------------------------------------------------------------------===# -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===------------------------------------------------------------------------===# - -# REQUIRES: target={{x86_64-.+}} -# UNSUPPORTED: target={{.*-windows.*}} -# UNSUPPORTED: target={{.*-apple.*}} - -# Inline assembly isn't supported by Memory Sanitizer -# UNSUPPORTED: msan - -# RUN: %{build} -no-pie -# RUN: %{run} - -# The following assembly is a translation of this code: -# -# _Unwind_Reason_Code callback(int, _Unwind_Action, long unsigned int, -# _Unwind_Exception*, _Unwind_Context*, void*) { -# return _Unwind_Reason_Code(0); -# } -# -# int main() { -# asm(".cfi_remember_state\n\t"); -# _Unwind_Exception exc; -# _Unwind_ForcedUnwind(&exc, callback, 0); -# asm(".cfi_restore_state\n\t"); -# } -# -# When unwinding, the CFI parser will stop parsing opcodes after the current PC, -# so in this case the DW_CFA_restore_state opcode will never be processed and, -# if the library doesn't clean up properly, the store allocated by -# DW_CFA_remember_state will be leaked. -# -# This test will fail when linked with an asan-enabled libunwind if the -# remembered state is leaked. - - SIZEOF_UNWIND_EXCEPTION = 32 - - .att_syntax - .text -callback: - xorl %eax, %eax - retq - - .globl main # -- Begin function main - .p2align 4, 0x90 - .type main,@function -main: # @main - .cfi_startproc - subq $8, %rsp # Adjust stack alignment - subq $SIZEOF_UNWIND_EXCEPTION, %rsp - .cfi_def_cfa_offset 48 - .cfi_remember_state - movq %rsp, %rdi - movabsq $callback, %rsi - xorl %edx, %edx - callq _Unwind_ForcedUnwind - .cfi_restore_state - xorl %eax, %eax - addq $SIZEOF_UNWIND_EXCEPTION, %rsp - addq $8, %rsp # Undo stack alignment adjustment - .cfi_def_cfa_offset 8 - retq -.Lfunc_end1: - .size main, .Lfunc_end1-main - .cfi_endproc - # -- End function diff --git a/src/native/external/llvm-libunwind/test/signal_frame.pass.cpp b/src/native/external/llvm-libunwind/test/signal_frame.pass.cpp deleted file mode 100644 index 004029cfe1e90b..00000000000000 --- a/src/native/external/llvm-libunwind/test/signal_frame.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Ensure that functions marked as signal frames are reported as such. - -// TODO: Investigate this failure on Apple -// XFAIL: target={{.+}}-apple-{{.+}} - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -// UNSUPPORTED: libunwind-arm-ehabi - -// The AIX assembler does not support CFI directives, which -// are necessary to run this test. -// UNSUPPORTED: target={{.*}}-aix{{.*}} - -// Windows doesn't generally use CFI directives. However, i686 -// mingw targets do use DWARF (where CFI directives are supported). -// UNSUPPORTED: target={{x86_64|arm.*|aarch64}}-{{.*}}-windows-{{.*}} - -#undef NDEBUG -#include -#include -#include - -void test() { - asm(".cfi_signal_frame"); - unw_cursor_t cursor; - unw_context_t uc; - unw_getcontext(&uc); - unw_init_local(&cursor, &uc); - assert(unw_step(&cursor) > 0); - assert(unw_is_signal_frame(&cursor)); -} - -int main(int, char**) { - test(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/signal_unwind.pass.cpp b/src/native/external/llvm-libunwind/test/signal_unwind.pass.cpp deleted file mode 100644 index ca50f83964c118..00000000000000 --- a/src/native/external/llvm-libunwind/test/signal_unwind.pass.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Ensure that the unwinder can cope with the signal handler. -// REQUIRES: target={{(aarch64|loongarch64|riscv64|s390x|x86_64)-.+}} -// UNSUPPORTED: target={{.*-windows.*}} -// UNSUPPORTED: target={{.*-apple.*}} - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -// Note: this test fails on musl because: -// -// (a) musl disables emission of unwind information for its build, and -// (b) musl's signal trampolines don't include unwind information -// -// XFAIL: target={{.*}}-musl - -#undef NDEBUG -#include -#include -#include -#include -#include -#include -#include -#include - -// Using __attribute__((section("main_func"))) is ELF specific, but then -// this entire test is marked as requiring Linux, so we should be good. -// -// We don't use dladdr() because on musl it's a no-op when statically linked. -extern char __start_main_func; -extern char __stop_main_func; - -_Unwind_Reason_Code frame_handler(struct _Unwind_Context* ctx, void* arg) { - (void)arg; - - // Unwind until the main is reached, above frames depend on the platform and - // architecture. - uintptr_t ip = _Unwind_GetIP(ctx); - if (ip >= (uintptr_t)&__start_main_func && - ip < (uintptr_t)&__stop_main_func) { - _Exit(0); - } - - return _URC_NO_REASON; -} - -void signal_handler(int signum) { - (void)signum; - _Unwind_Backtrace(frame_handler, NULL); - _Exit(-1); -} - -__attribute__((section("main_func"))) int main(int, char **) { - signal(SIGUSR1, signal_handler); - kill(getpid(), SIGUSR1); - return -2; -} diff --git a/src/native/external/llvm-libunwind/test/unw_getcontext.pass.cpp b/src/native/external/llvm-libunwind/test/unw_getcontext.pass.cpp deleted file mode 100644 index 95ffcf123267f0..00000000000000 --- a/src/native/external/llvm-libunwind/test/unw_getcontext.pass.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#undef NDEBUG -#include -#include - -int main(int, char**) { - unw_context_t context; - int ret = unw_getcontext(&context); - assert(ret == UNW_ESUCCESS); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/unw_resume.pass.cpp b/src/native/external/llvm-libunwind/test/unw_resume.pass.cpp deleted file mode 100644 index e1f40b4a42e947..00000000000000 --- a/src/native/external/llvm-libunwind/test/unw_resume.pass.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Ensure that unw_resume() resumes execution at the stack frame identified by -// cursor. - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -#include - -__attribute__((noinline)) void test_unw_resume() { - unw_context_t context; - unw_cursor_t cursor; - - unw_getcontext(&context); - unw_init_local(&cursor, &context); - unw_step(&cursor); - unw_resume(&cursor); -} - -int main(int, char **) { - test_unw_resume(); - return 0; -} diff --git a/src/native/external/llvm-libunwind/test/unwind_leaffunction.pass.cpp b/src/native/external/llvm-libunwind/test/unwind_leaffunction.pass.cpp deleted file mode 100644 index af791a6b2ed313..00000000000000 --- a/src/native/external/llvm-libunwind/test/unwind_leaffunction.pass.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// Ensure that leaf function can be unwund. -// REQUIRES: target={{(aarch64|loongarch64|riscv64|s390x|x86_64)-.+}} -// UNSUPPORTED: target={{.*-windows.*}} -// UNSUPPORTED: target={{.*-apple.*}} - -// TODO: Figure out why this fails with Memory Sanitizer. -// XFAIL: msan - -// Note: this test fails on musl because: -// -// (a) musl disables emission of unwind information for its build, and -// (b) musl's signal trampolines don't include unwind information -// -// XFAIL: target={{.*}}-musl - -#undef NDEBUG -#include -#include -#include -#include -#include -#include -#include -#include - -// Using __attribute__((section("main_func"))) is ELF specific, but then -// this entire test is marked as requiring Linux, so we should be good. -// -// We don't use dladdr() because on musl it's a no-op when statically linked. -extern char __start_main_func; -extern char __stop_main_func; - -_Unwind_Reason_Code frame_handler(struct _Unwind_Context* ctx, void* arg) { - (void)arg; - - // Unwind until the main is reached, above frames depend on the platform and - // architecture. - uintptr_t ip = _Unwind_GetIP(ctx); - if (ip >= (uintptr_t)&__start_main_func && - ip < (uintptr_t)&__stop_main_func) { - _Exit(0); - } - - return _URC_NO_REASON; -} - -void signal_handler(int signum) { - (void)signum; - _Unwind_Backtrace(frame_handler, NULL); - _Exit(-1); -} - -__attribute__((noinline)) void crashing_leaf_func(int do_trap) { - // libunwind searches for the address before the return address which points - // to the trap instruction. We make the trap conditional and prevent inlining - // of the function to ensure that the compiler doesn't remove the `ret` - // instruction altogether. - // - // It's also important that the trap instruction isn't the first instruction - // in the function (which it isn't because of the branch) for other unwinders - // that also decrement pc. - if (do_trap) - __builtin_trap(); -} - -__attribute__((section("main_func"))) int main(int, char **) { - signal(SIGTRAP, signal_handler); - signal(SIGILL, signal_handler); - crashing_leaf_func(1); - return -2; -} diff --git a/src/native/external/llvm-libunwind/test/unwind_scalable_vectors.pass.cpp b/src/native/external/llvm-libunwind/test/unwind_scalable_vectors.pass.cpp deleted file mode 100644 index 38d8bd5e002d14..00000000000000 --- a/src/native/external/llvm-libunwind/test/unwind_scalable_vectors.pass.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// REQUIRES: target={{riscv64-.+}} - -#undef NDEBUG -#include -#include - -#ifdef __riscv_vector -__attribute__((noinline)) extern "C" void stepper() { - unw_cursor_t cursor; - unw_context_t uc; - unw_getcontext(&uc); - unw_init_local(&cursor, &uc); - // Stepping into foo() should succeed. - assert(unw_step(&cursor) > 0); - // Stepping past foo() should succeed, too. - assert(unw_step(&cursor) > 0); -} - -// Check correct unwinding of frame with VLENB-sized objects (vector registers). -__attribute__((noinline)) static void foo() { - __rvv_int32m1_t v; - asm volatile("" : "=vr"(v)); // Dummy inline asm to def v. - stepper(); // def-use of v has cross the function, so that - // will triger spill/reload to/from the stack. - asm volatile("" ::"vr"(v)); // Dummy inline asm to use v. -} - -int main(int, char **) { - foo(); - return 0; -} -#else -int main(int, char **) { return 0; } -#endif