diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index bb887df3e4e046..8c4141db4341ad 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -748,8 +748,12 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() { llvm::Constant *FatBinStr; unsigned FatMagic; if (IsHIP) { - FatbinConstantName = ".hip_fatbin"; - FatbinSectionName = ".hipFatBinSegment"; + FatbinConstantName = CGM.getTriple().isMacOSX() + ? "__HIP,__hip_fatbin" + : ".hip_fatbin"; + FatbinSectionName = CGM.getTriple().isMacOSX() + ? "__HIP,__fatbin" + : ".hipFatBinSegment"; ModuleIDSectionName = "__hip_module_id"; ModuleIDPrefix = "__hip_"; @@ -835,7 +839,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() { Linkage, /*Initializer=*/llvm::ConstantPointerNull::get(VoidPtrPtrTy), "__hip_gpubin_handle"); - if (Linkage == llvm::GlobalValue::LinkOnceAnyLinkage) + if (CGM.supportsCOMDAT() && (Linkage == llvm::GlobalValue::LinkOnceAnyLinkage)) GpuBinaryHandle->setComdat( CGM.getModule().getOrInsertComdat(GpuBinaryHandle->getName())); GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign()); diff --git a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp index dbfd896362c76d..d84d0cc4765e0d 100644 --- a/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/OffloadWrapper.cpp @@ -299,7 +299,7 @@ GlobalVariable *createFatbinDesc(Module &M, ArrayRef Image, bool IsHIP) { // Create the global string containing the fatbinary. StringRef FatbinConstantSection = - IsHIP ? ".hip_fatbin" + IsHIP ? (Triple.isMacOSX() ? "__HIP,__hip_fatbin" : ".hip_fatbin") : (Triple.isMacOSX() ? "__NV_CUDA,__nv_fatbin" : ".nv_fatbin"); auto *Data = ConstantDataArray::get(C, Image); auto *Fatbin = new GlobalVariable(M, Data->getType(), /*isConstant*/ true, @@ -308,7 +308,9 @@ GlobalVariable *createFatbinDesc(Module &M, ArrayRef Image, bool IsHIP) { Fatbin->setSection(FatbinConstantSection); // Create the fatbinary wrapper - StringRef FatbinWrapperSection = IsHIP ? ".hipFatBinSegment" + StringRef FatbinWrapperSection = IsHIP + ? Triple.isMacOSX() ? "__HIP,__fatbin" + : ".hipFatBinSegment" : Triple.isMacOSX() ? "__NV_CUDA,__fatbin" : ".nvFatBinSegment"; Constant *FatbinWrapper[] = {