[clang] [llvm] [HIP][MacOS] Mach-O support and Darwin toolchain fixes (PR #183991)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 08:38:28 PDT 2026


================
@@ -114,20 +122,40 @@ std::pair<GlobalVariable *, GlobalVariable *>
 offloading::getOffloadEntryArray(Module &M, StringRef SectionName) {
   const llvm::Triple &Triple = M.getTargetTriple();
 
+  if (SectionName.empty())
+    SectionName = getOffloadEntrySection(M);
+
   auto *ZeroInitilaizer =
       ConstantAggregateZero::get(ArrayType::get(getEntryTy(M), 0u));
   auto *EntryInit = Triple.isOSBinFormatCOFF() ? ZeroInitilaizer : nullptr;
   auto *EntryType = ArrayType::get(getEntryTy(M), 0);
   auto Linkage = Triple.isOSBinFormatCOFF() ? GlobalValue::WeakODRLinkage
                                             : GlobalValue::ExternalLinkage;
 
-  auto *EntriesB =
-      new GlobalVariable(M, EntryType, /*isConstant=*/true, Linkage, EntryInit,
-                         "__start_" + SectionName);
+  // Mach-O uses linker-defined section boundary symbols with a special naming
+  // convention: \1section$start$<segment>$<section> (the \1 prefix suppresses
+  // the leading underscore that Mach-O normally adds to C symbols).
+  // See SanitizerCoverage for the existing precedent:
+  //   llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+  //   compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c
+  std::string StartName, StopName;
----------------
jhuber6 wrote:

Can we make this a helper? Also

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


More information about the llvm-commits mailing list