From 878c8c712fdf2758fcfa1c30cbebdf006fda5568 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Fri, 12 Nov 2021 22:54:12 +0100 Subject: [PATCH] [LDC] PGO: Avoid COMDAT members with private linkage for Windows To prevent according IR verifier errors with IR-based PGO ('comdat global value has private linkage'). --- llvm/lib/ProfileData/InstrProf.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index aee104310a1dd7..5ea6a54d7c7d25 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -360,8 +360,13 @@ GlobalVariable *createPGOFuncNameVar(Module &M, else if (Linkage == GlobalValue::AvailableExternallyLinkage) Linkage = GlobalValue::LinkOnceODRLinkage; else if (Linkage == GlobalValue::InternalLinkage || - Linkage == GlobalValue::ExternalLinkage) - Linkage = GlobalValue::PrivateLinkage; + Linkage == GlobalValue::ExternalLinkage) { + // LDC: use internal instead of private linkage for COFF (still local, but + // allows for COMDATs on Windows) + Linkage = Triple(M.getTargetTriple()).isOSBinFormatCOFF() + ? GlobalValue::InternalLinkage + : GlobalValue::PrivateLinkage; + } auto *Value = ConstantDataArray::getString(M.getContext(), PGOFuncName, false);