Skip to content

Commit

Permalink
Apply all patches
Browse files Browse the repository at this point in the history
Extracted changes from:

* https://github.com/dotnet/corerta48e1a6702d3678e7de02d36bd689b0c96fddeaa
* https://github.com/dotnet/corertc6571c6eb7b99afec7d69cd5f52fb3c5058a2e3c
* https://github.com/dotnet/corerte6ff5433da6027767eb87d7e0891bacddd87645a
* https://github.com/dotnet/corert4009f5aa449933468487c430a452fe81494f6d46
* https://github.com/dotnet/corert94f2d8ea3943f7e90cda86ae7b7cb47d3da5a53a
* https://github.com/dotnet/corert753c19b595773f4fabbba09ef184385324271d45
* https://github.com/dotnet/corert3d25db5b1c010346bbc480a20646c80ea413492f
* https://github.com/dotnet/corert3d25db5b1c010346bbc480a20646c80ea413492f
* https://github.com/dotnet/corert1bd9c3c2472e656d7e2c90b2c8273e99469faf05
* https://github.com/dotnet/corertb65389a856901b93d8d75851341a79b17ca5e745
* https://github.com/dotnet/corertd56451ee402459a23ff28fe1eff672d131468580
* https://github.com/dotnet/corertb059615c47caf5e06a694fa5e846504a808919a5
* https://github.com/dotnet/corertb059615c47caf5e06a694fa5e846504a808919a5
* https://github.com/dotnet/corert8157d14c1d82f1dbdb90e654dbc5cacdd74319e7
* https://github.com/dotnet/corertfd57cf11b863f9478788e5435fd4b92883a08b23
* https://github.com/dotnet/corertf528e70ce0df27c8609df1c68f3c942c63f1b1d4
* https://github.com/dotnet/corertccda70afb67ca55e297e68f8e96a10a903dcbee4
* https://github.com/dotnet/corert180a175405d76c83e48499a3eebabb952f7133d2
* https://github.com/dotnet/corertf2526602b0fd2897f9c0cbc637c322c8a167eb80
* https://github.com/dotnet/corertf2526602b0fd2897f9c0cbc637c322c8a167eb80
* https://github.com/dotnet/corert68d8ec9e7796865884ab281120ec220bcb284b3e
* https://github.com/dotnet/corertc01d95a7524173d7622d29b5da0a04fd0446dc32
* dotnet/corert@7f8470d
* dotnet/corert@2dfab60

* dotnet/runtimelab@a89d3cb
* dotnet/runtimelab@07bf6d3
* dotnet/runtimelab@ad25495
* dotnet/runtimelab@11e915e
* dotnet/runtimelab@666e35a
* dotnet/runtimelab@9a766d3

* 3ea30ed

Co-authored-by: RalfKornmannEnvision <[email protected]>
Co-authored-by: FabianNitsche <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
Co-authored-by: Jan Vorlicek <[email protected]>
Co-authored-by: Sergey Ignatov <[email protected]>
Co-authored-by: Morgan Brown <[email protected]>
Co-authored-by: John Doe <[email protected]>
Co-authored-by: Ivan Arishchenko <[email protected]>
Co-authored-by: Andrii Kurdiumov <[email protected]>
  • Loading branch information
10 people committed Jul 18, 2022
1 parent 7ae73fa commit 4c0ce47
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 216 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_B
endif()

set(PACKAGE_NAME libunwind)
set(PACKAGE_VERSION 9.0.0)
set(PACKAGE_VERSION 9.0.0svn)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "[email protected]")

