Skip to content

Commit 644405b

Browse files
committed
Use XXX_PTRAUTH_CALLS_AND_RETURNS macro instead of feature checks
1 parent 1e5b4cb commit 644405b

File tree

11 files changed

+37
-24
lines changed

11 files changed

+37
-24
lines changed

compiler-rt/lib/builtins/gcc_personality_v0.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
3030
_Unwind_Personality_Fn);
3131
#endif
3232

33-
#if __has_feature(ptrauth_calls)
33+
#if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
34+
#define COMPILERRT_PTRAUTH_CALLS_AND_RETURNS
35+
3436
#include <ptrauth.h>
3537

3638
#if __has_feature(ptrauth_restricted_intptr_qualifier)
@@ -42,6 +44,8 @@ EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT,
4244
discriminator) \
4345
__ptrauth(key, addressDiscriminated, discriminator)
4446
#endif
47+
#elif __has_feature(ptrauth_calls) || __has_feature(ptrauth_returns)
48+
#error "Either both or none of ptrauth_calls and ptrauth_returns is allowed to be enabled"
4549
#else
4650
#define __ptrauth_gcc_personality_intptr(...)
4751
#endif
@@ -289,7 +293,7 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0(
289293
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1), 0);
290294
size_t __ptrauth_gcc_personality_lpad landingPad =
291295
funcStart + landingPadOffset;
292-
#if __has_feature(ptrauth_calls)
296+
#ifdef COMPILERRT_PTRAUTH_CALLS_AND_RETURNS
293297
uintptr_t stackPointer = _Unwind_GetGR(context, -2);
294298
const uintptr_t existingDiscriminator = ptrauth_blend_discriminator(
295299
&landingPad, __ptrauth_gcc_personality_lpad_disc);

libcxxabi/include/__cxxabi_config.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@
103103
#define _LIBCXXABI_DTOR_FUNC
104104
#endif
105105

106-
#if __has_include(<ptrauth.h>)
107-
# include <ptrauth.h>
106+
#if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
107+
#define LIBCXXABI_PTRAUTH_CALLS_AND_RETURNS
108+
#elif __has_feature(ptrauth_calls) || __has_feature(ptrauth_returns)
109+
#error "Either both or none of ptrauth_calls and ptrauth_returns is allowed to be enabled"
108110
#endif
109111

110-
#if __has_feature(ptrauth_calls)
112+
#ifdef LIBCXXABI_PTRAUTH_CALLS_AND_RETURNS
113+
# include <ptrauth.h>
111114

112115
// ptrauth_string_discriminator("__cxa_exception::actionRecord") == 0xFC91
113116
# define __ptrauth_cxxabi_action_record __ptrauth(ptrauth_key_process_dependent_data, 1, 0xFC91)

libcxxabi/src/cxa_personality.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "cxa_handlers.h"
2222
#include "private_typeinfo.h"
2323

24-
#if __has_feature(ptrauth_calls)
24+
#ifdef LIBCXXABI_PTRAUTH_CALLS_AND_RETURNS
2525

2626
// CXXABI depends on defintions in libunwind as pointer auth couples the
2727
// definitions
@@ -625,7 +625,7 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
625625
reinterpret_cast<uintptr_t>(unwind_exception));
626626
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1),
627627
static_cast<uintptr_t>(results.ttypeIndex));
628-
#if __has_feature(ptrauth_calls)
628+
#ifdef LIBCXXABI_PTRAUTH_CALLS_AND_RETURNS
629629
auto stackPointer = _Unwind_GetGR(context, UNW_REG_SP);
630630
// We manually re-sign the IP as the __ptrauth qualifiers cannot
631631
// express the required relationship with the destination address

libunwind/include/libunwind.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@
4343
#define LIBUNWIND_AVAIL
4444
#endif
4545

46-
#if __has_feature(ptrauth_calls)
46+
#if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
47+
#define LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
48+
#elif __has_feature(ptrauth_calls) || __has_feature(ptrauth_returns)
49+
#error "Either both or none of ptrauth_calls and ptrauth_returns is allowed to be enabled"
50+
#endif
51+
52+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
4753

4854
#include <ptrauth.h>
4955

