Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ void Registers_REGDISPLAY::setFloatRegister(int num, unw_fpreg_t value)
// Shim that implements methods required by libunwind over REGDISPLAY
struct Registers_REGDISPLAY : REGDISPLAY
{
typedef uint64_t reg_t;

inline static int getArch() { return libunwind::REGISTERS_ARM64; }
static constexpr int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64; }

Expand Down
6 changes: 3 additions & 3 deletions src/native/external/llvm-libunwind-version.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v20.1.0
https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.0
v22.1.1
https://github.com/llvm/llvm-project/releases/tag/llvmorg-22.1.1

Apply https://github.com/dotnet/runtime/commit/d03d1ba7835fdf9e2a6bb537d49fb5ff6584697b
Apply https://github.com/dotnet/runtime/commit/35b7d59fa1075ab0fefb921393409806a821d8ed
10 changes: 10 additions & 0 deletions src/native/external/llvm-libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
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.")
Expand Down Expand Up @@ -181,6 +182,8 @@ include(HandleLibunwindFlags)
# 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()
Expand Down Expand Up @@ -329,6 +332,13 @@ if (C_SUPPORTS_COMMENT_LIB_PRAGMA)
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
#===============================================================================
Expand Down
56 changes: 0 additions & 56 deletions src/native/external/llvm-libunwind/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,6 @@ if (NOT LIBUNWIND_USE_COMPILER_RT)
endif ()
endif()

# libunwind is using -nostdlib++ at the link step when available,
# otherwise -nodefaultlibs is used. We want all our checks to also
# use one of these options, otherwise we may end up with an inconsistency between
# the flags we think we require during configuration (if the checks are
# performed without one of those options) and the flags that are actually
# required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
# required for the link to go through. We remove sanitizers from the
# configuration checks to avoid spurious link errors.

llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
else()
llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
endif()
endif()

# Only link against compiler-rt manually if we use -nodefaultlibs, since
# otherwise the compiler will do the right thing on its own.
if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
if (LIBUNWIND_HAS_C_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES c)
endif ()
if (LIBUNWIND_HAS_ROOT_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES root)
endif ()
if (LIBUNWIND_USE_COMPILER_RT)
include(HandleCompilerRT)
find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY
FLAGS ${LIBUNWIND_COMPILE_FLAGS})
list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
else ()
if (LIBUNWIND_HAS_GCC_S_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
endif ()
if (LIBUNWIND_HAS_GCC_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
endif ()
endif ()
if (MINGW)
# Mingw64 requires quite a few "C" runtime libraries in order for basic
# programs to link successfully with -nodefaultlibs.
if (LIBUNWIND_USE_COMPILER_RT)
set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY})
else ()
set(MINGW_RUNTIME gcc_s gcc)
endif()
set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
moldname mingwex msvcrt)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ libunwind specific options

.. option:: LIBUNWIND_ENABLE_WERROR:BOOL

**Default**: ``ON``
**Default**: ``OFF``

Compile with -Werror

Expand Down
6 changes: 2 additions & 4 deletions src/native/external/llvm-libunwind/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ if(LIBUNWIND_INSTALL_HEADERS)
)
endforeach()

if(NOT CMAKE_CONFIGURATION_TYPES)
if (NOT CMAKE_CONFIGURATION_TYPES)
add_custom_target(install-unwind-headers
DEPENDS unwind-headers
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_INSTALL_COMPONENT=unwind-headers
-P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind-headers)
add_custom_target(install-unwind-headers-stripped DEPENDS install-unwind-headers)
endif()
endif()
17 changes: 15 additions & 2 deletions src/native/external/llvm-libunwind/include/__libunwind_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# if defined(__i386__)
# define _LIBUNWIND_TARGET_I386
# define _LIBUNWIND_CONTEXT_SIZE 13
# define _LIBUNWIND_CURSOR_SIZE 20
# define _LIBUNWIND_CURSOR_SIZE 19
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86
# elif defined(__x86_64__)
# define _LIBUNWIND_TARGET_X86_64 1
Expand Down Expand Up @@ -178,13 +178,17 @@
#if __loongarch_grlen == 64
#define _LIBUNWIND_CONTEXT_SIZE 98
#define _LIBUNWIND_CURSOR_SIZE 110
#elif defined(HOST_WASM)
#define _LIBUNWIND_TARGET_WASM 1
// TODO: Determine the right values
#define _LIBUNWIND_CONTEXT_SIZE 0xbadf00d
#define _LIBUNWIND_CURSOR_SIZE 0xbadf00d
#else
#error "Unsupported LoongArch ABI"
#endif
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
_LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
#elif defined(__wasm__)
#define _LIBUNWIND_TARGET_WASM 1
// Unused
#define _LIBUNWIND_CONTEXT_SIZE 0
#define _LIBUNWIND_CURSOR_SIZE 0
Expand Down Expand Up @@ -213,4 +217,13 @@
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 287
#endif // _LIBUNWIND_IS_NATIVE_ONLY

