Skip to content

IRGen: Name the symbol for the private use area attached to protocol conformance descriptors. #32861

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ Globals
global ::= entity 'Wvd' // field offset
global ::= entity 'WC' // resilient enum tag index

global ::= global 'MK' // instantiation cache associated with global

A direct symbol resolves directly to the address of an object. An
indirect symbol resolves to the address of a pointer to the object.
They are distinct manglings to make a certain class of bugs
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,8 @@ CONTEXT_NODE(OpaqueReturnTypeOf)
NODE(CanonicalSpecializedGenericMetaclass)
NODE(CanonicalSpecializedGenericTypeMetadataAccessFunction)

// Added in Swift 5.4
NODE(MetadataInstantiationCache)

#undef CONTEXT_NODE
#undef NODE
3 changes: 3 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,9 @@ NodePointer Demangler::demangleMetatype() {
case 'j':
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorKey,
popNode());
case 'K':
return createWithChild(Node::Kind::MetadataInstantiationCache,
popNode());
case 'k':
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorVar,
popNode());
Expand Down
5 changes: 5 additions & 0 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class NodePrinter {
case Node::Kind::PropertyDescriptor:
case Node::Kind::ProtocolConformance:
case Node::Kind::ProtocolConformanceDescriptor:
case Node::Kind::MetadataInstantiationCache:
case Node::Kind::ProtocolDescriptor:
case Node::Kind::ProtocolRequirementsBaseDescriptor:
case Node::Kind::ProtocolSelfConformanceDescriptor:
Expand Down Expand Up @@ -2433,6 +2434,10 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
Printer << "canonical specialized generic type metadata accessor for ";
print(Node->getChild(0));
return nullptr;
case Node::Kind::MetadataInstantiationCache:
Printer << "metadata instantiation cache for ";
print(Node->getChild(0));
return nullptr;
}
printer_unreachable("bad node kind!");
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,9 @@ void Remangler::mangleOpaqueTypeDescriptorAccessorVar(Node *node) {
void Remangler::mangleAccessorFunctionReference(Node *node) {
unreachable("can't remangle");
}
void Remangler::mangleMetadataInstantiationCache(Node *node) {
unreachable("unsupported");
}

void Remangler::mangleCanonicalSpecializedGenericMetaclass(Node *node) {
Buffer << "MM";
Expand Down
5 changes: 5 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,11 @@ void Remangler::mangleCanonicalSpecializedGenericTypeMetadataAccessFunction(
Buffer << "Mb";
}

void Remangler::mangleMetadataInstantiationCache(Node *node) {
mangleSingleChildNode(node);
Buffer << "MK";
}

} // anonymous namespace

/// The top-level interface to the remangler.
Expand Down
7 changes: 6 additions & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,16 @@ namespace {
llvm::ArrayType::get(IGM.Int8PtrTy,
swift::NumGenericMetadataPrivateDataWords);
auto privateDataInit = llvm::Constant::getNullValue(privateDataTy);

IRGenMangler mangler;
auto symbolName =
mangler.mangleProtocolConformanceInstantiationCache(Conformance);

auto privateData =
new llvm::GlobalVariable(IGM.Module, privateDataTy,
/*constant*/ false,
llvm::GlobalVariable::InternalLinkage,
privateDataInit, "");
privateDataInit, symbolName);
B.addRelativeAddress(privateData);
}
}
Expand Down
17 changes: 17 additions & 0 deletions lib/IRGen/IRGenMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
});
}



std::string IRGenMangler::mangleProtocolConformanceDescriptor(
const RootProtocolConformance *conformance) {
beginMangling();
Expand All @@ -157,6 +159,21 @@ std::string IRGenMangler::mangleProtocolConformanceDescriptor(
return finalize();
}

std::string IRGenMangler::mangleProtocolConformanceInstantiationCache(
const RootProtocolConformance *conformance) {
beginMangling();
if (isa<NormalProtocolConformance>(conformance)) {
appendProtocolConformance(conformance);
appendOperator("Mc");
} else {
auto protocol = cast<SelfProtocolConformance>(conformance)->getProtocol();
appendProtocolName(protocol);
appendOperator("MS");
}
appendOperator("MK");
return finalize();
}

SymbolicMangling
IRGenMangler::mangleProtocolConformanceForReflection(IRGenModule &IGM,
Type ty, ProtocolConformanceRef conformance) {
Expand Down
6 changes: 4 additions & 2 deletions lib/IRGen/IRGenMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,10 @@ class IRGenMangler : public Mangle::ASTMangler {
}

std::string mangleProtocolConformanceDescriptor(
const RootProtocolConformance *conformance);

const RootProtocolConformance *conformance);
std::string mangleProtocolConformanceInstantiationCache(
const RootProtocolConformance *conformance);

std::string manglePropertyDescriptor(const AbstractStorageDecl *storage) {
beginMangling();
appendEntity(storage);
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/protocol_resilience_descriptors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public struct Y { }
// -- instantiator function
// CHECK-USAGE-SAME: i32 0,
// -- private data area
// CHECK-USAGE-SAME: {{@[0-9]+}}
// CHECK-USAGE-SAME: "$s31protocol_resilience_descriptors1YV010resilient_A022OtherResilientProtocolAAMcMK"
// --
// CHECK-USAGE-SAME: }
extension Y: OtherResilientProtocol { }
Expand Down