Skip to content

Commit 4fb933c

Browse files
committed
[AArch64][PAC] Support init/fini array signing
Implement an option `-fptrauth-init-fini` allowing to sign pointers in init/fini arrays with a constant discriminator distinguishing them from other function pointers. The option is automatically enabled when building with `-mbranch-protection=pauthabi` and disabled by default otherwise.
1 parent 63d119a commit 4fb933c

File tree

11 files changed

+193
-38
lines changed

11 files changed

+193
-38
lines changed

clang/include/clang/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ FEATURE(ptrauth_member_function_pointer_type_discrimination, LangOpts.PointerAut
119119
FEATURE(ptrauth_function_pointer_type_discrimination, LangOpts.FunctionPointerTypeDiscrimination)
120120
FEATURE(ptrauth_signed_block_descriptors, LangOpts.PointerAuthBlockDescriptorPointers)
121121
FEATURE(ptrauth_objc_isa_masking, LangOpts.PointerAuthObjcIsaMasking)
122+
FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
122123
FEATURE(swiftasynccc,
123124
PP.getTargetInfo().checkCallingConvention(CC_SwiftAsync) ==
124125
clang::TargetInfo::CCCR_OK)

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ LANGOPT(PointerAuthReturns, 1, 0, "return pointer authentication")
166166
LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication failure traps")
167167
LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address discrimination in authenticated vtable pointers")
168168
LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type discrimination in authenticated vtable pointers")
169+
LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini arrays")
169170
ENUM_LANGOPT(PointerAuthObjcIsaAuthentication, PointerAuthenticationMode, 2,
170171
PointerAuthenticationMode::None, "authentication mode for objc isa")
171172
LANGOPT(PointerAuthObjcIsaMasking, 1, 0, "pre- and post-authentication masking for Objective-C isa pointer")

clang/include/clang/Basic/PointerAuthOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ constexpr uint16_t SuperPointerConstantDiscriminator = 0xB5AB;
4141
/// is ptrauth_string_discriminator("block_descriptor")
4242
constexpr uint16_t BlockDescriptorConstantDiscriminator = 0xC0BB;
4343

44+
/// Constant discriminator to be used with function pointers in .init_array and
45+
/// .fini_array. The value is ptrauth_string_discriminator("init_fini")
46+
constexpr uint16_t InitFiniPointerConstantDiscriminator = 0xD9D4;
47+
4448
constexpr int PointerAuthKeyNone = -1;
4549

4650
class PointerAuthSchema {
@@ -64,6 +68,7 @@ class PointerAuthSchema {
6468
ObjCMethodListPointer = 7,
6569
ObjCIsaPointer = 8,
6670
BlockDescriptorPointers = 9,
71+
InitFiniPointers = 10,
6772
};
6873

6974
/// Hardware pointer-signing keys in ARM8.3.
@@ -277,6 +282,9 @@ struct PointerAuthOptions {
277282

278283
/// The ABI for Objective-C superclass pointers.
279284
PointerAuthSchema ObjCSuperPointers;
285+
286+
/// The ABI for function addresses in .init_array and .fini_array
287+
PointerAuthSchema InitFiniPointers;
280288
};
281289

282290
} // end namespace clang

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,6 +3895,8 @@ let Group = f_Group in {
38953895
HelpText<"enable signing block descriptors">;
38963896
def fptrauth_function_pointer_type_discrimination : Flag<["-"], "fptrauth-function-pointer-type-discrimination">,
38973897
HelpText<"Enabling type discrimination on C function pointers">;
3898+
def fptrauth_init_fini : Flag<["-"], "fptrauth-init-fini">,
3899+
HelpText<"Enable signing of function pointers in init/fini arrays">;
38983900
def fptrauth_objc_isa : Flag<["-"], "fptrauth-objc-isa">,
38993901
HelpText<"Enable signing and authentication of Objective-C object's 'isa' field">;
39003902
def fptrauth_objc_isa_mode : Joined<["-"], "fptrauth-objc-isa-mode=">,
@@ -3912,6 +3914,7 @@ let Group = f_Group in {
39123914
def fno_ptrauth_objc_isa : Flag<["-"], "fno-ptrauth-objc-isa">;
39133915
def fno_ptrauth_block_descriptor_pointers : Flag<["-"], "fno-ptrauth-block-descriptor-pointers">;
39143916
def fno_ptrauth_function_pointer_type_discrimination : Flag<["-"], "fno-ptrauth-function-pointer-type-discrimination">;
3917+
def fno_ptrauth_init_fini : Flag<["-"], "fno-ptrauth-init-fini">;
39153918
def fno_branch_target_identification : Flag<["-"], "fno-branch-target-identification">;
39163919
}
39173920

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,37 +1944,81 @@ void CodeGenModule::AddGlobalDtor(llvm::Function *Dtor, int Priority,
19441944
void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
19451945
if (Fns.empty()) return;
19461946

1947-
// Ctor function type is void()*.
1948-
llvm::FunctionType* CtorFTy = llvm::FunctionType::get(VoidTy, false);
1949-
llvm::Type *CtorPFTy = llvm::PointerType::get(CtorFTy,
1950-
TheModule.getDataLayout().getProgramAddressSpace());
1951-
1952-
// Get the type of a ctor entry, { i32, void ()*, i8* }.
1953-
llvm::StructType *CtorStructTy = llvm::StructType::get(
1954-
Int32Ty, CtorPFTy, VoidPtrTy);
1955-
1956-
// Construct the constructor and destructor arrays.
1957-
ConstantInitBuilder builder(*this);
1958-
auto ctors = builder.beginArray(CtorStructTy);
1959-
for (const auto &I : Fns) {
1960-
auto ctor = ctors.beginStruct(CtorStructTy);
1961-
ctor.addInt(Int32Ty, I.Priority);
1962-
ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy));
1963-
if (I.AssociatedData)
1964-
ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy));
1965-
else
1966-
ctor.addNullPointer(VoidPtrTy);
1967-
ctor.finishAndAddTo(ctors);
1968-
}
1947+
const PointerAuthSchema &InitFiniAuthSchema =
1948+
getCodeGenOpts().PointerAuth.InitFiniPointers;
1949+
if (InitFiniAuthSchema) {
1950+
// Ctor function type is void()*.
1951+
llvm::FunctionType *CtorFTy = llvm::FunctionType::get(VoidTy, false);
1952+
llvm::Type *CtorPFTy = llvm::PointerType::get(
1953+
CtorFTy, TheModule.getDataLayout().getProgramAddressSpace());
1954+
1955+
llvm::StructType *CtorPauthTy =
1956+
llvm::StructType::get(CtorPFTy, Int32Ty, Int64Ty, Int64Ty);
1957+
llvm::Type *CtorPauthPTy = llvm::PointerType::get(
1958+
CtorPauthTy, TheModule.getDataLayout().getProgramAddressSpace());
1959+
1960+
// Get the type of a ctor entry, { i32, ptr, i8* }.
1961+
llvm::StructType *CtorStructTy =
1962+
llvm::StructType::get(Int32Ty, CtorPauthPTy, VoidPtrTy);
1963+
1964+
// Construct the constructor and destructor arrays.
1965+
ConstantInitBuilder builder(*this);
1966+
auto ctors = builder.beginArray(CtorStructTy);
1967+
for (const auto &I : Fns) {
1968+
auto ctor = ctors.beginStruct(CtorStructTy);
1969+
ctor.addInt(Int32Ty, I.Priority);
1970+
assert(!InitFiniAuthSchema.isAddressDiscriminated());
1971+
llvm::Constant *signedCtorAddr = getConstantSignedPointer(
1972+
I.Initializer, InitFiniAuthSchema.getKey(), 0,
1973+
llvm::ConstantInt::get(
1974+
SizeTy, InitFiniAuthSchema.getConstantDiscrimination()));
1975+
ctor.add(llvm::ConstantExpr::getBitCast(signedCtorAddr, CtorPauthPTy));
1976+
if (I.AssociatedData)
1977+
ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy));
1978+
else
1979+
ctor.addNullPointer(VoidPtrTy);
1980+
ctor.finishAndAddTo(ctors);
1981+
}
1982+
1983+
auto list = ctors.finishAndCreateGlobal(
1984+
GlobalName, getPointerAlign(),
1985+
/*constant*/ false, llvm::GlobalValue::AppendingLinkage);
19691986