#if defined(__has_feature)
# if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
# define _LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING 1
# elif __has_feature(ptrauth_calls) != __has_feature(ptrauth_returns)
# error "Either both or none of ptrauth_calls and ptrauth_returns "\
"is allowed to be enabled"
# endif
#endif

#endif // ____LIBUNWIND_CONFIG_H__
128 changes: 117 additions & 11 deletions src/native/external/llvm-libunwind/include/libunwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,109 @@
#define LIBUNWIND_AVAIL
#endif

#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)

#include <ptrauth.h>

// `__ptrauth_restricted_intptr` is a feature of apple clang that predates
// support for direct application of `__ptrauth` to integer types. This
// guard is necessary to support compilation with those compiler.
#if __has_extension(ptrauth_restricted_intptr_qualifier)
#define __unwind_ptrauth_restricted_intptr(...) \
__ptrauth_restricted_intptr(__VA_ARGS__)
#else
#define __unwind_ptrauth_restricted_intptr(...) \
__ptrauth(__VA_ARGS__)
#endif

// ptrauth_string_discriminator("unw_proc_info_t::handler") == 0x7405
#define __ptrauth_unwind_upi_handler_disc 0x7405

#define __ptrauth_unwind_upi_handler \
__ptrauth(ptrauth_key_function_pointer, 1, __ptrauth_unwind_upi_handler_disc)

#define __ptrauth_unwind_upi_handler_intptr \
__unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1,\
__ptrauth_unwind_upi_handler_disc)

// ptrauth_string_discriminator("unw_proc_info_t::start_ip") == 0xCA2C
#define __ptrauth_unwind_upi_startip \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_independent_code, 1, 0xCA2C)

// ptrauth_string_discriminator("unw_proc_info_t::end_ip") == 0xE183
#define __ptrauth_unwind_upi_endip \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_independent_code, 1, 0xE183)

// ptrauth_string_discriminator("unw_proc_info_t::lsda") == 0x83DE
#define __ptrauth_unwind_upi_lsda \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x83DE)

// ptrauth_string_discriminator("unw_proc_info_t::flags") == 0x79A1
#define __ptrauth_unwind_upi_flags \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x79A1)

// ptrauth_string_discriminator("unw_proc_info_t::unwind_info") == 0xC20C
#define __ptrauth_unwind_upi_info \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0xC20C)

// ptrauth_string_discriminator("unw_proc_info_t::extra") == 0x03DF
#define __ptrauth_unwind_upi_extra \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x03DF)

// ptrauth_string_discriminator("Registers_arm64::link_reg_t") == 0x8301
#define __ptrauth_unwind_registers_arm64_link_reg \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_code, 1, 0x8301)

// ptrauth_string_discriminator("UnwindInfoSections::dso_base") == 0x4FF5
#define __ptrauth_unwind_uis_dso_base \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x4FF5)

// ptrauth_string_discriminator("UnwindInfoSections::dwarf_section") == 0x4974
#define __ptrauth_unwind_uis_dwarf_section \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x4974)

// ptrauth_string_discriminator("UnwindInfoSections::dwarf_section_length") == 0x2A9A
#define __ptrauth_unwind_uis_dwarf_section_length \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x2A9A)

// ptrauth_string_discriminator("UnwindInfoSections::compact_unwind_section") == 0xA27B
#define __ptrauth_unwind_uis_compact_unwind_section \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0xA27B)