Expand Down
25 changes: 15 additions & 10 deletions src/coreclr/nativeaot/libunwind/include/__libunwind_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#if defined(_LIBUNWIND_IS_NATIVE_ONLY)
# if defined(__i386__)
# define _LIBUNWIND_TARGET_I386
# define _LIBUNWIND_CONTEXT_SIZE 8
# define _LIBUNWIND_CURSOR_SIZE 15
# define _LIBUNWIND_CONTEXT_SIZE 13
# 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 All @@ -40,8 +40,8 @@
# define _LIBUNWIND_CURSOR_SIZE 66
# endif
# else
# define _LIBUNWIND_CONTEXT_SIZE 21
# define _LIBUNWIND_CURSOR_SIZE 33
# define _LIBUNWIND_CONTEXT_SIZE 38
# define _LIBUNWIND_CURSOR_SIZE 50
# endif
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86_64
# elif defined(__powerpc64__)
Expand All @@ -56,11 +56,11 @@
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC
# elif defined(__aarch64__)
# define _LIBUNWIND_TARGET_AARCH64 1
# define _LIBUNWIND_CONTEXT_SIZE 66
# define _LIBUNWIND_CONTEXT_SIZE 100
# if defined(__SEH__)
# define _LIBUNWIND_CURSOR_SIZE 164
# define _LIBUNWIND_CURSOR_SIZE 198
# else
# define _LIBUNWIND_CURSOR_SIZE 78
# define _LIBUNWIND_CURSOR_SIZE 112
# endif
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64
# elif defined(__arm__)
Expand All @@ -72,8 +72,8 @@
# define _LIBUNWIND_CONTEXT_SIZE 61
# define _LIBUNWIND_CURSOR_SIZE 68
# else
# define _LIBUNWIND_CONTEXT_SIZE 42
# define _LIBUNWIND_CURSOR_SIZE 49
# define _LIBUNWIND_CONTEXT_SIZE 50
# define _LIBUNWIND_CURSOR_SIZE 57
# endif
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM
# elif defined(__or1k__)
Expand Down Expand Up @@ -118,7 +118,12 @@
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC
#define _LIBUNWIND_CONTEXT_SIZE 16
#define _LIBUNWIND_CURSOR_SIZE 23
# else
#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 architecture."
# endif
#else // !_LIBUNWIND_IS_NATIVE_ONLY
Expand Down
24 changes: 22 additions & 2 deletions src/coreclr/nativeaot/libunwind/include/libunwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ struct unw_proc_info_t {
};
typedef struct unw_proc_info_t unw_proc_info_t;

enum unw_save_loc_type_t
{
UNW_SLT_NONE, /* register is not saved ("not an l-value") */
UNW_SLT_MEMORY, /* register has been saved in memory */
UNW_SLT_REG /* register has been saved in (another) register */
};
typedef enum unw_save_loc_type_t unw_save_loc_type_t;

struct unw_save_loc_t
{
unw_save_loc_type_t type;
union
{
unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */
unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */
}
u;
};
typedef struct unw_save_loc_t unw_save_loc_t;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -105,7 +125,7 @@ extern int unw_init_local(unw_cursor_t *, unw_context_t *) LIBUNWIND_AVAIL;
extern int unw_step(unw_cursor_t *) LIBUNWIND_AVAIL;
extern int unw_get_reg(unw_cursor_t *, unw_regnum_t, unw_word_t *) LIBUNWIND_AVAIL;
extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_AVAIL;
extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL;
extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t, unw_word_t *) LIBUNWIND_AVAIL;
extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t) LIBUNWIND_AVAIL;
extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;

Expand All @@ -120,7 +140,7 @@ extern int unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *) LIBUNWIND_AVAIL;
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*);
extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*) LIBUNWIND_AVAIL;