1970-
auto list =
1971-
ctors.finishAndCreateGlobal(GlobalName, getPointerAlign(),
1972-
/*constant*/ false,
1973-
llvm::GlobalValue::AppendingLinkage);
1987+
// The LTO linker doesn't seem to like it when we set an alignment
1988+
// on appending variables. Take it off as a workaround.
1989+
list->setAlignment(std::nullopt);
1990+
} else {
1991+
// Ctor function type is void()*.
1992+
llvm::FunctionType *CtorFTy = llvm::FunctionType::get(VoidTy, false);
1993+
llvm::Type *CtorPFTy = llvm::PointerType::get(
1994+
CtorFTy, TheModule.getDataLayout().getProgramAddressSpace());
1995+
1996+
// Get the type of a ctor entry, { i32, void ()*, i8* }.
1997+
llvm::StructType *CtorStructTy =
1998+
llvm::StructType::get(Int32Ty, CtorPFTy, VoidPtrTy);
1999+
2000+
// Construct the constructor and destructor arrays.
2001+
ConstantInitBuilder builder(*this);
2002+
auto ctors = builder.beginArray(CtorStructTy);
2003+
for (const auto &I : Fns) {
2004+
auto ctor = ctors.beginStruct(CtorStructTy);
2005+
ctor.addInt(Int32Ty, I.Priority);
2006+
ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy));
2007+
if (I.AssociatedData)
2008+
ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy));
2009+
else
2010+
ctor.addNullPointer(VoidPtrTy);
2011+
ctor.finishAndAddTo(ctors);
2012+
}
19742013

