@@ -670,55 +670,63 @@ static void setPointerAuthOptions(PointerAuthOptions &opts,
670
670
return ;
671
671
672
672
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;
675
686
676
687
// If you change anything here, be sure to update <ptrauth.h>.
677
688
opts.SwiftFunctionPointers =
678
- PointerAuthSchema (key , /* address*/ false , Discrimination::Type);
689
+ PointerAuthSchema (codeKey , /* address*/ false , Discrimination::Type);
679
690
opts.KeyPaths =
680
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
691
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
681
692
opts.ValueWitnesses =
682
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
693
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
683
694
opts.ProtocolWitnesses =
684
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
695
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
685
696
opts.ProtocolAssociatedTypeAccessFunctions =
686
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
697
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
687
698
opts.ProtocolAssociatedTypeWitnessTableAccessFunctions =
688
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
699
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
689
700
opts.SwiftClassMethods =
690
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
701
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
691
702
opts.SwiftClassMethodPointers =
692
- PointerAuthSchema (key , /* address*/ false , Discrimination::Decl);
703
+ PointerAuthSchema (codeKey , /* address*/ false , Discrimination::Decl);
693
704
opts.HeapDestructors =
694
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
705
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
695
706
696
707
// Partial-apply captures are not ABI and can use a more aggressive key.
697
708
opts.PartialApplyCapture =
698
- PointerAuthSchema (nonABIKey , /* address*/ true , Discrimination::Decl);
709
+ PointerAuthSchema (nonABICodeKey , /* address*/ true , Discrimination::Decl);
699
710
700
711
opts.TypeDescriptors =
701
- PointerAuthSchema (PointerAuthSchema::ARM8_3Key::ASDA, /* address*/ true ,
702
- Discrimination::Decl);
712
+ PointerAuthSchema (dataKey, /* address*/ true , Discrimination::Decl);
703
713
opts.TypeDescriptorsAsArguments =
704
- PointerAuthSchema (PointerAuthSchema::ARM8_3Key::ASDA, /* address*/ false ,
705
- Discrimination::Decl);
714
+ PointerAuthSchema (dataKey, /* address*/ false , Discrimination::Decl);
706
715
707
716
opts.SwiftDynamicReplacements =
708
- PointerAuthSchema (key , /* address*/ true , Discrimination::Decl);
717
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Decl);
709
718
opts.SwiftDynamicReplacementKeys =
710
- PointerAuthSchema (PointerAuthSchema::ARM8_3Key::ASDA, /* address*/ true ,
711
- Discrimination::Decl);
719
+ PointerAuthSchema (dataKey, /* address*/ true , Discrimination::Decl);
712
720
713
721
// Coroutine resumption functions are never stored globally in the ABI,
714
722
// so we can do some things that aren't normally okay to do. However,
715
723
// we can't use ASIB because that would break ARM64 interoperation.
716
724
// The address used in the discrimination is not the address where the
717
725
// function pointer is signed, but the address of the coroutine buffer.
718
726
opts.YieldManyResumeFunctions =
719
- PointerAuthSchema (key , /* address*/ true , Discrimination::Type);
727
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Type);
720
728
opts.YieldOnceResumeFunctions =
721
- PointerAuthSchema (key , /* address*/ true , Discrimination::Type);
729
+ PointerAuthSchema (codeKey , /* address*/ true , Discrimination::Type);
722
730
}
723
731
724
732
std::unique_ptr<llvm::TargetMachine>
0 commit comments