extern unw_addr_space_t unw_local_addr_space;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ enum {
// are encoded in the UNWIND_X86_EBP_FRAME_REGISTERS bits as five 3-bit entries.
// Each entry contains which register to restore.
// UNWIND_X86_MODE_STACK_IMMD:
// A "frameless" (EBP not used as frame pointer) function with a small
// A "frameless" (EBP not used as frame pointer) function with a small
// constant stack size. To return, a constant (encoded in the compact
// unwind encoding) is added to the ESP. Then the return is done by
// popping the stack into the pc.
Expand All @@ -119,16 +119,16 @@ enum {
// UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION constains which registers were
// saved and their order.
// UNWIND_X86_MODE_STACK_IND:
// A "frameless" (EBP not used as frame pointer) function large constant
// A "frameless" (EBP not used as frame pointer) function large constant
// stack size. This case is like the previous, except the stack size is too
// large to encode in the compact unwind encoding. Instead it requires that
// the function contains "subl $nnnnnnnn,ESP" in its prolog. The compact
// large to encode in the compact unwind encoding. Instead it requires that
// the function contains "subl $nnnnnnnn,ESP" in its prolog. The compact
// encoding contains the offset to the nnnnnnnn value in the function in
// UNWIND_X86_FRAMELESS_STACK_SIZE.
// UNWIND_X86_FRAMELESS_STACK_SIZE.
// UNWIND_X86_MODE_DWARF:
// No compact unwind encoding is available. Instead the low 24-bits of the
// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
// This mode is never used in object files. It is only generated by the
// This mode is never used in object files. It is only generated by the
// linker in final linked images which have only DWARF unwind info for a
// function.
//
Expand Down Expand Up @@ -233,36 +233,36 @@ enum {
// For x86_64 there are four modes for the compact unwind encoding:
// UNWIND_X86_64_MODE_RBP_FRAME:
// RBP based frame where RBP is push on stack immediately after return address,
// then RSP is moved to RBP. Thus, to unwind RSP is restored with the current
// EPB value, then RBP is restored by popping off the stack, and the return
// then RSP is moved to RBP. Thus, to unwind RSP is restored with the current
// EPB value, then RBP is restored by popping off the stack, and the return
// is done by popping the stack once more into the pc.
// All non-volatile registers that need to be restored must have been saved
// in a small range in the stack that starts RBP-8 to RBP-2040. The offset/8
// in a small range in the stack that starts RBP-8 to RBP-2040. The offset/8
// is encoded in the UNWIND_X86_64_RBP_FRAME_OFFSET bits. The registers saved
// are encoded in the UNWIND_X86_64_RBP_FRAME_REGISTERS bits as five 3-bit entries.
// Each entry contains which register to restore.
// Each entry contains which register to restore.
// UNWIND_X86_64_MODE_STACK_IMMD:
// A "frameless" (RBP not used as frame pointer) function with a small
// constant stack size. To return, a constant (encoded in the compact
// unwind encoding) is added to the RSP. Then the return is done by
// A "frameless" (RBP not used as frame pointer) function with a small
// constant stack size. To return, a constant (encoded in the compact
// unwind encoding) is added to the RSP. Then the return is done by
// popping the stack into the pc.
// All non-volatile registers that need to be restored must have been saved
// on the stack immediately after the return address. The stack_size/8 is
// encoded in the UNWIND_X86_64_FRAMELESS_STACK_SIZE (max stack size is 2048).
// The number of registers saved is encoded in UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT.
// UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION constains which registers were
// saved and their order.
// saved and their order.
// UNWIND_X86_64_MODE_STACK_IND:
// A "frameless" (RBP not used as frame pointer) function large constant
// A "frameless" (RBP not used as frame pointer) function large constant
// stack size. This case is like the previous, except the stack size is too
// large to encode in the compact unwind encoding. Instead it requires that
// the function contains "subq $nnnnnnnn,RSP" in its prolog. The compact
// large to encode in the compact unwind encoding. Instead it requires that
// the function contains "subq $nnnnnnnn,RSP" in its prolog. The compact
// encoding contains the offset to the nnnnnnnn value in the function in
// UNWIND_X86_64_FRAMELESS_STACK_SIZE.
// UNWIND_X86_64_FRAMELESS_STACK_SIZE.
// UNWIND_X86_64_MODE_DWARF:
// No compact unwind encoding is available. Instead the low 24-bits of the
// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
// This mode is never used in object files. It is only generated by the
// This mode is never used in object files. It is only generated by the
// linker in final linked images which have only DWARF unwind info for a
// function.
//
Expand Down Expand Up @@ -307,20 +307,20 @@ enum {
// This is a standard arm64 prolog where FP/LR are immediately pushed on the
// stack, then SP is copied to FP. If there are any non-volatile registers
// saved, then are copied into the stack frame in pairs in a contiguous
// range right below the saved FP/LR pair. Any subset of the five X pairs
// range right below the saved FP/LR pair. Any subset of the five X pairs
// and four D pairs can be saved, but the memory layout must be in register
// number order.
// number order.
// UNWIND_ARM64_MODE_FRAMELESS:
// A "frameless" leaf function, where FP/LR are not saved. The return address
// A "frameless" leaf function, where FP/LR are not saved. The return address
// remains in LR throughout the function. If any non-volatile registers
// are saved, they must be pushed onto the stack before any stack space is
// allocated for local variables. The stack sized (including any saved
// non-volatile registers) divided by 16 is encoded in the bits
// non-volatile registers) divided by 16 is encoded in the bits
// UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK.
// UNWIND_ARM64_MODE_DWARF:
// No compact unwind encoding is available. Instead the low 24-bits of the
// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
// This mode is never used in object files. It is only generated by the
// This mode is never used in object files. It is only generated by the
// linker in final linked images which have only DWARF unwind info for a
// function.
//
Expand All @@ -337,19 +337,19 @@ enum {

//
// A compiler can generated compact unwind information for a function by adding
// a "row" to the __LD,__compact_unwind section. This section has the
// S_ATTR_DEBUG bit set, so the section will be ignored by older linkers.
// It is removed by the new linker, so never ends up in final executables.
// This section is a table, initially with one row per function (that needs
// a "row" to the __LD,__compact_unwind section. This section has the
// S_ATTR_DEBUG bit set, so the section will be ignored by older linkers.
// It is removed by the new linker, so never ends up in final executables.
// This section is a table, initially with one row per function (that needs
// unwind info). The table columns and some conceptual entries are:
//
// range-start pointer to start of function/range
// range-length
// compact-unwind-encoding 32-bit encoding
// range-length
// compact-unwind-encoding 32-bit encoding
// personality-function or zero if no personality function
// lsda or zero if no LSDA data
//
// The length and encoding fields are 32-bits. The other are all pointer sized.
// The length and encoding fields are 32-bits. The other are all pointer sized.
//
// In x86_64 assembly, these entry would look like:
//
Expand All @@ -372,23 +372,23 @@ enum {
// .quad except_tab1
//
//
// Notes: There is no need for any labels in the the __compact_unwind section.
// The use of the .set directive is to force the evaluation of the
// Notes: There is no need for any labels in the __compact_unwind section.
// The use of the .set directive is to force the evaluation of the
// range-length at assembly time, instead of generating relocations.
//
// To support future compiler optimizations where which non-volatile registers
// To support future compiler optimizations where which non-volatile registers
// are saved changes within a function (e.g. delay saving non-volatiles until
// necessary), there can by multiple lines in the __compact_unwind table for one
// function, each with a different (non-overlapping) range and each with
// different compact unwind encodings that correspond to the non-volatiles
// function, each with a different (non-overlapping) range and each with
// different compact unwind encodings that correspond to the non-volatiles
// saved at that range of the function.
//
// If a particular function is so wacky that there is no compact unwind way
// to encode it, then the compiler can emit traditional DWARF unwind info.
// to encode it, then the compiler can emit traditional DWARF unwind info.
// The runtime will use which ever is available.
//
// Runtime support for compact unwind encodings are only available on 10.6
// and later. So, the compiler should not generate it when targeting pre-10.6.
// Runtime support for compact unwind encodings are only available on 10.6
// and later. So, the compiler should not generate it when targeting pre-10.6.



Expand All @@ -402,7 +402,7 @@ enum {
//
// The __TEXT,__unwind_info section is laid out for an efficient two level lookup.
// The header of the section contains a coarse index that maps function address
// to the page (4096 byte block) containing the unwind info for that function.
// to the page (4096 byte block) containing the unwind info for that function.
//

#define UNWIND_SECTION_VERSION 1
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/nativeaot/libunwind/include/unwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ _Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
extern _Unwind_VRS_Result
_Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
uint32_t regno, _Unwind_VRS_DataRepresentation representation,
void *valuep);
void *valuep, uint32_t *pos);

extern _Unwind_VRS_Result
_Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
Expand All @@ -220,7 +220,7 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,

extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index);
extern void _Unwind_SetGR(struct _Unwind_Context *context, int index,
uintptr_t new_value);
uintptr_t new_value, uintptr_t *pos);
extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value);

Expand Down Expand Up @@ -248,8 +248,8 @@ uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index) {

_LIBUNWIND_EXPORT_UNWIND_LEVEL1
void _Unwind_SetGR(struct _Unwind_Context *context, int index,
uintptr_t value) {
_Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
uintptr_t value,uintptr_t *pos) {
_Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value, pos);
}

_LIBUNWIND_EXPORT_UNWIND_LEVEL1
Expand All @@ -261,7 +261,7 @@ uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
_LIBUNWIND_EXPORT_UNWIND_LEVEL1
void _Unwind_SetIP(struct _Unwind_Context *context, uintptr_t value) {
uintptr_t thumb_bit = _Unwind_GetGR(context, 15) & ((uintptr_t)0x1);
_Unwind_SetGR(context, 15, value | thumb_bit);
_Unwind_SetGR(context, 15, value | thumb_bit, NULL);
}
#endif // defined(_LIBUNWIND_ARM_EHABI)

Expand Down
Loading

0 comments on commit 4c0ce47

Please sign in to comment.