1975-
// The LTO linker doesn't seem to like it when we set an alignment
1976-
// on appending variables. Take it off as a workaround.
1977-
list->setAlignment(std::nullopt);
2014+
auto list = ctors.finishAndCreateGlobal(
2015+
GlobalName, getPointerAlign(),
2016+
/*constant*/ false, llvm::GlobalValue::AppendingLinkage);
2017+
2018+
// The LTO linker doesn't seem to like it when we set an alignment
2019+
// on appending variables. Take it off as a workaround.
2020+
list->setAlignment(std::nullopt);
2021+
}
19782022

19792023
Fns.clear();
19802024
}

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,12 +1626,6 @@ static void handlePAuthABIOption(const ArgList &DriverArgs,
16261626
options::OPT_fno_ptrauth_auth_traps))
16271627
CC1Args.push_back("-fptrauth-auth-traps");
16281628

1629-
#if 1
1630-
if (!DriverArgs.hasArg(
1631-
options::OPT_fptrauth_block_descriptor_pointers,
1632-
options::OPT_fno_ptrauth_block_descriptor_pointers))
1633-
CC1Args.push_back("-fptrauth-block-descriptor-pointers");
1634-
16351629
if (!DriverArgs.hasArg(
16361630
options::OPT_fptrauth_vtable_pointer_address_discrimination,
16371631
options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
@@ -1642,6 +1636,13 @@ static void handlePAuthABIOption(const ArgList &DriverArgs,
16421636
options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
16431637
CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
16441638

1639+
if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
1640+
options::OPT_fno_ptrauth_init_fini))
1641+
CC1Args.push_back("-fptrauth-init-fini");
1642+
1643+
#if 0
1644+
// Due to implicit casts, code with function pointer type discrimination
1645+
// enabled might be broken.
16451646
if (!DriverArgs.hasArg(
16461647
options::OPT_fptrauth_function_pointer_type_discrimination,
16471648
options::OPT_fno_ptrauth_function_pointer_type_discrimination))
@@ -7079,6 +7080,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70797080
false))
70807081
CmdArgs.push_back("-fptrauth-vtable-pointer-type-discrimination");
70817082

