mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user