Skip to content

Commit a0713ad

Browse files
committed
[ObjC][Gen] Emit ObjC strings to respective sections
1 parent 8c5acc0 commit a0713ad

File tree

9 files changed

+57
-37
lines changed

9 files changed

+57
-37
lines changed

lib/IRGen/GenBuiltin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14011401
auto clangTy = IGF.IGM.getClangType(valueTy->getCanonicalType());
14021402
std::string encoding;
14031403
IGF.IGM.getClangASTContext().getObjCEncodingForType(clangTy, encoding);
1404-
1405-
auto globalString = IGF.IGM.getAddrOfGlobalString(encoding);
1404+
1405+
auto globalString = IGF.IGM.getAddrOfGlobalString(
1406+
encoding, /*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
14061407
out.add(globalString);
14071408
return;
14081409
}

lib/IRGen/GenClass.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ namespace {
14641464

14651465
// struct category_t {
14661466
// char const *name;
1467-
fields.add(IGM.getAddrOfGlobalString(CategoryName));
1467+
fields.add(IGM.getAddrOfGlobalString(CategoryName, /*sectionName=*/"__TEXT,__objc_classname,cstring_literals")));
14681468
// const class_t *theClass;
14691469
fields.add(getClassMetadataRef());
14701470
// const method_list_t *instanceMethods;
@@ -1503,7 +1503,7 @@ namespace {
15031503
// Class super;
15041504
fields.addNullPointer(IGM.Int8PtrTy);
15051505
// char const *name;
1506-
fields.add(IGM.getAddrOfGlobalString(getEntityName(nameBuffer)));
1506+
fields.add(IGM.getAddrOfGlobalString(getEntityName(nameBuffer), /*sectionName=*/"__TEXT,__objc_classname,cstring_literals")));
15071507
// const protocol_list_t *baseProtocols;
15081508
fields.add(buildProtocolList(weakLinkage));
15091509
// const method_list_t *requiredInstanceMethods;
@@ -1724,7 +1724,7 @@ namespace {
17241724
}
17251725

17261726
llvm::SmallString<64> buffer;
1727-
Name = IGM.getAddrOfGlobalString(getClass()->getObjCRuntimeName(buffer));
1727+
Name = IGM.getAddrOfGlobalString(getClass()->getObjCRuntimeName(buffer), /*sectionName=*/"__TEXT,__objc_classname,cstring_literals"));
17281728
return Name;
17291729
}
17301730

@@ -2088,11 +2088,8 @@ namespace {
20882088
else
20892089
fields.addNullPointer(IGM.PtrTy);
20902090

2091-
// TODO: clang puts this in __TEXT,__objc_methname,cstring_literals
2092-
fields.add(IGM.getAddrOfGlobalString(name));
2093-
2094-
// TODO: clang puts this in __TEXT,__objc_methtype,cstring_literals
2095-
fields.add(IGM.getAddrOfGlobalString(typeEnc));
2091+
fields.add(IGM.getAddrOfGlobalString(name), /*sectionName=*/"__TEXT,__objc_methname,cstring_literals"));
2092+
fields.add(IGM.getAddrOfGlobalString(typeEnc), /*sectionName=*/"__TEXT,__objc_methtype,cstring_literals"));
20962093

20972094
Size size;
20982095
Alignment alignment;
@@ -2228,8 +2225,8 @@ namespace {
22282225
buildPropertyAttributes(prop, propertyAttributes);
22292226

22302227
auto fields = properties.beginStruct();
2231-
fields.add(IGM.getAddrOfGlobalString(prop->getObjCPropertyName().str()));
2232-
fields.add(IGM.getAddrOfGlobalString(propertyAttributes));
2228+
fields.add(IGM.getAddrOfGlobalString(prop->getObjCPropertyName().str(), /*sectionName=*/"__TEXT,__objc_methname,cstring_literals")));
2229+
fields.add(IGM.getAddrOfGlobalString(propertyAttributes, /*sectionName=*/"__TEXT,__objc_methname,cstring_literals")));
22332230
fields.finishAndAddTo(properties);
22342231
}
22352232