7083+
if (Args.hasFlag(options::OPT_fptrauth_init_fini,
7084+
options::OPT_fno_ptrauth_init_fini,
7085+
false))
7086+
CmdArgs.push_back("-fptrauth-init-fini");
7087+
70827088
if (Args.hasFlag(options::OPT_fptrauth_objc_isa,
70837089
options::OPT_fno_ptrauth_objc_isa, false))
70847090
CmdArgs.push_back("-fptrauth-objc-isa-mode=sign-and-auth");

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,11 @@ bool CompilerInvocation::setDefaultPointerAuthOptions(
14911491
Key::ObjCIsaPointer, true, explicitIsaAuthenticationMode,
14921492
Discrimination::Constant, SuperPointerConstantDiscriminator);
14931493
}
1494+
if (LangOpts.PointerAuthInitFini) {
1495+
Opts.InitFiniPointers = PointerAuthSchema(
1496+
Key::InitFiniPointers, false, Discrimination::Constant,
1497+
InitFiniPointerConstantDiscriminator);
1498+
}
14941499
}
14951500
Opts.ReturnAddresses = LangOpts.PointerAuthReturns;
14961501
Opts.AuthTraps = LangOpts.PointerAuthAuthTraps;
@@ -1546,6 +1551,11 @@ bool CompilerInvocation::setDefaultPointerAuthOptions(
15461551
Key::ASDA, true, explicitIsaAuthenticationMode,
15471552
Discrimination::Constant, SuperPointerConstantDiscriminator);
15481553
}
1554+
if (LangOpts.PointerAuthInitFini) {
1555+
Opts.InitFiniPointers =
1556+
PointerAuthSchema(Key::ASIA, false, Discrimination::Constant,
1557+
InitFiniPointerConstantDiscriminator);
1558+
}
15491559
}
15501560
Opts.ReturnAddresses = LangOpts.PointerAuthReturns;
15511561
Opts.AuthTraps = LangOpts.PointerAuthAuthTraps;
@@ -3443,6 +3453,8 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts,
34433453
}
34443454
if (Opts.PointerAuthObjcIsaMasking)
34453455
GenerateArg(Consumer, OPT_fptrauth_objc_isa_masking);
3456+
if (Opts.PointerAuthInitFini)
3457+
GenerateArg(Consumer, OPT_fptrauth_init_fini);
34463458
}
34473459

34483460
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
@@ -3455,6 +3467,7 @@ static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
34553467
Args.hasArg(OPT_fptrauth_vtable_pointer_address_discrimination);
34563468
Opts.PointerAuthVTPtrTypeDiscrimination =
34573469
Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination);
3470+
Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
34583471
Opts.SoftPointerAuth = Args.hasArg(OPT_fptrauth_soft);
34593472
Opts.PointerAuthBlockDescriptorPointers =
34603473
Args.hasArg(OPT_fptrauth_block_descriptor_pointers);

clang/lib/Headers/ptrauth.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ typedef enum {
8080
/* The key used to sign block descriptor pointers. */
8181
ptrauth_key_block_descriptor_pointer = ptrauth_key_asda,
8282

83+
/* The key used to sign pointers in ELF .init_array/.fini_array. */
84+
ptrauth_key_init_fini_pointer = ptrauth_key_asia,
85+
8386
/* Other pointers signed under the ABI use private ABI rules. */
8487

8588
} ptrauth_key;
@@ -398,6 +401,9 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
398401
__ptrauth(ptrauth_key_cxx_vtable_pointer,0,0)
399402
#define __ptrauth_swift_heap_object_destructor \
400403
__ptrauth(ptrauth_key_function_pointer,1,0xbbbf)
404+
#define __ptrauth_init_fini_discriminator 0xd9d4
405+
#define __ptrauth_init_fini_pointer \
406+
__ptrauth(ptrauth_key_init_fini_pointer, 0, __ptrauth_init_fini_discriminator)
401407

