-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CodeGen][AArch64][FMV] PAC the stub_helper's frame on arm64e #84704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
b352a41
73aa834
499382f
492d65f
ec43ccb
bd8b5e1
96dbf9f
94ce822
4d5b066
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals --include-generated-funcs | ||
// RUN: %clang_cc1 -triple arm64e-apple-ios -target-feature +ls64 -target-feature +fullfp16 -S -emit-llvm -o - %s | FileCheck %s | ||
|
||
int __attribute__((target_version("sha1"))) fmv(void) { return 1; } | ||
int __attribute__((target_version("default"))) fmv(void) { return 0; } | ||
int foo() { | ||
return fmv(); | ||
} | ||
|
||
//. | ||
// CHECK: @__aarch64_cpu_features = external dso_local global { i64 } | ||
// CHECK: @fmv.ifunc = weak_odr alias i32 (), ptr @fmv | ||
// CHECK: @fmv = weak_odr ifunc i32 (), ptr @fmv.resolver | ||
//. | ||
// CHECK: Function Attrs: noinline nounwind optnone | ||
// CHECK-LABEL: define {{[^@]+}}@fmv._Msha1 | ||
// CHECK-SAME: () #[[ATTR0:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: ret i32 1 | ||
// | ||
// | ||
// CHECK: Function Attrs: noinline nounwind optnone | ||
// CHECK-LABEL: define {{[^@]+}}@foo | ||
// CHECK-SAME: () #[[ATTR1:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[CALL:%.*]] = call i32 @fmv() | ||
// CHECK-NEXT: ret i32 [[CALL]] | ||
// | ||
// | ||
// CHECK-LABEL: define {{[^@]+}}@fmv.resolver | ||
// CHECK-SAME: () #[[ATTR2:[0-9]+]] { | ||
// CHECK-NEXT: resolver_entry: | ||
// CHECK-NEXT: call void @__init_cpu_features_resolver() | ||
// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8 | ||
// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 2048 | ||
// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 2048 | ||
// CHECK-NEXT: [[TMP3:%.*]] = and i1 true, [[TMP2]] | ||
// CHECK-NEXT: br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label [[RESOLVER_ELSE:%.*]] | ||
// CHECK: resolver_return: | ||
// CHECK-NEXT: ret ptr @fmv._Msha1 | ||
// CHECK: resolver_else: | ||
// CHECK-NEXT: ret ptr @fmv.default | ||
// | ||
// | ||
// CHECK: Function Attrs: noinline nounwind optnone | ||
// CHECK-LABEL: define {{[^@]+}}@fmv.default | ||
// CHECK-SAME: () #[[ATTR1]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: ret i32 0 | ||
// | ||
//. | ||
// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+ls64,+neon" } | ||
// CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fullfp16,+ls64" } | ||
// CHECK: attributes #[[ATTR2]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fullfp16,+ls64" } | ||
//. | ||
// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} | ||
// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} | ||
//. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,8 @@ class AArch64AsmPrinter : public AsmPrinter { | |
assert(STI); | ||
return STI; | ||
} | ||
const MCExpr * | ||
emitMachOIfuncLazyPointerInit(const MCSymbolRefExpr *Init) override; | ||
void emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI, | ||
MCSymbol *LazyPointer) override; | ||
void emitMachOIFuncStubHelperBody(Module &M, const GlobalIFunc &GI, | ||
|
@@ -1897,6 +1899,15 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) { | |
EmitToStreamer(*OutStreamer, TmpInst); | ||
} | ||
|
||
const MCExpr * | ||
AArch64AsmPrinter::emitMachOIfuncLazyPointerInit(const MCSymbolRefExpr *Init) { | ||
if (TM.getTargetTriple().isArm64e()) | ||
return AArch64AuthMCExpr::create(Init, /*Disc=*/0, AArch64PACKey::IA, | ||
/*HasAddressDiversity=*/false, OutContext); | ||
|
||
return Init; | ||
} | ||
|
||
void AArch64AsmPrinter::emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI, | ||
MCSymbol *LazyPointer) { | ||
// _ifunc: | ||
|
@@ -1980,6 +1991,9 @@ void AArch64AsmPrinter::emitMachOIFuncStubHelperBody(Module &M, | |
// ldp fp, lr, [sp], #16 | ||
// br x16 | ||
|
||
if (TM.getTargetTriple().isArm64e()) | ||
OutStreamer->emitInstruction(MCInstBuilder(AArch64::PACIBSP), *STI); | ||
|
||
OutStreamer->emitInstruction(MCInstBuilder(AArch64::STPXpre) | ||
.addReg(AArch64::SP) | ||
.addReg(AArch64::FP) | ||
|
@@ -2085,6 +2099,37 @@ void AArch64AsmPrinter::emitMachOIFuncStubHelperBody(Module &M, | |
.addImm(2), | ||
*STI); | ||
|
||
if (TM.getTargetTriple().isArm64e()) { | ||
// autibsp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave the tail-call checking for the general tail-call checking patches, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a PR up for that that I should tack this bit onto the end of? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is not, but send me your patch and I'll tack it onto the relevant commit (and split the tail-call check emission into a helper) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// eor x17, lr, lr, lsl #1 | ||
// tbz x17, #62, Lgoodsig | ||
// brk #0xc741 | ||
// Lgoodsig: | ||
|
||
OutStreamer->emitInstruction(MCInstBuilder(AArch64::AUTIBSP), *STI); | ||
|
||
OutStreamer->emitInstruction(MCInstBuilder(AArch64::EORXrs) | ||
.addReg(AArch64::X17) | ||
.addReg(AArch64::LR) | ||
.addReg(AArch64::LR) | ||
.addImm(1), | ||
*STI); | ||
|
||
MCContext &Ctx = OutStreamer->getContext(); | ||
MCSymbol *GoodSigSym = Ctx.createTempSymbol(); | ||
const MCExpr *GoodSig = MCSymbolRefExpr::create(GoodSigSym, Ctx); | ||
OutStreamer->emitInstruction(MCInstBuilder(AArch64::TBZX) | ||
.addReg(AArch64::X17) | ||
.addImm(62) | ||
.addExpr(GoodSig), | ||
*STI); | ||
|
||
OutStreamer->emitInstruction(MCInstBuilder(AArch64::BRK).addImm(0xc471), | ||
*STI); | ||
|
||
OutStreamer->emitLabel(GoodSigSym); | ||
} | ||
|
||
OutStreamer->emitInstruction(MCInstBuilder(TM.getTargetTriple().isArm64e() | ||
? AArch64::BRAAZ | ||
: AArch64::BR) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The machinery to sign these hasn't been upstreamed yet, but they'll be e.g.
@fmv.default.pauth
when that happens.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks useful for arm64 as well, could you reveal more details on the machinery and approach to PAC resolver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing that's missing is this:
https://github.com/apple/llvm-project/blob/970b6231f607e211c23e15a582572e6f18f4e6b2/clang/include/clang/CodeGen/CodeGenABITypes.h#L122-L126
along with this hunk:
This arranges for the resolver to return signed function pointers. There is no difference for arm64(non-e).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asl the check in the hunk above should be generalized for ELF, and only turned on with
-fptrauth-calls
. I wasn't sure how to get a QualType here though, which would be needed to get theCGPointerAuthInfo
that this would make the check on. Not sure if it's reasonable to "invent" one that's close enough, e.g. forvoid (*fn_ptr)(void);
or something.