Skip to content

Commit 23ccaba

Browse files
committed
Add a mangling for constant static arrays.
The layout of constant static arrays differs from non-constant static arrays. Therefore use a different mangling to get symbol mismatches if for some reason two modules don't agree on which version a static array is.
1 parent 30cb7a2 commit 23ccaba

File tree

7 files changed

+23
-0
lines changed

7 files changed

+23
-0
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ Entities
349349
entity-spec ::= 'fE' // ivar destroyer; untyped
350350
entity-spec ::= 'fe' // ivar initializer; untyped
351351
entity-spec ::= 'Tv' NATURAL // outlined global variable (from context function)
352+
entity-spec ::= 'Tv' NATURAL 'r' // outlined global read-only object
352353
entity-spec ::= 'Te' bridge-spec // outlined objective c method call
353354

354355
entity-spec ::= decl-name label-list function-signature generic-signature? 'F' // function

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ NODE(OutlinedAssignWithTake)
279279
NODE(OutlinedAssignWithCopy)
280280
NODE(OutlinedDestroy)
281281
NODE(OutlinedVariable)
282+
NODE(OutlinedReadOnlyObject)
282283
NODE(AssocTypePath)
283284
NODE(LabelList)
284285
NODE(ModuleDescriptor)

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
131131
case Node::Kind::PartialApplyForwarder:
132132
case Node::Kind::PartialApplyObjCForwarder:
133133
case Node::Kind::OutlinedVariable:
134+
case Node::Kind::OutlinedReadOnlyObject:
134135
case Node::Kind::OutlinedBridgedMethod:
135136
case Node::Kind::MergedFunction:
136137
case Node::Kind::DistributedThunk:
@@ -2615,6 +2616,8 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
26152616
int Idx = demangleIndex();
26162617
if (Idx < 0)
26172618
return nullptr;
2619+
if (nextChar() == 'r')
2620+
return createNode(Node::Kind::OutlinedReadOnlyObject, Idx);
26182621
return createNode(Node::Kind::OutlinedVariable, Idx);
26192622
}
26202623
case 'e': {

lib/Demangling/NodePrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ class NodePrinter {
547547
case Node::Kind::OutlinedAssignWithCopy:
548548
case Node::Kind::OutlinedDestroy:
549549
case Node::Kind::OutlinedVariable:
550+
case Node::Kind::OutlinedReadOnlyObject:
550551
case Node::Kind::AssocTypePath:
551552
case Node::Kind::ModuleDescriptor:
552553
case Node::Kind::AnonymousDescriptor:
@@ -1265,6 +1266,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
12651266
case Node::Kind::OutlinedVariable:
12661267
Printer << "outlined variable #" << Node->getIndex() << " of ";
12671268
return nullptr;
1269+
case Node::Kind::OutlinedReadOnlyObject:
1270+
Printer << "outlined read-only object #" << Node->getIndex() << " of ";
1271+
return nullptr;
12681272
case Node::Kind::Directness:
12691273
Printer << toString(Directness(Node->getIndex())) << " ";
12701274
return nullptr;

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,11 @@ ManglingError Remangler::mangleOutlinedVariable(Node *node, unsigned depth) {
24672467
return mangleSingleChildNode(node, depth + 1);
24682468
}
24692469

2470+
ManglingError Remangler::mangleOutlinedReadOnlyObject(Node *node, unsigned depth) {
2471+
Buffer << "Tv" << node->getIndex() << 'r';
2472+
return mangleSingleChildNode(node, depth + 1);
2473+
}
2474+
24702475
ManglingError Remangler::mangleOutlinedBridgedMethod(Node *node,
24712476
unsigned depth) {
24722477
Buffer << "Te" << node->getText();

lib/Demangling/Remangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@ ManglingError Remangler::mangleGlobal(Node *node, unsigned depth) {
16281628
case Node::Kind::GenericPartialSpecializationNotReAbstracted:
16291629
case Node::Kind::OutlinedBridgedMethod:
16301630
case Node::Kind::OutlinedVariable:
1631+
case Node::Kind::OutlinedReadOnlyObject:
16311632
case Node::Kind::ObjCAttribute:
16321633
case Node::Kind::NonObjCAttribute:
16331634
case Node::Kind::DynamicAttribute:
@@ -3153,6 +3154,13 @@ ManglingError Remangler::mangleOutlinedVariable(Node *node, unsigned depth) {
31533154
return ManglingError::Success;
31543155
}
31553156

3157+
ManglingError Remangler::mangleOutlinedReadOnlyObject(Node *node, unsigned depth) {
3158+
Buffer << "Tv";
3159+
mangleIndex(node->getIndex());
3160+
Buffer << 'r';
3161+
return ManglingError::Success;
3162+
}
3163+
31563164
ManglingError Remangler::mangleOutlinedBridgedMethod(Node *node,
31573165
unsigned depth) {
31583166
Buffer << "Te";

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ _$S3abc6testityySiFTm ---> merged abc.testit(Swift.Int) -> ()
294294
_$S4main4TestC1xACSi_tc6_PRIV_Llfc ---> main.Test.(in _PRIV_).init(x: Swift.Int) -> main.Test
295295
_T0SqWOy.17 ---> outlined copy of Swift.Optional with unmangled suffix ".17"
296296
_T03nix6testitSaySiGyFTv_ ---> outlined variable #0 of nix.testit() -> [Swift.Int]
297+
_T03nix6testitSaySiGyFTv_r ---> outlined read-only object #0 of nix.testit() -> [Swift.Int]
297298
_T03nix6testitSaySiGyFTv0_ ---> outlined variable #1 of nix.testit() -> [Swift.Int]
298299
_T0So11UITextFieldC4textSSSgvgToTepb_ ---> outlined bridged method (pb) of @objc __C.UITextField.text.getter : Swift.String?
299300
_T0So11UITextFieldC4textSSSgvgToTeab_ ---> outlined bridged method (ab) of @objc __C.UITextField.text.getter : Swift.String?

0 commit comments

Comments
 (0)