lib/IRGen/GenConstant.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ llvm::Constant *irgen::emitAddrOfConstantString(IRGenModule &IGM,
7979
case StringLiteralInst::Encoding::Bytes:
8080
case StringLiteralInst::Encoding::UTF8:
8181
case StringLiteralInst::Encoding::UTF8_OSLOG:
82-
return IGM.getAddrOfGlobalString(SLI->getValue(), false, useOSLogEncoding);
82+
return IGM.getAddrOfGlobalString(SLI->getValue(), /*sectionName=*/"", false,
83+
useOSLogEncoding);
8384

8485
case StringLiteralInst::Encoding::ObjCSelector:
8586
llvm_unreachable("cannot get the address of an Objective-C selector");

lib/IRGen/GenDecl.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,10 @@ class ObjCProtocolInitializerVisitor
296296
// Check if the ObjC runtime already has a descriptor for this
297297
// protocol. If so, use it.
298298
SmallString<32> buf;
299-
auto protocolName
300-
= IGM.getAddrOfGlobalString(proto->getObjCRuntimeName(buf));
301-
299+
auto protocolName = IGM.getAddrOfGlobalString(
300+
proto->getObjCRuntimeName(buf),
301+
/*sectionName=*/"__TEXT,__objc_classname,cstring_literals");
302+
302303
auto existing = Builder.CreateCall(objc_getProtocol, protocolName);
303304
auto isNull = Builder.CreateICmpEQ(existing,
304305
llvm::ConstantPointerNull::get(IGM.ProtocolDescriptorPtrTy));
@@ -4241,8 +4242,9 @@ getObjCClassByNameReference(IRGenModule &IGM, ClassDecl *cls) {
42414242
auto kind = TypeReferenceKind::DirectObjCClassName;
42424243
SmallString<64> objcRuntimeNameBuffer;
42434244
auto ref = IGM.getAddrOfGlobalString(
4244-
cls->getObjCRuntimeName(objcRuntimeNameBuffer),
4245-
/*willBeRelativelyAddressed=*/true);
4245+
cls->getObjCRuntimeName(objcRuntimeNameBuffer),
4246+
/*sectionName=*/"__TEXT,__objc_classname,cstring_literals",
4247+
/*willBeRelativelyAddressed=*/true);
42464248

42474249
return TypeEntityReference(kind, ref);
42484250
}
@@ -4800,7 +4802,7 @@ void IRGenModule::emitAccessibleFunction(StringRef sectionName,
48004802
// -- Field: Name (record name)
48014803
{
48024804
llvm::Constant *name =
4803-
getAddrOfGlobalString(func.getFunctionName(),
4805+
getAddrOfGlobalString(func.getFunctionName(), /*sectionName=*/"",
48044806
/*willBeRelativelyAddressed=*/true);
48054807
fields.addRelativeAddress(name);
48064808
}
@@ -6023,9 +6025,10 @@ Address IRGenFunction::createAlloca(llvm::Type *type,
60236025
/// FIXME: willBeRelativelyAddressed is only needed to work around an ld64 bug
60246026
/// resolving relative references to coalesceable symbols.
60256027
/// It should be removed when fixed. rdar://problem/22674524
6026-
llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
6027-
bool willBeRelativelyAddressed,
6028-
bool useOSLogSection) {
6028+
llvm::Constant *
6029+
IRGenModule::getAddrOfGlobalString(StringRef data, StringRef sectionName,
6030+
bool willBeRelativelyAddressed,
6031+
bool useOSLogSection) {
60296032
useOSLogSection = useOSLogSection &&
60306033
TargetInfo.OutputObjectFormat == llvm::Triple::MachO;
60316034

@@ -6053,8 +6056,8 @@ llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
60536056
(llvm::Twine(".nul") + llvm::Twine(i)).toVector(name);
60546057
}
60556058

6056-
auto sectionName =
6057-
useOSLogSection ? "__TEXT,__oslogstring,cstring_literals" : "";
6059+
sectionName =
6060+
useOSLogSection ? "__TEXT,__oslogstring,cstring_literals" : sectionName;
60586061

60596062
entry = createStringConstant(data, willBeRelativelyAddressed,
60606063
sectionName, name);
@@ -6067,9 +6070,11 @@ IRGenModule::getAddrOfGlobalIdentifierString(StringRef data,
60676070
if (Lexer::identifierMustAlwaysBeEscaped(data)) {
60686071
llvm::SmallString<256> name;
60696072
Mangle::Mangler::appendRawIdentifierForRuntime(data, name);
6070-
return getAddrOfGlobalString(name, willBeRelativelyAddressed);
6073+
return getAddrOfGlobalString(name, /*sectionName=*/"",
6074+
willBeRelativelyAddressed);
60716075
}
6072-
return getAddrOfGlobalString(data, willBeRelativelyAddressed);
6076+
return getAddrOfGlobalString(data, /*sectionName=*/"",
6077+
willBeRelativelyAddressed);
60736078
}
60746079

60756080
/// Get or create a global UTF-16 string constant.

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
11431143
// null otherwise.
11441144
if (!pattern->getObjCString().empty()) {
11451145
auto objcString = getAddrOfGlobalString(pattern->getObjCString(),
1146+
/*sectionName=*/"",
11461147
/*relatively addressed*/ true);
11471148
fields.addRelativeAddress(objcString);
11481149
} else {

lib/IRGen/GenMeta.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,9 @@ namespace {
846846
IRGenMangler mangler(IGM.Context);
847847
auto mangledName = mangler.mangleAnonymousDescriptorName(Name);
848848
auto mangledNameConstant =
849-
IGM.getAddrOfGlobalString(mangledName,
850-
/*willBeRelativelyAddressed*/ true);
849+
IGM.getAddrOfGlobalString(mangledName,
850+
/*sectionName=*/"",
851+
/*willBeRelativelyAddressed*/ true);
851852
B.addRelativeAddress(mangledNameConstant);
852853
}
853854

@@ -1278,6 +1279,7 @@ namespace {
12781279
llvm::Constant *global = nullptr;
12791280
if (!AssociatedTypeNames.empty()) {
12801281
global = IGM.getAddrOfGlobalString(AssociatedTypeNames,
1282+
/*sectionName=*/"",
12811283
/*willBeRelativelyAddressed=*/true);
12821284
}
12831285
B.addRelativeAddressOrNull(global);
@@ -1516,9 +1518,11 @@ namespace {
15161518
name.pop_back();
15171519
assert(name.back() == '\0');
15181520
}
1519-
1520-
auto nameStr = IGM.getAddrOfGlobalString(name,
1521-
/*willBeRelativelyAddressed*/ true);
1521+
1522+
auto nameStr =
1523+
IGM.getAddrOfGlobalString(name,
1524+
/*sectionName=*/"",
1525+
/*willBeRelativelyAddressed*/ true);
15221526
B.addRelativeAddress(nameStr);
15231527
}
15241528

lib/IRGen/GenObjC.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,9 @@ static llvm::Constant *getObjCEncodingForTypes(IRGenModule &IGM,
13161316
encodingString += llvm::itostr(parmOffset);
13171317
encodingString += fixedParamsString;
13181318
encodingString += paramsString;
1319-
return IGM.getAddrOfGlobalString(encodingString);
1319+
return IGM.getAddrOfGlobalString(
1320+
encodingString,
1321+
/*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
13201322
}
13211323

13221324
static llvm::Constant *
@@ -1327,16 +1329,19 @@ getObjectEncodingFromClangNode(IRGenModule &IGM, Decl *d,
13271329
auto clangDecl = d->getClangNode().castAsDecl();
13281330
auto &clangASTContext = IGM.getClangASTContext();
13291331
std::string typeStr;
1332+
std::string sectionName;
13301333
if (auto objcMethodDecl = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) {
13311334
typeStr = clangASTContext.getObjCEncodingForMethodDecl(
13321335
objcMethodDecl, useExtendedEncoding /*extended*/);
1336+
sectionName = "__TEXT,__objc_methtype,cstring_literals";
13331337
}
13341338
if (auto objcPropertyDecl = dyn_cast<clang::ObjCPropertyDecl>(clangDecl)) {
13351339
typeStr = clangASTContext.getObjCEncodingForPropertyDecl(objcPropertyDecl,
13361340
nullptr);
1341+
sectionName = "__TEXT,__objc_methname,cstring_literals";
13371342
}
13381343
if (!typeStr.empty()) {
1339-
return IGM.getAddrOfGlobalString(typeStr.c_str());
1344+
return IGM.getAddrOfGlobalString(typeStr.c_str(), sectionName);
13401345
}
13411346
}
13421347
return nullptr;
@@ -1432,7 +1437,9 @@ irgen::emitObjCGetterDescriptorParts(IRGenModule &IGM, VarDecl *property) {
14321437
TypeStr += llvm::itostr(ParmOffset);
14331438
TypeStr += "@0:";
14341439
TypeStr += llvm::itostr(PtrSize.getValue());
1435-
descriptor.typeEncoding = IGM.getAddrOfGlobalString(TypeStr.c_str());
1440+
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1441+
TypeStr.c_str(),
1442+
/*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
14361443
descriptor.silFunction = nullptr;
14371444
descriptor.impl = getObjCGetterPointer(IGM, property, descriptor.silFunction);
14381445
return descriptor;
@@ -1509,7 +1516,9 @@ irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
15091516
ParmOffset = 2 * PtrSize.getValue();
15101517
clangASTContext.getObjCEncodingForType(clangType, TypeStr);
15111518
TypeStr += llvm::itostr(ParmOffset);
1512-
descriptor.typeEncoding = IGM.getAddrOfGlobalString(TypeStr.c_str());
1519+
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1520+
TypeStr.c_str(),
1521+
/*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
15131522
descriptor.silFunction = nullptr;
15141523
descriptor.impl = getObjCSetterPointer(IGM, property, descriptor.silFunction);
15151524
return descriptor;
@@ -1615,7 +1624,8 @@ void irgen::emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
16151624
auto ptrSize = IGM.getPointerSize().getValue();
16161625
llvm::SmallString<8> signature;
16171626
signature = "v" + llvm::itostr(ptrSize * 2) + "@0:" + llvm::itostr(ptrSize);
1618-
descriptor.typeEncoding = IGM.getAddrOfGlobalString(signature);
1627+
descriptor.typeEncoding = IGM.getAddrOfGlobalString(
1628+
signature, /*sectionName=*/"__TEXT,__objc_methtype,cstring_literals");
16191629

16201630
/// The third element is the method implementation pointer.
16211631
descriptor.impl = llvm::ConstantExpr::getBitCast(objcImpl, IGM.Int8PtrTy);

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ class IRGenModule {
12041204
StringRef Str, bool willBeRelativelyAddressed = false,
12051205
StringRef sectionName = "", StringRef name = "");
12061206
llvm::Constant *getAddrOfGlobalString(StringRef utf8,
1207+
StringRef sectionName = "",
12071208
bool willBeRelativelyAddressed = false,
12081209
bool useOSLogSection = false);
12091210
llvm::Constant *getAddrOfGlobalUTF16String(StringRef utf8);

test/IRGen/objc_runtime_visible_conformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ extension A : YourProtocol {}
1515
// CHECK-SAME: @"$sSo1AC32objc_runtime_visible_conformance10MyProtocolACWP"
1616
// DirectObjCClassName
1717
// CHECK-SAME: i32 16
18-
// CHECK: @.str.21.MyRuntimeVisibleClass = private constant [22 x i8] c"MyRuntimeVisibleClass\00"
18+
// CHECK: @.str.21.MyRuntimeVisibleClass = {{.*}} [22 x i8] c"MyRuntimeVisibleClass\00"

0 commit comments

Comments
 (0)