@@ -169,18 +169,15 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
169169
170170  //  create the ModuleReference node for this module
171171  const  auto  thismrefIRMangle = getIRMangledModuleRefSymbolName (moduleMangle);
172-   Loc loc;
173-   LLGlobalVariable *thismref = getOrCreateGlobal (
174-       loc, gIR ->module , modulerefTy, false , LLGlobalValue::InternalLinkage,
175-       thismrefinit, thismrefIRMangle);
172+   LLGlobalVariable *thismref =
173+       defineGlobal (Loc (), gIR ->module , thismrefIRMangle, thismrefinit,
174+                    LLGlobalValue::InternalLinkage, false );
176175  //  make sure _Dmodule_ref is declared
177176  const  auto  mrefIRMangle = getIRMangledVarName (" _Dmodule_ref" 
178177  LLConstant *mref = gIR ->module .getNamedGlobal (mrefIRMangle);
179178  LLType *modulerefPtrTy = getPtrToType (modulerefTy);
180179  if  (!mref) {
181-     mref = new  LLGlobalVariable (gIR ->module , modulerefPtrTy, false ,
182-                                 LLGlobalValue::ExternalLinkage, nullptr ,
183-                                 mrefIRMangle);
180+     mref = declareGlobal (Loc (), gIR ->module , modulerefPtrTy, mrefIRMangle, false );
184181  }
185182  mref = DtoBitCast (mref, getPtrToType (modulerefPtrTy));
186183
@@ -218,9 +215,9 @@ llvm::Function *buildGetTLSAnchor() {
218215  //  Create a dummmy TLS global private to this module.
219216  const  auto  one =
220217      llvm::ConstantInt::get (llvm::Type::getInt8Ty (gIR ->context ()), 1 );
221-   const  auto  anchor = getOrCreateGlobal ( 
222-       Loc (),  gIR -> module , one-> getType () , false ,
223-       llvm::GlobalValue::LinkOnceODRLinkage, one,  " ldc.tls_anchor " ,  true );
218+   const  auto  anchor = defineGlobal ( Loc (),  gIR -> module ,  " ldc.tls_anchor " , one, 
219+                                    llvm::GlobalValue::LinkOnceODRLinkage , false ,
220+                                     /* isThreadLocal= */ true );
224221  anchor->setVisibility (llvm::GlobalValue::HiddenVisibility);
225222  anchor->setAlignment (16 );
226223
@@ -358,11 +355,11 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
358355
359356  const  auto  thismrefIRMangle =
360357      getIRMangledModuleRefSymbolName (moduleMangle.c_str ());
361-   auto  thismref = new   llvm::GlobalVariable ( 
362-       gIR -> module , moduleInfoPtrTy,
363-       false ,  //  FIXME: mRelocModel !=  llvm::Reloc::PIC_ 
364-       llvm::GlobalValue::LinkOnceODRLinkage, 
365-        DtoBitCast (thisModuleInfo, moduleInfoPtrTy), thismrefIRMangle );
358+   auto  thismref = defineGlobal ( Loc (),  gIR -> module , thismrefIRMangle, 
359+                                 DtoBitCast (thisModuleInfo , moduleInfoPtrTy) ,
360+                                 llvm::GlobalValue::LinkOnceODRLinkage, 
361+                                 false   //  FIXME: mRelocModel !=  llvm::Reloc::PIC_ 
362+   );
366363  thismref->setSection (sectionName);
367364  gIR ->usedArray .push_back (thismref);
368365
@@ -382,22 +379,19 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
382379  const  auto  magicEndSymbolName = (style == RegistryStyle::sectionDarwin)
383380                                      ? " \1 section$end$__DATA$.minfo" 
384381                                      : " __stop___minfo" 
385-   auto  minfoBeg = new  llvm::GlobalVariable (gIR ->module , moduleInfoPtrTy, false ,
386-                                            llvm::GlobalValue::ExternalLinkage,
387-                                            nullptr , magicBeginSymbolName);
388-   auto  minfoEnd = new  llvm::GlobalVariable (gIR ->module , moduleInfoPtrTy, false ,
389-                                            llvm::GlobalValue::ExternalLinkage,
390-                                            nullptr , magicEndSymbolName);
382+   auto  minfoBeg = declareGlobal (Loc (), gIR ->module , moduleInfoPtrTy,
383+                                 magicBeginSymbolName, false );
384+   auto  minfoEnd = declareGlobal (Loc (), gIR ->module , moduleInfoPtrTy,
385+                                 magicEndSymbolName, false );
391386  minfoBeg->setVisibility (llvm::GlobalValue::HiddenVisibility);
392387  minfoEnd->setVisibility (llvm::GlobalValue::HiddenVisibility);
393388
394389  //  Build the ctor to invoke _d_dso_registry.
395390
396391  //  This is the DSO slot for use by the druntime implementation.
397-   auto  dsoSlot =
398-       new  llvm::GlobalVariable (gIR ->module , getVoidPtrType (), false ,
399-                                llvm::GlobalValue::LinkOnceODRLinkage,
400-                                getNullPtr (getVoidPtrType ()), " ldc.dso_slot" 
392+   auto  dsoSlot = defineGlobal (Loc (), gIR ->module , " ldc.dso_slot" 
393+                               getNullPtr (getVoidPtrType ()),
394+                               llvm::GlobalValue::LinkOnceODRLinkage, false );
401395  dsoSlot->setVisibility (llvm::GlobalValue::HiddenVisibility);
402396
403397  //  Okay, so the theory is easy: We want to have one global constructor and
@@ -429,11 +423,10 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
429423  //  problems. This would mean that it is no longer safe to link D objects
430424  //  directly using e.g. "g++ dcode.o cppcode.o", though.
431425
432-   auto  dsoInitialized = new  llvm::GlobalVariable (
433-       gIR ->module , llvm::Type::getInt8Ty (gIR ->context ()), false ,
434-       llvm::GlobalValue::LinkOnceODRLinkage,
426+   auto  dsoInitialized = defineGlobal (
427+       Loc (), gIR ->module , " ldc.dso_initialized" 
435428      llvm::ConstantInt::get (llvm::Type::getInt8Ty (gIR ->context ()), 0 ),
436-       " ldc.dso_initialized " 
429+       llvm::GlobalValue::LinkOnceODRLinkage,  false );
437430  dsoInitialized->setVisibility (llvm::GlobalValue::HiddenVisibility);
438431
439432  //  There is no reason for this cast to void*, other than that removing it
@@ -505,7 +498,7 @@ void addCoverageAnalysis(Module *m) {
505498    llvm::ConstantAggregateZero *zeroinitializer =
506499        llvm::ConstantAggregateZero::get (type);
507500    m->d_cover_valid  = new  llvm::GlobalVariable (
508-         gIR ->module , type, true , LLGlobalValue::InternalLinkage,
501+         gIR ->module , type, /* isConstant= */ true , LLGlobalValue::InternalLinkage,
509502        zeroinitializer, " _d_cover_valid" 
510503    LLConstant *idxs[] = {DtoConstUint (0 ), DtoConstUint (0 )};
511504    d_cover_valid_slice =
0 commit comments