// ptrauth_string_discriminator("UnwindInfoSections::compact_unwind_section_length") == 0x5D0A
#define __ptrauth_unwind_uis_compact_unwind_section_length \
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x5D0A)

// ptrauth_string_discriminator("CIE_Info::personality") == 0x6A40
#define __ptrauth_unwind_cie_info_personality_disc 0x6A40
#define __ptrauth_unwind_cie_info_personality \
__unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1, \
__ptrauth_unwind_cie_info_personality_disc)

// ptrauth_string_discriminator("personality") == 0x7EAD)
#define __ptrauth_unwind_pauthtest_personality_disc 0x7EAD

#else

#define __unwind_ptrauth_restricted_intptr(...)
#define __ptrauth_unwind_upi_handler
#define __ptrauth_unwind_upi_handler_intptr
#define __ptrauth_unwind_upi_startip
#define __ptrauth_unwind_upi_endip
#define __ptrauth_unwind_upi_lsda
#define __ptrauth_unwind_upi_flags
#define __ptrauth_unwind_upi_info
#define __ptrauth_unwind_upi_extra
#define __ptrauth_unwind_registers_arm64_link_reg
#define __ptrauth_unwind_uis_dso_base
#define __ptrauth_unwind_uis_dwarf_section
#define __ptrauth_unwind_uis_dwarf_section_length
#define __ptrauth_unwind_uis_compact_unwind_section
#define __ptrauth_unwind_uis_compact_unwind_section_length
#define __ptrauth_unwind_cie_info_personality

#endif

#if defined(_WIN32) && defined(__SEH__)
#define LIBUNWIND_CURSOR_ALIGNMENT_ATTR __attribute__((__aligned__(16)))
#else
Expand Down Expand Up @@ -88,17 +191,18 @@ typedef double unw_fpreg_t;
#endif

struct unw_proc_info_t {
unw_word_t start_ip; /* start address of function */
unw_word_t end_ip; /* address after end of function */
unw_word_t lsda; /* address of language specific data area, */
/* or zero if not used */
unw_word_t handler; /* personality routine, or zero if not used */
unw_word_t gp; /* not used */
unw_word_t flags; /* not used */
uint32_t format; /* compact unwind encoding, or zero if none */
uint32_t unwind_info_size; /* size of DWARF unwind info, or zero if none */
unw_word_t unwind_info; /* address of DWARF unwind info, or zero */
unw_word_t extra; /* mach_header of mach-o image containing func */
unw_word_t __ptrauth_unwind_upi_startip start_ip; /* start address of function */
unw_word_t __ptrauth_unwind_upi_endip end_ip; /* address after end of function */
unw_word_t __ptrauth_unwind_upi_lsda lsda; /* address of language specific data area, */
/* or zero if not used */

unw_word_t __ptrauth_unwind_upi_handler_intptr handler;
unw_word_t gp; /* not used */
unw_word_t __ptrauth_unwind_upi_flags flags; /* not used */
uint32_t format; /* compact unwind encoding, or zero if none */
uint32_t unwind_info_size; /* size of DWARF unwind info, or zero if none */
unw_word_t __ptrauth_unwind_upi_info unwind_info; /* address of DWARF unwind info, or zero */
unw_word_t __ptrauth_unwind_upi_extra extra; /* mach_header of mach-o image containing func */
};
typedef struct unw_proc_info_t unw_proc_info_t;

Expand Down Expand Up @@ -150,6 +254,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*) LIBUNWIND_AVAIL;
extern const char *unw_strerror(int) LIBUNWIND_AVAIL;

extern unw_addr_space_t unw_local_addr_space;

Expand Down Expand Up @@ -552,6 +657,7 @@ enum {
UNW_AARCH64_X31 = 31,
UNW_AARCH64_SP = 31,
UNW_AARCH64_PC = 32,
UNW_AARCH64_VG = 46,

// reserved block
UNW_AARCH64_RA_SIGN_STATE = 34,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
uint32_t discriminator,
_Unwind_VRS_DataRepresentation representation);

extern _Unwind_Reason_Code __gnu_unwind_frame(_Unwind_Exception *,
_Unwind_Context *);

#if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE)
#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern
#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern __inline__
#else
#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__
#endif
Expand Down
Loading
Loading