|
26 | 26 | #include "GenDecl.h"
|
27 | 27 | #include "GenMeta.h"
|
28 | 28 | #include "GenOpaque.h"
|
| 29 | +#include "GenPointerAuth.h" |
29 | 30 | #include "GenProto.h"
|
30 | 31 | #include "GenType.h"
|
31 | 32 | #include "IRGenDebugInfo.h"
|
@@ -588,9 +589,26 @@ static llvm::Value *lookupWitnessTable(IRGenFunction &IGF, llvm::Value *witness,
|
588 | 589 | assert(Lowering::TypeConverter::protocolRequiresWitnessTable(protocol));
|
589 | 590 |
|
590 | 591 | auto &IGM = IGF.IGM;
|
591 |
| - auto *protocolDescriptor = IGM.getAddrOfProtocolDescriptor(protocol); |
| 592 | + llvm::Value *protocolDescriptor = IGM.getAddrOfProtocolDescriptor(protocol); |
| 593 | + |
| 594 | + bool signedProtocolDescriptor = IGM.getAvailabilityRange().isContainedIn( |
| 595 | + IGM.Context.getSignedConformsToProtocolAvailability()); |
| 596 | + |
| 597 | + auto conformsToProtocolFunctionPointer = signedProtocolDescriptor ? |
| 598 | + IGM.getConformsToProtocol2FunctionPointer() : |
| 599 | + IGM.getConformsToProtocolFunctionPointer(); |
| 600 | + |
| 601 | + // Sign the protocol descriptor. |
| 602 | + auto schema = IGF.IGM.getOptions().PointerAuth.ProtocolDescriptorsAsArguments; |
| 603 | + if (schema && signedProtocolDescriptor) { |
| 604 | + auto authInfo = PointerAuthInfo::emit( |
| 605 | + IGF, schema, nullptr, |
| 606 | + PointerAuthEntity::Special::ProtocolDescriptorAsArgument); |
| 607 | + protocolDescriptor = emitPointerAuthSign(IGF, protocolDescriptor, authInfo); |
| 608 | + } |
| 609 | + |
592 | 610 | auto *witnessTable = IGF.Builder.CreateCall(
|
593 |
| - IGM.getConformsToProtocolFunctionPointer(), {witness, protocolDescriptor}); |
| 611 | + conformsToProtocolFunctionPointer, {witness, protocolDescriptor}); |
594 | 612 |
|
595 | 613 | auto failBB = IGF.createBasicBlock("missing-witness");
|
596 | 614 | auto contBB = IGF.createBasicBlock("");
|
|
0 commit comments