@@ -2482,7 +2482,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
24822482 return Address (addr, alignment);
24832483 }
24842484
2485- LinkEntity entity = LinkEntity::forSILGlobalVariable (var, * this );
2485+ LinkEntity entity = LinkEntity::forSILGlobalVariable (var);
24862486 ResilienceExpansion expansion = getResilienceExpansionForLayout (var);
24872487
24882488 llvm::Type *storageType;
@@ -2528,33 +2528,28 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
25282528
25292529 // Check whether we've created the global variable already.
25302530 // FIXME: We should integrate this into the LinkEntity cache more cleanly.
2531- LinkInfo link = LinkInfo::get (*this , entity, forDefinition);
2532- auto gvar = Module.getGlobalVariable (link.getName (), /* allowInternal*/ true );
2531+ auto gvar = Module.getGlobalVariable (var->getName (), /* allowInternal*/ true );
25332532 if (gvar) {
25342533 if (forDefinition)
25352534 updateLinkageForDefinition (*this , gvar, entity);
25362535 } else {
2536+ LinkInfo link = LinkInfo::get (*this , entity, forDefinition);
25372537 llvm::Type *storageTypeWithContainer = storageType;
25382538 if (var->isInitializedObject ()) {
2539- if (canMakeStaticObjectsReadOnly ()) {
2540- gvar = createVariable (*this , link, storageType, fixedAlignment);
2541- gvar->setConstant (true );
2542- } else {
2543- // A statically initialized object must be placed into a container struct
2544- // because the swift_initStaticObject needs a swift_once_t at offset -1:
2545- // struct Container {
2546- // swift_once_t token[fixedAlignment / sizeof(swift_once_t)];
2547- // HeapObject object;
2548- // };
2549- std::string typeName = storageType->getStructName ().str () + ' c' ;
2550- assert (fixedAlignment >= getPointerAlignment ());
2551- unsigned numTokens = fixedAlignment.getValue () /
2552- getPointerAlignment ().getValue ();
2553- storageTypeWithContainer = llvm::StructType::create (getLLVMContext (),
2554- {llvm::ArrayType::get (OnceTy, numTokens), storageType}, typeName);
2555- gvar = createVariable (*this , link, storageTypeWithContainer,
2556- fixedAlignment);
2557- }
2539+ // A statically initialized object must be placed into a container struct
2540+ // because the swift_initStaticObject needs a swift_once_t at offset -1:
2541+ // struct Container {
2542+ // swift_once_t token[fixedAlignment / sizeof(swift_once_t)];
2543+ // HeapObject object;
2544+ // };
2545+ std::string typeName = storageType->getStructName ().str () + ' c' ;
2546+ assert (fixedAlignment >= getPointerAlignment ());
2547+ unsigned numTokens = fixedAlignment.getValue () /
2548+ getPointerAlignment ().getValue ();
2549+ storageTypeWithContainer = llvm::StructType::create (getLLVMContext (),
2550+ {llvm::ArrayType::get (OnceTy, numTokens), storageType}, typeName);
2551+ gvar = createVariable (*this , link, storageTypeWithContainer,
2552+ fixedAlignment);
25582553 } else {
25592554 StringRef name;
25602555 Optional<SILLocation> loc;
@@ -2579,7 +2574,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
25792574 gvar->setComdat (nullptr );
25802575 }
25812576 llvm::Constant *addr = gvar;
2582- if (var->isInitializedObject () && ! canMakeStaticObjectsReadOnly () ) {
2577+ if (var->isInitializedObject ()) {
25832578 // Project out the object from the container.
25842579 llvm::Constant *Indices[2 ] = {
25852580 llvm::ConstantExpr::getIntegerValue (Int32Ty, APInt (32 , 0 )),
0 commit comments