402408
/* Some situations in the C++ and Swift ABIs use declaration-specific
403409
or type-specific extra discriminators. */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// REQUIRES: aarch64-registered-target
2+
// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -mbranch-protection=pauthabi -S -emit-llvm -o - -c %s | FileCheck --check-prefix=SIGNED %s
3+
// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -mbranch-protection=pauthabi -fptrauth-init-fini -S -emit-llvm -o - -c %s | FileCheck --check-prefix=SIGNED %s
4+
// RUN: %clang -target aarch64-elf -march=armv8.3-a+pauth -mbranch-protection=pauthabi -fno-ptrauth-init-fini -S -emit-llvm -o - -c %s | FileCheck --check-prefix=UNSIGNED %s
5+
6+
// SIGNED: @foo.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @foo, i32 0, i64 0, i64 55764 }, section "llvm.ptrauth", align 8
7+
// SIGNED: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @foo.ptrauth, ptr null }]
8+
// SIGNED: @bar.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @bar, i32 0, i64 0, i64 55764 }, section "llvm.ptrauth", align 8
9+
// SIGNED: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @bar.ptrauth, ptr null }]
10+
11+
// UNSIGNED-NOT: @foo.ptrauth
12+
// UNSIGNED: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @foo, ptr null }]
13+
// UNSIGNED-NOT: @bar.ptrauth
14+
// UNSIGNED: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @bar, ptr null }]
15+
16+
17+
volatile int x = 0;
18+
19+
__attribute__((constructor)) void foo(void) {
20+
x = 42;
21+
}
22+
23+
__attribute__((destructor)) void bar(void) {
24+
x = 24;
25+
}
26+
27+
int main() {
28+
return x;
29+
}

clang/test/Preprocessor/ptrauth_feature.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// RUN: %clang_cc1 %s -E -triple=arm64-- -fptrauth-returns | FileCheck %s --check-prefixes=NOCALLS,NOINTRIN,RETS,NOQUAL,NOFUNC
44
// RUN: %clang_cc1 %s -E -triple=arm64-- -fptrauth-intrinsics | FileCheck %s --check-prefixes=NOCALLS,INTRIN,NORETS,QUAL,NOFUNC
55
// RUN: %clang_cc1 %s -E -triple=arm64e-apple-ios6.0 -fptrauth-intrinsics -fptrauth-function-pointer-type-discrimination | FileCheck %s --check-prefixes=NOCALLS,INTRIN,NORETS,QUAL,FUNC
6+
// RUN: %clang -E %s --target=aarch64-elf -mbranch-protection=pauthabi | FileCheck %s --check-prefixes=INITFINI,VPTR_ADDR_DISCR,VPTR_TYPE_DISCR
7+
// RUN: %clang -E %s --target=aarch64-elf -mbranch-protection=pauthabi -fno-ptrauth-init-fini | FileCheck %s --check-prefixes=NOINITFINI
8+
// RUN: %clang -E %s --target=aarch64-elf -mbranch-protection=pauthabi -fno-ptrauth-vtable-pointer-address-discrimination | FileCheck %s --check-prefixes=NOVPTR_ADDR_DISCR
9+
// RUN: %clang -E %s --target=aarch64-elf -mbranch-protection=pauthabi -fno-ptrauth-vtable-pointer-type-discrimination | FileCheck %s --check-prefixes=NOVPTR_TYPE_DISCR
610

