Index: lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenMPRuntime.cpp +++ lib/CodeGen/CGOpenMPRuntime.cpp @@ -3818,7 +3818,17 @@ CGF.disableDebugInfo(); const auto &FI = CGM.getTypes().arrangeNullaryFunction(); llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI); - std::string Descriptor = getName({"omp_offloading", "descriptor_reg"}); + + // Encode offload target triples into the registration function name. It + // will serve as a comdat key for the registration/unregistration code for + // this particular combination of offloading targets. + SmallVector RegFnNameParts; + RegFnNameParts.push_back("omp_offloading"); + RegFnNameParts.push_back("descriptor_reg"); + for (const auto &Device : Devices) + RegFnNameParts.push_back(Device.getTriple()); + std::sort(RegFnNameParts.begin() + 2, RegFnNameParts.end()); + std::string Descriptor = getName(RegFnNameParts); RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI); CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList()); CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc);