Skip to content

Commit 8c2401a

Browse files
committed
[IRGen] Generate plausible signature for .cxx_{construct,destruct}
"@?" is not a method signature. An acceptable format is "vM@0:N", where N is the pointer size and M is twice the pointer size. The numeric values don't matter anymore on Apple platforms because the runtime does not rely on them (they used to be stack offsets from the base pointer), but given that the first (self) and second (_cmd) parameters are pointers, the expected value is easily obtained and it is probably good style to include it. Fixes https://bugs.swift.org/browse/SR-8203
1 parent 131b860 commit 8c2401a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/IRGen/GenObjC.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,9 @@ void irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
11591159
/// The first element is the selector.
11601160
selectorRef = IGM.getAddrOfObjCMethodName(selector.str());
11611161

1162-
/// The second element is the type @encoding.
1162+
/// The second element is the method signature. A method signature is made of
1163+
/// the return type @encoding and every parameter type @encoding, glued with
1164+
/// numbers that used to represent stack offsets for each of these elements.
11631165
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
11641166
atEncoding = getObjCEncodingForMethodType(IGM, methodType, extendedEncoding);
11651167

@@ -1349,9 +1351,13 @@ void irgen::emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
13491351
Selector selector(declRef);
13501352
auto selectorRef = IGM.getAddrOfObjCMethodName(selector.str());
13511353

1352-
/// The second element is the type @encoding, which is always "@?"
1353-
/// for a function type.
1354-
auto atEncoding = IGM.getAddrOfGlobalString("@?");
1354+
/// The second element is the method signature. A method signature is made of
1355+
/// the return type @encoding and every parameter type @encoding, glued with
1356+
/// numbers that used to represent stack offsets for each of these elements.
1357+
auto ptrSize = IGM.getPointerSize().getValue();
1358+
llvm::SmallString<8> signature;
1359+
signature = "v" + llvm::itostr(ptrSize * 2) + "@0:" + llvm::itostr(ptrSize);
1360+
auto atEncoding = IGM.getAddrOfGlobalString(signature);
13551361

13561362
/// The third element is the method implementation pointer.
13571363
auto impl = llvm::ConstantExpr::getBitCast(objcImpl, IGM.Int8PtrTy);

0 commit comments

Comments
 (0)