libunwind/src/DwarfParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
398398
pint_t personality = addressSpace.getEncodedP(
399399
p, cieContentEnd, cieInfo->personalityEncoding,
400400
/*datarelBase=*/0, &resultAddr);
401-
#if __has_feature(ptrauth_calls)
401+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
402402
if (personality) {
403403
// The GOT for the personality function was signed address
404404
// authenticated. Manually re-sign with the CIE_Info::personality

libunwind/src/Registers.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18651865
void setSP(uint64_t value) { _registers.__sp = value; }
18661866
uint64_t getIP() const {
18671867
uint64_t value = _registers.__pc;
1868-
#if __has_feature(ptrauth_calls)
1868+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
18691869
// Note the value of the PC was signed to its address in the register state
18701870
// but everyone else expects it to be sign by the SP, so convert on return.
18711871
value = (uint64_t)ptrauth_auth_and_resign((void *)_registers.__pc,
@@ -1877,7 +1877,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18771877
return value;
18781878
}
18791879
void setIP(uint64_t value) {
1880-
#if __has_feature(ptrauth_calls)
1880+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
18811881
// Note the value which was set should have been signed with the SP.
18821882
// We then resign with the slot we are being stored in to so that both SP
18831883
// and LR can't be spoofed at the same time.
@@ -1892,7 +1892,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18921892
uint64_t getFP() const { return _registers.__fp; }
18931893
void setFP(uint64_t value) { _registers.__fp = value; }
18941894

1895-
#if __has_feature(ptrauth_calls)
1895+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
18961896
void
18971897
loadAndAuthenticateLinkRegister(reg_t inplaceAuthedLinkRegister,
18981898
link_reg_t *referenceAuthedLinkRegister) {
@@ -1944,7 +1944,7 @@ inline Registers_arm64::Registers_arm64(const void *registers) {
19441944
memcpy(_vectorHalfRegisters,
19451945
static_cast<const uint8_t *>(registers) + sizeof(GPRs),
19461946
sizeof(_vectorHalfRegisters));
1947-
#if __has_feature(ptrauth_calls)
1947+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
19481948
// We have to do some pointer authentication fixups after this copy,
19491949
// and as part of that we need to load the source pc without
19501950
// authenticating so that we maintain the signature for the resigning
@@ -1964,7 +1964,7 @@ inline Registers_arm64& Registers_arm64::operator=(const Registers_arm64& other)
19641964
memcpy(&_registers, &other._registers, sizeof(_registers));
19651965
memcpy(_vectorHalfRegisters, &other._vectorHalfRegisters,
19661966
sizeof(_vectorHalfRegisters));
1967-
#if __has_feature(ptrauth_calls)
1967+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
19681968
// We perform this step to ensure that we correctly authenticate and re-sign
19691969
// the pc after the bitwise copy.
19701970
setIP(other.getIP());

libunwind/src/UnwindCursor.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ class UnwindCursor : public AbstractUnwindCursor{
10511051
const UnwindInfoSections &sects,
10521052
uint32_t fdeSectionOffsetHint = 0);
10531053
int stepWithDwarfFDE(bool stage2) {
1054-
#if __has_feature(ptrauth_calls)
1054+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
10551055
typename R::reg_t rawPC = this->getReg(UNW_REG_IP);
10561056
typename R::link_reg_t pc;
10571057
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
@@ -1995,7 +1995,7 @@ bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(
19951995
personalityIndex * sizeof(uint32_t));
19961996
pint_t personalityPointer = sects.dso_base + (pint_t)personalityDelta;
19971997
personality = _addressSpace.getP(personalityPointer);
1998-
#if __has_feature(ptrauth_calls)
1998+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
19991999
// The GOT for the personality function was signed address authenticated.
20002000
// Resign it as a regular function pointer.
20012001
const auto discriminator =
@@ -2682,7 +2682,7 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
26822682
#endif
26832683

26842684
typename R::link_reg_t pc;
2685-
#if __has_feature(ptrauth_calls)
2685+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
26862686
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
26872687
#else
26882688
pc = rawPC;
@@ -3237,7 +3237,7 @@ void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) {
32373237
template <typename A, typename R>
32383238
bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
32393239
unw_word_t *offset) {
3240-
#if __has_feature(ptrauth_calls)
3240+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
32413241
typename R::reg_t rawPC = this->getReg(UNW_REG_IP);
32423242
typename R::link_reg_t pc;
32433243
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);

libunwind/src/UnwindLevel1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
608608
unw_word_t result;
609609
__unw_get_reg(cursor, UNW_REG_IP, &result);
610610

611-
#if __has_feature(ptrauth_calls)
611+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
612612
// If we are in an arm64e frame, then the PC should have been signed with the
613613
// sp
614614
{

libunwind/src/UnwindRegistersRestore.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
685685
ldr x16, [x0, #0x0F8] // load sp into scratch
686686
ldr lr, [x0, #0x100] // restore pc into lr
687687

688-
#if __has_feature(ptrauth_calls)
688+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
689689
// The LR is signed with its address inside the register state. Time
690690
// to resign to be a regular ROP protected signed pointer
691691
add x1, x0, #0x100
@@ -706,7 +706,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
706706
Lnogcs:
707707
#endif
708708

709-
#if __has_feature(ptrauth_calls)
709+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
710710
retab
711711
#else
712712
ret x30 // jump to pc

libunwind/src/UnwindRegistersSave.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ LnoR2Fix:
768768
.p2align 2
769769
DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
770770

771-
#if __has_feature(ptrauth_calls)
771+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
772772
pacibsp
773773
#endif
774774

@@ -813,7 +813,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
813813
#endif
814814
mov x0, #0 // return UNW_ESUCCESS
815815

816-
#if __has_feature(ptrauth_calls)
816+
#ifdef LIBUNWIND_PTRAUTH_CALLS_AND_RETURNS
817817
retab
818818
#else
819819
ret

0 commit comments

Comments
 (0)