711
#if __has_feature(ptrauth_calls)
812
// CALLS: has_ptrauth_calls
@@ -45,6 +49,30 @@ void has_ptrauth_member_function_pointer_type_discrimination() {}
4549
void no_ptrauth_member_function_pointer_type_discrimination() {}
4650
#endif
4751

52+
#if __has_feature(ptrauth_vtable_pointer_address_discrimination)
53+
// VPTR_ADDR_DISCR: has_ptrauth_vtable_pointer_address_discrimination
54+
void has_ptrauth_vtable_pointer_address_discrimination() {}
55+
#else
56+
// NOVPTR_ADDR_DISCR: no_ptrauth_vtable_pointer_address_discrimination
57+
void no_ptrauth_vtable_pointer_address_discrimination() {}
58+
#endif
59+
60+
#if __has_feature(ptrauth_vtable_pointer_type_discrimination)
61+
// VPTR_TYPE_DISCR: has_ptrauth_vtable_pointer_type_discrimination
62+
void has_ptrauth_vtable_pointer_type_discrimination() {}
63+
#else
64+
// NOVPTR_TYPE_DISCR: no_ptrauth_vtable_pointer_type_discrimination
65+
void no_ptrauth_vtable_pointer_type_discrimination() {}
66+
#endif
67+
68+
#if __has_feature(ptrauth_init_fini)
69+
// INITFINI: has_ptrauth_init_fini
70+
void has_ptrauth_init_fini() {}
71+
#else
72+
// NOINITFINI: no_ptrauth_init_fini
73+
void no_ptrauth_init_fini() {}
74+
#endif
75+
4876
#include <ptrauth.h>
4977

5078
#if __has_feature(ptrauth_function_pointer_type_discrimination)

compiler-rt/lib/builtins/crtbegin.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include <stddef.h>
1010

11+
#if __has_feature(ptrauth_calls)
12+
#include <ptrauth.h>
13+
#endif
14+
1115
__attribute__((visibility("hidden"))) void *__dso_handle = &__dso_handle;
1216

1317
#ifdef EH_USE_FRAME_REGISTRY
@@ -35,7 +39,9 @@ static void __attribute__((used)) __do_init(void) {
3539
__initialized = 1;
3640

3741
#ifdef EH_USE_FRAME_REGISTRY
38-
static struct { void *p[8]; } __object;
42+
static struct {
43+
void *p[8];
44+
} __object;
3945
if (__register_frame_info)
4046
__register_frame_info(__EH_FRAME_LIST__, &__object);
4147
#endif
@@ -46,8 +52,13 @@ static void __attribute__((used)) __do_init(void) {
4652
}
4753

4854
#ifdef CRT_HAS_INITFINI_ARRAY
55+
#if __has_feature(ptrauth_calls)
4956
__attribute__((section(".init_array"),
50-
used)) static void (*__init)(void) = __do_init;
57+
used)) static void *__ptrauth_init_fini_pointer __init =
58+
__do_init;
59+
#else
60+
__attribute__((section(".init_array"), used)) static void *__init = __do_init;
61+
#endif
5162
#elif defined(__i386__) || defined(__x86_64__)
5263
__asm__(".pushsection .init,\"ax\",@progbits\n\t"
5364
"call __do_init\n\t"
@@ -103,8 +114,13 @@ static void __attribute__((used)) __do_fini(void) {
103114
}
104115

105116
#ifdef CRT_HAS_INITFINI_ARRAY
117+
#if __has_feature(ptrauth_calls)
106118
__attribute__((section(".fini_array"),
107-
used)) static void (*__fini)(void) = __do_fini;
119+
used)) static void *__ptrauth_init_fini_pointer __fini =
120+
__do_fini;
121+
#else
122+
__attribute__((section(".fini_array"), used)) static void *__fini = __do_fini;
123+
#endif
108124
#elif defined(__i386__) || defined(__x86_64__)
109125
__asm__(".pushsection .fini,\"ax\",@progbits\n\t"
110126
"call __do_fini\n\t"

0 commit comments

Comments
 (0)