[libcxx-commits] [compiler-rt] [libcxxabi] [libunwind] [runtimes][PAC] Harden unwinding when possible (#138571) (PR #143230)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 6 19:13:49 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions c,h,cpp,hpp -- compiler-rt/lib/builtins/gcc_personality_v0.c compiler-rt/lib/profile/InstrProfilingValue.c libcxxabi/include/__cxxabi_config.h libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_personality.cpp libunwind/include/libunwind.h libunwind/src/AddressSpace.hpp libunwind/src/DwarfInstructions.hpp libunwind/src/DwarfParser.hpp libunwind/src/Registers.hpp libunwind/src/UnwindCursor.hpp libunwind/src/UnwindLevel1.c libunwind/src/libunwind.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/builtins/gcc_personality_v0.c b/compiler-rt/lib/builtins/gcc_personality_v0.c
index 42b992949..8bc7cb3ea 100644
--- a/compiler-rt/lib/builtins/gcc_personality_v0.c
+++ b/compiler-rt/lib/builtins/gcc_personality_v0.c
@@ -38,13 +38,14 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
#if __has_feature(ptrauth_restricted_intptr_qualifier)
#define PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(key, addressDiscriminated, \
discriminatorString) \
- __ptrauth_restricted_intptr(key, addressDiscriminated, \
- ptrauth_string_discriminator(discriminatorString))
+ __ptrauth_restricted_intptr( \
+ key, addressDiscriminated, \
+ ptrauth_string_discriminator(discriminatorString))
#else
#define PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(key, addressDiscriminated, \
discriminatorString) \
- __ptrauth(key, addressDiscriminated, \
- ptrauth_string_discriminator(discriminatorString))
+ __ptrauth(key, addressDiscriminated, \
+ ptrauth_string_discriminator(discriminatorString))
#endif
#else
#define PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(key, addressDiscriminated, \
@@ -57,17 +58,17 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
// * RA : ptrauth_key_return_address
// * FN : ptrauth_key_function_pointer
#define PERSONALITY_PTRAUTH_RI_FN(__discriminator) \
- PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_function_pointer, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_function_pointer, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
#define PERSONALITY_PTRAUTH_RI_PDC(__discriminator) \
- PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_code, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_code, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
#define PERSONALITY_PTRAUTH_RI_RA(__discriminator) \
- PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_return_address, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_return_address, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
// Pointer encodings documented at:
// http://refspecs.freestandards.org/LSB_1.3.0/gLSB/gLSB/ehframehdr.html
@@ -264,10 +265,10 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
const uint8_t *callSiteTableEnd = callSiteTableStart + callSiteTableLength;
const uint8_t *p = callSiteTableStart;
while (p < callSiteTableEnd) {
- uintptr_t PERSONALITY_PTRAUTH_RI_PDC("__gcc_personality_v0'start")
- start = readEncodedPointer(&p, callSiteEncoding);
- size_t PERSONALITY_PTRAUTH_RI_PDC("__gcc_personality_v0'length")
- length = readEncodedPointer(&p, callSiteEncoding);
+ uintptr_t PERSONALITY_PTRAUTH_RI_PDC("__gcc_personality_v0'start") start =
+ readEncodedPointer(&p, callSiteEncoding);
+ size_t PERSONALITY_PTRAUTH_RI_PDC("__gcc_personality_v0'length") length =
+ readEncodedPointer(&p, callSiteEncoding);
size_t PERSONALITY_PTRAUTH_RI_PDC("__gcc_personality_v0'landingPadOffset")
landingPadOffset = readEncodedPointer(&p, callSiteEncoding);
readULEB128(&p); // action value not used for C code
@@ -282,13 +283,12 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
(uintptr_t)exceptionObject);
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1), 0);
#define LANDING_PAD_DISCRIMINATOR "__gcc_personality_v0'landingPad"
- size_t PERSONALITY_PTRAUTH_RI_RA(LANDING_PAD_DISCRIMINATOR)
- landingPad = funcStart + landingPadOffset;
+ size_t PERSONALITY_PTRAUTH_RI_RA(LANDING_PAD_DISCRIMINATOR) landingPad =
+ funcStart + landingPadOffset;
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
uintptr_t stack_pointer = _Unwind_GetGR(context, -2);
const uintptr_t existingDiscriminator = ptrauth_blend_discriminator(
- &landingPad,
- ptrauth_string_discriminator(LANDING_PAD_DISCRIMINATOR));
+ &landingPad, ptrauth_string_discriminator(LANDING_PAD_DISCRIMINATOR));
uintptr_t newIP = (uintptr_t)ptrauth_auth_and_resign(
*(void **)&landingPad, ptrauth_key_function_pointer,
existingDiscriminator, ptrauth_key_return_address, stack_pointer);
diff --git a/compiler-rt/lib/profile/InstrProfilingValue.c b/compiler-rt/lib/profile/InstrProfilingValue.c
index cd6ae3d7a..eea7b6ef4 100644
--- a/compiler-rt/lib/profile/InstrProfilingValue.c
+++ b/compiler-rt/lib/profile/InstrProfilingValue.c
@@ -89,7 +89,7 @@ __llvm_get_function_addr(const __llvm_profile_data *Data) {
// signed pointers.
FP = ptrauth_sign_unauthenticated(FP, VALID_CODE_KEY, 0);
#endif
- return FP;
+ return FP;
}
/* Allocate an array that holds the pointers to the linked lists of
diff --git a/libcxxabi/include/__cxxabi_config.h b/libcxxabi/include/__cxxabi_config.h
index e67d065fe..0a3c132e4 100644
--- a/libcxxabi/include/__cxxabi_config.h
+++ b/libcxxabi/include/__cxxabi_config.h
@@ -32,23 +32,23 @@
#endif
#if defined(_WIN32)
- #if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) || \
- (defined(__MINGW32__) && !defined(_LIBCXXABI_BUILDING_LIBRARY))
- #define _LIBCXXABI_HIDDEN
- #define _LIBCXXABI_DATA_VIS
- #define _LIBCXXABI_FUNC_VIS
- #define _LIBCXXABI_TYPE_VIS
- #elif defined(_LIBCXXABI_BUILDING_LIBRARY)
- #define _LIBCXXABI_HIDDEN
- #define _LIBCXXABI_DATA_VIS __declspec(dllexport)
- #define _LIBCXXABI_FUNC_VIS __declspec(dllexport)
- #define _LIBCXXABI_TYPE_VIS __declspec(dllexport)
- #else
- #define _LIBCXXABI_HIDDEN
- #define _LIBCXXABI_DATA_VIS __declspec(dllimport)
- #define _LIBCXXABI_FUNC_VIS __declspec(dllimport)
- #define _LIBCXXABI_TYPE_VIS __declspec(dllimport)
- #endif
+# if defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) || \
+ (defined(__MINGW32__) && !defined(_LIBCXXABI_BUILDING_LIBRARY))
+# define _LIBCXXABI_HIDDEN
+# define _LIBCXXABI_DATA_VIS
+# define _LIBCXXABI_FUNC_VIS
+# define _LIBCXXABI_TYPE_VIS
+# elif defined(_LIBCXXABI_BUILDING_LIBRARY)
+# define _LIBCXXABI_HIDDEN
+# define _LIBCXXABI_DATA_VIS __declspec(dllexport)
+# define _LIBCXXABI_FUNC_VIS __declspec(dllexport)
+# define _LIBCXXABI_TYPE_VIS __declspec(dllexport)
+# else
+# define _LIBCXXABI_HIDDEN
+# define _LIBCXXABI_DATA_VIS __declspec(dllimport)
+# define _LIBCXXABI_FUNC_VIS __declspec(dllimport)
+# define _LIBCXXABI_TYPE_VIS __declspec(dllimport)
+# endif
#else
#if !defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
#define _LIBCXXABI_HIDDEN __attribute__((__visibility__("hidden")))
@@ -111,30 +111,24 @@
#endif
#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
+# include <ptrauth.h>
#endif
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
-# define _LIBCXXABI_PTRAUTH(__key, __address_discriminated, __discriminator) \
- __ptrauth(__key,__address_discriminated, \
- ptrauth_string_discriminator(__discriminator))
+# define _LIBCXXABI_PTRAUTH(__key, __address_discriminated, __discriminator) \
+ __ptrauth(__key, __address_discriminated, ptrauth_string_discriminator(__discriminator))
// This work around is required to support divergence in spelling
// during the ptrauth upstreaming process.
# if __has_feature(ptrauth_restricted_intptr_qualifier)
-# define _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, \
- __discriminator) \
- __ptrauth_restricted_intptr(__key,__address_discriminated, \
- ptrauth_string_discriminator(__discriminator))
+# define _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, __discriminator) \
+ __ptrauth_restricted_intptr(__key, __address_discriminated, ptrauth_string_discriminator(__discriminator))
# else
-# define _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, \
- __discriminator) \
- __ptrauth(__key,__address_discriminated, \
- ptrauth_string_discriminator(__discriminator))
+# define _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, __discriminator) \
+ __ptrauth(__key, __address_discriminated, ptrauth_string_discriminator(__discriminator))
# endif
#else
# define _LIBCXXABI_PTRAUTH(__key, __address_discriminated, __discriminator)
-# define _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, \
- __discriminator)
+# define _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, __discriminator)
#endif
// Helper wrappers for pointer auth qualifiers because we use a lot of variants
@@ -142,17 +136,12 @@
// * _RI : qualifier is __ptrauth_restricted_intptr
// * PDD : key is ptrauth_key_process_dependent_data
// * FN : key is ptrauth_key_function_pointer
-#define _LIBCXXABI_PTRAUTH_PDD(__discriminator) \
- _LIBCXXABI_PTRAUTH(ptrauth_key_process_dependent_data, \
- /*__address_discriminated=*/1, \
- __discriminator)
-#define _LIBCXXABI_PTRAUTH_FN(__discriminator) \
- _LIBCXXABI_PTRAUTH(ptrauth_key_function_pointer, \
- /*__address_discriminated=*/1, \
- __discriminator)
-#define _LIBCXXABI_PTRAUTH_RI_PDD(__discriminator) \
- _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_data, \
- /*__address_discriminated=*/1, \
- __discriminator)
+#define _LIBCXXABI_PTRAUTH_PDD(__discriminator) \
+ _LIBCXXABI_PTRAUTH(ptrauth_key_process_dependent_data, /*__address_discriminated=*/1, __discriminator)
+#define _LIBCXXABI_PTRAUTH_FN(__discriminator) \
+ _LIBCXXABI_PTRAUTH(ptrauth_key_function_pointer, /*__address_discriminated=*/1, __discriminator)
+#define _LIBCXXABI_PTRAUTH_RI_PDD(__discriminator) \
+ _LIBCXXABI_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_data, /*__address_discriminated=*/1, \
+ __discriminator)
#endif // ____CXXABI_CONFIG_H
diff --git a/libcxxabi/src/cxa_exception.h b/libcxxabi/src/cxa_exception.h
index 4c69d4804..6b0db16af 100644
--- a/libcxxabi/src/cxa_exception.h
+++ b/libcxxabi/src/cxa_exception.h
@@ -47,7 +47,8 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
// In Wasm, a destructor returns its argument
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
#else
- void(_LIBCXXABI_DTOR_FUNC* _LIBCXXABI_PTRAUTH_FN("__cxa_exception::exceptionDestructor") exceptionDestructor)(void*);
+ void(_LIBCXXABI_DTOR_FUNC* _LIBCXXABI_PTRAUTH_FN("__cxa_exception::exceptionDestructor")
+ exceptionDestructor)(void*);
#endif
std::unexpected_handler _LIBCXXABI_PTRAUTH_FN("__cxa_exception::unexpectedHandler") unexpectedHandler;
std::terminate_handler _LIBCXXABI_PTRAUTH_FN("__cxa_exception::terminateHandler") terminateHandler;
@@ -88,7 +89,8 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
#endif
std::type_info *exceptionType;
- void(_LIBCXXABI_DTOR_FUNC* _LIBCXXABI_PTRAUTH_FN("__cxa_exception::exceptionDestructor") exceptionDestructor)(void*);
+ void(_LIBCXXABI_DTOR_FUNC* _LIBCXXABI_PTRAUTH_FN("__cxa_exception::exceptionDestructor")
+ exceptionDestructor)(void*);
std::unexpected_handler _LIBCXXABI_PTRAUTH_FN("__cxa_exception::unexpectedHandler") unexpectedHandler;
std::terminate_handler _LIBCXXABI_PTRAUTH_FN("__cxa_exception::terminateHandler") terminateHandler;
diff --git a/libcxxabi/src/cxa_personality.cpp b/libcxxabi/src/cxa_personality.cpp
index cbb3f46e0..05737b376 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -23,7 +23,7 @@
#include "unwind.h"
#if __has_include(<ptrauth.h>)
-#include <ptrauth.h>
+# include <ptrauth.h>
#endif
#include "libunwind.h"
@@ -601,13 +601,10 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
// We manually re-sign the IP as the __ptrauth qualifiers cannot
// express the required relationship with the destination address
const auto existingDiscriminator = ptrauth_blend_discriminator(
- &results.landingPad,
- ptrauth_string_discriminator(_LIBCXXABI_PTRAUTH_SCANRESULT_LANDINGPAD_DISC));
- unw_word_t newIP = (unw_word_t)ptrauth_auth_and_resign(*(void**)&results.landingPad,
- _LIBCXXABI_PTRAUTH_KEY,
- existingDiscriminator,
- ptrauth_key_return_address,
- stack_pointer);
+ &results.landingPad, ptrauth_string_discriminator(_LIBCXXABI_PTRAUTH_SCANRESULT_LANDINGPAD_DISC));
+ unw_word_t newIP =
+ (unw_word_t)ptrauth_auth_and_resign(*(void**)&results.landingPad, _LIBCXXABI_PTRAUTH_KEY, existingDiscriminator,
+ ptrauth_key_return_address, stack_pointer);
_Unwind_SetIP(context, newIP);
#else
_Unwind_SetIP(context, results.landingPad);
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index e7375bbca..4c6b031d9 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -57,12 +57,12 @@
#define _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, \
__discriminator) \
__ptrauth_restricted_intptr(__key, __address_discriminated, \
- ptrauth_string_discriminator(__discriminator))
+ ptrauth_string_discriminator(__discriminator))
#else
#define _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(__key, __address_discriminated, \
__discriminator) \
__ptrauth(__key, __address_discriminated, \
- ptrauth_string_discriminator(__discriminator))
+ ptrauth_string_discriminator(__discriminator))
#endif
#else
#define _LIBUNWIND_PTRAUTH(__key, __address_discriminated, __discriminator)
@@ -78,25 +78,24 @@
// * PDC : ptrauth_key_process_dependent_code
// * FN : ptrauth_key_function_pointer
#define __LIBUNWIND_PTRAUTH_RI_PDD(__discriminator) \
- _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_data, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_data, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
#define __LIBUNWIND_PTRAUTH_RI_PIC(__discriminator) \
- _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_independent_code, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_independent_code, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
#define __LIBUNWIND_PTRAUTH_RI_PDC(__discriminator) \
- _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_code, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_code, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
#define __LIBUNWIND_PTRAUTH_RI_FN(__discriminator) \
- _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_function_pointer, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_function_pointer, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
#define __LIBUNWIND_PTRAUTH_FN(__discriminator) \
- _LIBUNWIND_PTRAUTH(ptrauth_key_function_pointer, \
- /*__address_discriminated=*/1, \
- __discriminator)
+ _LIBUNWIND_PTRAUTH(ptrauth_key_function_pointer, \
+ /*__address_discriminated=*/1, __discriminator)
#if defined(_WIN32) && defined(__SEH__)
#define LIBUNWIND_CURSOR_ALIGNMENT_ATTR __attribute__((__aligned__(16)))
@@ -143,24 +142,24 @@ typedef double unw_fpreg_t;
#endif
struct unw_proc_info_t {
- unw_word_t __LIBUNWIND_PTRAUTH_RI_PIC("unw_proc_info_t::start_ip")
- start_ip; /* start address of function */
- unw_word_t __LIBUNWIND_PTRAUTH_RI_PIC("unw_proc_info_t::end_ip")
- end_ip; /* address after end of function */
+ unw_word_t __LIBUNWIND_PTRAUTH_RI_PIC(
+ "unw_proc_info_t::start_ip") start_ip; /* start address of function */
+ unw_word_t __LIBUNWIND_PTRAUTH_RI_PIC(
+ "unw_proc_info_t::end_ip") end_ip; /* address after end of function */
unw_word_t __LIBUNWIND_PTRAUTH_RI_PDD("unw_proc_info_t::lsda")
- lsda; /* address of language specific data area, */
- /* or zero if not used */
+ lsda; /* address of language specific data area, */
+ /* or zero if not used */
unw_word_t __LIBUNWIND_PTRAUTH_RI_FN("unw_proc_info_t::handler")
- handler; /* personality routine, or zero if not used */
+ handler; /* personality routine, or zero if not used */
unw_word_t gp; /* not used */
- unw_word_t __LIBUNWIND_PTRAUTH_RI_PDD("unw_proc_info_t::flags") \
- flags; /* not used */
+ unw_word_t
+ __LIBUNWIND_PTRAUTH_RI_PDD("unw_proc_info_t::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 __LIBUNWIND_PTRAUTH_RI_PDD("unw_proc_info_t::unwind_info")
- unwind_info; /* address of DWARF unwind info, or zero */
+ unwind_info; /* address of DWARF unwind info, or zero */
unw_word_t __LIBUNWIND_PTRAUTH_RI_PDD("unw_proc_info_t::extra")
- extra; /* mach_header of mach-o image containing func */
+ extra; /* mach_header of mach-o image containing func */
};
typedef struct unw_proc_info_t unw_proc_info_t;
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 1b89d5c03..b4bca4612 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -129,8 +129,8 @@ struct UnwindInfoSections {
defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND) || \
defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
// No dso_base for SEH.
- uintptr_t __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::dso_base")
- dso_base = 0;
+ uintptr_t
+ __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::dso_base") dso_base = 0;
#endif
#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
size_t __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::text_segment_length")
@@ -143,15 +143,17 @@ struct UnwindInfoSections {
dwarf_section_length = 0;
#endif
#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
- uintptr_t __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::dwarf_index_section")
- dwarf_index_section = 0;
- size_t __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::dwarf_index_section_length")
+ uintptr_t __LIBUNWIND_PTRAUTH_RI_PDD(
+ "UnwindInfoSections::dwarf_index_section") dwarf_index_section = 0;
+ size_t __LIBUNWIND_PTRAUTH_RI_PDD(
+ "UnwindInfoSections::dwarf_index_section_length")
dwarf_index_section_length = 0;
#endif
#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
- uintptr_t __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::compact_unwind_section")
- compact_unwind_section = 0;
- size_t __LIBUNWIND_PTRAUTH_RI_PDD("UnwindInfoSections::compact_unwind_section_length")
+ uintptr_t __LIBUNWIND_PTRAUTH_RI_PDD(
+ "UnwindInfoSections::compact_unwind_section") compact_unwind_section = 0;
+ size_t __LIBUNWIND_PTRAUTH_RI_PDD(
+ "UnwindInfoSections::compact_unwind_section_length")
compact_unwind_section_length = 0;
#endif
#if defined(_LIBUNWIND_ARM_EHABI)
@@ -366,7 +368,7 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
if (encoding & DW_EH_PE_indirect) {
if (resultAddr)
*resultAddr = result;
- result = getP(result);
+ result = getP(result);
} else {
if (resultAddr)
*resultAddr = startAddr;
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 8cde9cfe0..bd12734fd 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -37,7 +37,8 @@ template <typename A>
class CFI_Parser {
public:
typedef typename A::pint_t pint_t;
- typedef pint_t __LIBUNWIND_PTRAUTH_RI_FN("CIE_Info::personality") personality_t;
+ typedef pint_t
+ __LIBUNWIND_PTRAUTH_RI_FN("CIE_Info::personality") personality_t;
/// Information encoded in a CIE (Common Information Entry)
struct CIE_Info {
@@ -328,7 +329,7 @@ void set_cie_info_personality(CIE_Info *info, T signed_personality) {
memmove((void *)&info->personality, (void *)&signed_personality,
sizeof(signed_personality));
}
-}
+} // namespace
/// Extract info from a CIE
template <typename A>
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 8d4345332..cc1f96a34 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -17,8 +17,8 @@
#include "config.h"
#include "libunwind.h"
-#include "shadow_stack_unwind.h"
#include "libunwind_ext.h"
+#include "shadow_stack_unwind.h"
#if __has_include(<ptrauth.h>)
#include <ptrauth.h>
@@ -100,7 +100,7 @@ public:
typedef uint32_t reg_t;
typedef uint32_t link_reg_t;
- void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
+ void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
link_reg_t *dstLinkRegister) {
*dstLinkRegister = srcLinkRegister;
}
@@ -325,7 +325,7 @@ public:
typedef uint64_t reg_t;
typedef uint64_t link_reg_t;
- void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
+ void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
link_reg_t *dstLinkRegister) {
*dstLinkRegister = srcLinkRegister;
}
@@ -643,7 +643,7 @@ public:
typedef uint32_t reg_t;
typedef uint32_t link_reg_t;
- void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
+ void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
link_reg_t *dstLinkRegister) {
*dstLinkRegister = srcLinkRegister;
}
@@ -1871,57 +1871,51 @@ public:
uint64_t getSP() const { return _registers.__sp; }
void setSP(uint64_t value) { _registers.__sp = value; }
- uint64_t getIP() const {
+ uint64_t getIP() const {
uint64_t value = _registers.__pc;
#if __has_feature(ptrauth_calls)
// Note the value of the PC was signed to its address in the register state
// but everyone else expects it to be sign by the SP, so convert on return.
- value = (uint64_t)ptrauth_auth_and_resign((void *)_registers.__pc,
- ptrauth_key_return_address,
- &_registers.__pc,
- ptrauth_key_return_address,
- getSP());
+ value = (uint64_t)ptrauth_auth_and_resign(
+ (void *)_registers.__pc, ptrauth_key_return_address, &_registers.__pc,
+ ptrauth_key_return_address, getSP());
#endif
return value;
}
- void setIP(uint64_t value) {
+ void setIP(uint64_t value) {
#if __has_feature(ptrauth_calls)
// Note the value which was set should have been signed with the SP.
// We then resign with the slot we are being stored in to so that both SP
// and LR can't be spoofed at the same time.
- value = (uint64_t)ptrauth_auth_and_resign((void *)value,
- ptrauth_key_return_address,
- getSP(),
- ptrauth_key_return_address,
- &_registers.__pc);
+ value = (uint64_t)ptrauth_auth_and_resign(
+ (void *)value, ptrauth_key_return_address, getSP(),
+ ptrauth_key_return_address, &_registers.__pc);
#endif
_registers.__pc = value;
}
- uint64_t getFP() const {
- return _registers.__fp;
- }
- void setFP(uint64_t value) {
- _registers.__fp = value;
- }
+ uint64_t getFP() const { return _registers.__fp; }
+ void setFP(uint64_t value) { _registers.__fp = value; }
typedef uint64_t reg_t;
- typedef uint64_t __LIBUNWIND_PTRAUTH_RI_PDC("Registers_arm64::link_reg_t") link_reg_t;
+ typedef uint64_t
+ __LIBUNWIND_PTRAUTH_RI_PDC("Registers_arm64::link_reg_t") link_reg_t;
void
loadAndAuthenticateLinkRegister(reg_t inplaceAuthedLinkRegister,
link_reg_t *referenceAuthedLinkRegister) {
#if __has_feature(ptrauth_calls)
// If we are in an arm64e frame, then the PC should have been signed
// with the SP
- *referenceAuthedLinkRegister =
- (uint64_t)ptrauth_auth_data((void *)inplaceAuthedLinkRegister, ptrauth_key_return_address, _registers.__sp);
+ *referenceAuthedLinkRegister = (uint64_t)ptrauth_auth_data(
+ (void *)inplaceAuthedLinkRegister, ptrauth_key_return_address,
+ _registers.__sp);
#else
*referenceAuthedLinkRegister = inplaceAuthedLinkRegister;
#endif
}
// arm64_32 and i386 simulator hack
- void loadAndAuthenticateLinkRegister(uint32_t srcLinkRegister,
- uint32_t *dstLinkRegister) {
+ void loadAndAuthenticateLinkRegister(uint32_t srcLinkRegister,
+ uint32_t *dstLinkRegister) {
*dstLinkRegister = srcLinkRegister;
}
@@ -1954,19 +1948,22 @@ inline Registers_arm64::Registers_arm64(const void *registers) {
sizeof(_vectorHalfRegisters));
#if __has_feature(ptrauth_calls)
uint64_t pcRegister = 0;
- memcpy(&pcRegister, ((uint8_t*)&_registers) + offsetof(GPRs, __pc), sizeof(pcRegister));
+ memcpy(&pcRegister, ((uint8_t *)&_registers) + offsetof(GPRs, __pc),
+ sizeof(pcRegister));
setIP(pcRegister);
uint64_t fpRegister = 0;
- memcpy(&fpRegister, ((uint8_t*)&_registers) + offsetof(GPRs, __fp), sizeof(fpRegister));
+ memcpy(&fpRegister, ((uint8_t *)&_registers) + offsetof(GPRs, __fp),
+ sizeof(fpRegister));
setFP(fpRegister);
#endif
}
-inline Registers_arm64::Registers_arm64(const Registers_arm64& other) {
+inline Registers_arm64::Registers_arm64(const Registers_arm64 &other) {
*this = other;
}
-inline Registers_arm64& Registers_arm64::operator=(const Registers_arm64& other) {
+inline Registers_arm64 &
+Registers_arm64::operator=(const Registers_arm64 &other) {
memcpy(&_registers, &other._registers, sizeof(_registers));
memcpy(_vectorHalfRegisters, &other._vectorHalfRegisters,
sizeof(_vectorHalfRegisters));
@@ -2240,7 +2237,7 @@ public:
typedef uint32_t reg_t;
typedef uint32_t link_reg_t;
- void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
+ void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
link_reg_t *dstLinkRegister) {
*dstLinkRegister = srcLinkRegister;
}
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 7068e42c3..205265d18 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -613,12 +613,14 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
__unw_get_reg(cursor, UNW_REG_IP, &result);
#if __has_feature(ptrauth_calls)
- // 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);
- }
+ // 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,
``````````
</details>
https://github.com/llvm/llvm-project/pull/143230
More information about the libcxx-commits
mailing list