Skip to content

Commit 905477d

Browse files
committed
Enable libunwind hardening
1 parent b155532 commit 905477d

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

compiler-rt/lib/builtins/gcc_personality_v0.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <stddef.h>
1111

1212
#include <unwind.h>
13+
14+
#define EXTRA_PTRAUTH_HARDENING 1
15+
1316
#if defined(__arm__) && !defined(__ARM_DWARF_EH__) && \
1417
!defined(__USING_SJLJ_EXCEPTIONS__)
1518
// When building with older compilers (e.g. clang <3.9), it is possible that we
@@ -34,7 +37,7 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
3437
#include <ptrauth.h>
3538
#endif
3639

37-
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
40+
#if defined(EXTRA_PTRAUTH_HARDENING) && __has_feature(ptrauth_qualifier)
3841
#if __has_feature(ptrauth_restricted_intptr_qualifier)
3942
#define PERSONALITY_PTRAUTH_RESTRICTED_INTPTR(key, addressDiscriminated, \
4043
discriminatorString) \
@@ -285,7 +288,7 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
285288
#define LANDING_PAD_DISCRIMINATOR "__gcc_personality_v0'landingPad"
286289
size_t PERSONALITY_PTRAUTH_RI_RA(LANDING_PAD_DISCRIMINATOR) landingPad =
287290
funcStart + landingPadOffset;
288-
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
291+
#if defined(EXTRA_PTRAUTH_HARDENING) && __has_feature(ptrauth_qualifier)
289292
uintptr_t stack_pointer = _Unwind_GetGR(context, -2);
290293
const uintptr_t existingDiscriminator = ptrauth_blend_discriminator(
291294
&landingPad, ptrauth_string_discriminator(LANDING_PAD_DISCRIMINATOR));

libcxxabi/include/__cxxabi_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef ____CXXABI_CONFIG_H
1010
#define ____CXXABI_CONFIG_H
1111

12+
#define EXTRA_PTRAUTH_HARDENING 1
13+
1214
#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
1315
!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
1416
#define _LIBCXXABI_ARM_EHABI
@@ -114,7 +116,7 @@
114116
# include <ptrauth.h>
115117
#endif
116118

117-
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
119+
#if defined(EXTRA_PTRAUTH_HARDENING) && __has_feature(ptrauth_qualifier)
118120
# define _LIBCXXABI_PTRAUTH(__key, __address_discriminated, __discriminator) \
119121
__ptrauth(__key, __address_discriminated, ptrauth_string_discriminator(__discriminator))
120122
// This work around is required to support divergence in spelling

libcxxabi/src/cxa_personality.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "private_typeinfo.h"
2323
#include "unwind.h"
2424

25+
#define EXTRA_PTRAUTH_HARDENING 1
26+
2527
#if __has_include(<ptrauth.h>)
2628
# include <ptrauth.h>
2729
#endif
@@ -596,7 +598,7 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
596598
reinterpret_cast<uintptr_t>(unwind_exception));
597599
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1),
598600
static_cast<uintptr_t>(results.ttypeIndex));
599-
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
601+
#if defined(EXTRA_PTRAUTH_HARDENING) && __has_feature(ptrauth_qualifier)
600602
auto stack_pointer = _Unwind_GetGR(context, UNW_REG_SP);
601603
// We manually re-sign the IP as the __ptrauth qualifiers cannot
602604
// express the required relationship with the destination address

libunwind/include/libunwind.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <stdint.h>
1919
#include <stddef.h>
2020

21+
#define EXTRA_PTRAUTH_HARDENING 1
22+
2123
#ifdef __APPLE__
2224
#if __clang__
2325
#if __has_include(<Availability.h>)
@@ -47,7 +49,7 @@
4749
#include <ptrauth.h>
4850
#endif
4951

50-
#if defined(__APPLE__) && __has_feature(ptrauth_qualifier)
52+
#if defined(EXTRA_PTRAUTH_HARDENING) && __has_feature(ptrauth_qualifier)
5153
#define _LIBUNWIND_PTRAUTH(__key, __address_discriminated, __discriminator) \
5254
__ptrauth(__key, __address_discriminated, \
5355
ptrauth_string_discriminator(__discriminator))

0 commit comments

Comments
 (0)