IRGen: restrict generation of read-only static objects to Array buffers

Currently only arrays can be put into a read-only data section.
"Regular" classes have dynamically initialized metadata, which needs to be stored into the isa field at runtime.
This commit is contained in:
Erik Eckstein
2023-12-29 18:54:05 +01:00
parent 33c7326365
commit eaabcfd933
6 changed files with 18 additions and 8 deletions

View File

@@ -2023,7 +2023,7 @@ bool IRGenModule::canUseObjCSymbolicReferences() {
context.getObjCSymbolicReferencesAvailability());
}
bool IRGenModule::canMakeStaticObjectsReadOnly() {
bool IRGenModule::canMakeStaticObjectReadOnly(SILType objectType) {
if (getOptions().DisableReadonlyStaticObjects)
return false;
@@ -2032,6 +2032,16 @@ bool IRGenModule::canMakeStaticObjectsReadOnly() {
if (!Triple.isOSDarwin())
return false;
auto *clDecl = objectType.getClassOrBoundGenericClass();
if (!clDecl)
return false;
// Currently only arrays can be put into a read-only data section.
// "Regular" classes have dynamically initialized metadata, which needs to be
// stored into the isa field at runtime.
if (clDecl->getNameStr() != "_ContiguousArrayStorage")
return false;
if (!getAvailabilityContext().isContainedIn(Context.getStaticReadOnlyArraysAvailability()))
return false;