[llvm] [clang] [Offload] Initial support for registering offloading entries on COFF targets (PR #72697)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 20 12:49:15 PST 2023


================
@@ -62,35 +63,51 @@ void offloading::emitOffloadingEntry(Module &M, Constant *Addr, StringRef Name,
       M.getDataLayout().getDefaultGlobalsAddressSpace());
 
   // The entry has to be created in the section the linker expects it to be.
-  Entry->setSection(SectionName);
+  if (Triple.isOSBinFormatCOFF())
+    Entry->setSection((SectionName + "$OE").str());
+  else
+    Entry->setSection(SectionName);
   Entry->setAlignment(Align(1));
 }
 
 std::pair<GlobalVariable *, GlobalVariable *>
 offloading::getOffloadEntryArray(Module &M, StringRef SectionName) {
-  auto *EntriesB =
-      new GlobalVariable(M, ArrayType::get(getEntryTy(M), 0),
-                         /*isConstant=*/true, GlobalValue::ExternalLinkage,
-                         /*Initializer=*/nullptr, "__start_" + SectionName);
+  llvm::Triple Triple(M.getTargetTriple());
+
+  auto *ZeroInitilaizer =
+      ConstantAggregateZero::get(ArrayType::get(getEntryTy(M), 0u));
+  auto *EntryInit = Triple.isOSBinFormatCOFF() ? ZeroInitilaizer : nullptr;
+  auto *EntryType = Triple.isOSBinFormatCOFF()
+                        ? ZeroInitilaizer->getType()
+                        : ArrayType::get(getEntryTy(M), 0);
----------------
jhuber6 wrote:

Actually you're right, forgot the initializer used the array type as well.

https://github.com/llvm/llvm-project/pull/72697


More information about the cfe-commits mailing list