Skip to content

Commit 05f92f1

Browse files
authored
Merge pull request #30396 from rjmccall/key-is-code-key
More descriptive names and comments; NFC
2 parents 710799d + 2d25b66 commit 05f92f1

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -670,55 +670,63 @@ static void setPointerAuthOptions(PointerAuthOptions &opts,
670670
return;
671671

672672
using Discrimination = PointerAuthSchema::Discrimination;
673-
auto key = clangOpts.FunctionPointers.getARM8_3Key();
674-
auto nonABIKey = PointerAuthSchema::ARM8_3Key::ASIB;
673+
674+
// A key suitable for code pointers that might be used anywhere in the ABI.
675+
auto codeKey = clangOpts.FunctionPointers.getARM8_3Key();
676+
677+
// A key suitable for data pointers that might be used anywhere in the ABI.
678+
// Using a data key for data pointers and vice-versa is important for
679+
// ABI future-proofing.
680+
auto dataKey = PointerAuthSchema::ARM8_3Key::ASDA;
681+
682+
// A key suitable for code pointers that are only used in private
683+
// situations. Do not use this key for any sort of signature that
684+
// might end up on a global constant initializer.
685+
auto nonABICodeKey = PointerAuthSchema::ARM8_3Key::ASIB;
675686

676687
// If you change anything here, be sure to update <ptrauth.h>.
677688
opts.SwiftFunctionPointers =
678-
PointerAuthSchema(key, /*address*/ false, Discrimination::Type);
689+
PointerAuthSchema(codeKey, /*address*/ false, Discrimination::Type);
679690
opts.KeyPaths =
680-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
691+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
681692
opts.ValueWitnesses =
682-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
693+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
683694
opts.ProtocolWitnesses =
684-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
695+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
685696
opts.ProtocolAssociatedTypeAccessFunctions =
686-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
697+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
687698
opts.ProtocolAssociatedTypeWitnessTableAccessFunctions =
688-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
699+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
689700
opts.SwiftClassMethods =
690-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
701+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
691702
opts.SwiftClassMethodPointers =
692-
PointerAuthSchema(key, /*address*/ false, Discrimination::Decl);
703+
PointerAuthSchema(codeKey, /*address*/ false, Discrimination::Decl);
693704
opts.HeapDestructors =
694-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
705+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
695706

696707
// Partial-apply captures are not ABI and can use a more aggressive key.
697708
opts.PartialApplyCapture =
698-
PointerAuthSchema(nonABIKey, /*address*/ true, Discrimination::Decl);
709+
PointerAuthSchema(nonABICodeKey, /*address*/ true, Discrimination::Decl);
699710

700711
opts.TypeDescriptors =
701-
PointerAuthSchema(PointerAuthSchema::ARM8_3Key::ASDA, /*address*/ true,
702-
Discrimination::Decl);
712+
PointerAuthSchema(dataKey, /*address*/ true, Discrimination::Decl);
703713
opts.TypeDescriptorsAsArguments =
704-
PointerAuthSchema(PointerAuthSchema::ARM8_3Key::ASDA, /*address*/ false,
705-
Discrimination::Decl);
714+
PointerAuthSchema(dataKey, /*address*/ false, Discrimination::Decl);
706715

707716
opts.SwiftDynamicReplacements =
708-
PointerAuthSchema(key, /*address*/ true, Discrimination::Decl);
717+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Decl);
709718
opts.SwiftDynamicReplacementKeys =
710-
PointerAuthSchema(PointerAuthSchema::ARM8_3Key::ASDA, /*address*/ true,
711-
Discrimination::Decl);
719+
PointerAuthSchema(dataKey, /*address*/ true, Discrimination::Decl);
712720

713721
// Coroutine resumption functions are never stored globally in the ABI,
714722
// so we can do some things that aren't normally okay to do. However,
715723
// we can't use ASIB because that would break ARM64 interoperation.
716724
// The address used in the discrimination is not the address where the
717725
// function pointer is signed, but the address of the coroutine buffer.
718726
opts.YieldManyResumeFunctions =
719-
PointerAuthSchema(key, /*address*/ true, Discrimination::Type);
727+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Type);
720728
opts.YieldOnceResumeFunctions =
721-
PointerAuthSchema(key, /*address*/ true, Discrimination::Type);
729+
PointerAuthSchema(codeKey, /*address*/ true, Discrimination::Type);
722730
}
723731

724732
std::unique_ptr<llvm::TargetMachine>

0 commit comments

Comments
 (0)