Skip to content

Commit a3a09f0

Browse files
committed
Updating for feedback
1 parent 6ceef4f commit a3a09f0

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

libcxxabi/src/cxa_exception.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
4747
// In Wasm, a destructor returns its argument
4848
void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
4949
#else
50-
void(_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void*);
50+
void (_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void *);
5151
#endif
5252
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
5353
std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
@@ -88,7 +88,7 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
8888
#endif
8989

9090
std::type_info *exceptionType;
91-
void(_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void*);
91+
void (_LIBCXXABI_DTOR_FUNC *__ptrauth_cxxabi_exception_destructor exceptionDestructor)(void *);
9292
std::unexpected_handler __ptrauth_cxxabi_unexpected_handler unexpectedHandler;
9393
std::terminate_handler __ptrauth_cxxabi_terminate_handler terminateHandler;
9494

libunwind/include/__libunwind_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC
7474
# elif defined(__aarch64__)
7575
# define _LIBUNWIND_TARGET_AARCH64 1
76+
# if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
77+
# define _LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING 1
78+
# elif __has_feature(ptrauth_calls) != __has_feature(ptrauth_returns)
79+
# #error "Either both or none of ptrauth_calls and ptrauth_returns is allowed to be enabled"
80+
# endif
7681
#define _LIBUNWIND_CONTEXT_SIZE 67
7782
# if defined(__SEH__)
7883
# define _LIBUNWIND_CURSOR_SIZE 164

libunwind/src/DwarfInstructions.hpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,21 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace,
302302

303303
isSignalFrame = cieInfo.isSignalFrame;
304304

305-
#if defined(__ARM64E__)
306-
// If the target is using the arm64e ABI then the return address has
307-
// been signed using the stack pointer as a diversifier. The original
308-
// return address needs to be authenticated before the it is restored.
309-
// autia1716 is used instead of autia as autia1716 assembles to a NOP on
310-
// pre-v8.3a architectures.
305+
#if defined(_LIBUNWIND_TARGET_AARCH64) && \
306+
!defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
307+
// There are two ways of return address signing: pac-ret (enabled via
308+
// -mbranch-protection=pac-ret) and ptrauth-returns (enabled as part of
309+
// Apple's arm64e or experimental pauthtest ABI on Linux). The code
310+
// below handles signed RA for pac-ret, while ptrauth-returns uses
311+
// different logic.
312+
// TODO: unify logic for both cases, see
313+
// https://github.com/llvm/llvm-project/issues/160110
314+
//
315+
// If the target is aarch64 then the return address may have been signed
316+
// using the v8.3 pointer authentication extensions. The original
317+
// return address needs to be authenticated before the return address is
318+
// restored. autia1716 is used instead of autia as autia1716 assembles
319+
// to a NOP on pre-v8.3a architectures.
311320
if ((R::getArch() == REGISTERS_ARM64) &&
312321
isReturnAddressSigned(addressSpace, registers, cfa, prolog) &&
313322
returnAddress != 0) {

0 commit comments

Comments
 (0)