================ @@ -1221,44 +1231,68 @@ MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const { MCSection * MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const { - if (Ctx->getObjectFileType() != MCContext::IsELF) - return PseudoProbeSection; - - const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec); - unsigned Flags = ELF::SHF_LINK_ORDER; - StringRef GroupName; - if (const MCSymbol *Group = ElfSec.getGroup()) { - GroupName = Group->getName(); - Flags |= ELF::SHF_GROUP; + auto ObjFileType = Ctx->getObjectFileType(); + if (ObjFileType == MCContext::IsELF) { + const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec); + unsigned Flags = ELF::SHF_LINK_ORDER; + StringRef GroupName; + if (const MCSymbol *Group = ElfSec.getGroup()) { + GroupName = Group->getName(); + Flags |= ELF::SHF_GROUP; + } + return Ctx->getELFSection( + PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName, + true, ElfSec.getUniqueID(), + static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); + } else if (ObjFileType == MCContext::IsCOFF) { + StringRef COMDATSymName = ""; + int Selection = 0; + unsigned Characteristics = + static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics(); + const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec); + if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) { + // Associate .pseudo_probe to its function section. + COMDATSymName = COMDATSym->getName(); + Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; + Selection = COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE; + } + return Ctx->getCOFFSection(PseudoProbeSection->getName(), Characteristics, + COMDATSymName, Selection, COFFSec.getUniqueID()); } - return Ctx->getELFSection( - PseudoProbeSection->getName(), ELF::SHT_PROGBITS, Flags, 0, GroupName, - true, ElfSec.getUniqueID(), - static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); + return PseudoProbeSection; } MCSection * MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { - if (Ctx->getObjectFileType() == MCContext::IsELF) { - // Create a separate comdat group for each function's descriptor in order - // for the linker to deduplicate. The duplication, must be from different - // tranlation unit, can come from: - // 1. Inline functions defined in header files; - // 2. ThinLTO imported funcions; - // 3. Weak-linkage definitions. - // Use a concatenation of the section name and the function name as the - // group name so that descriptor-only groups won't be folded with groups of - // code. - if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) { - auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); - auto Flags = S->getFlags() | ELF::SHF_GROUP; - return Ctx->getELFSection(S->getName(), S->getType(), Flags, - S->getEntrySize(), - S->getName() + "_" + FuncName, - /*IsComdat=*/true); - } + if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty()) + return PseudoProbeDescSection; + + // Create a separate comdat group for each function's descriptor in order + // for the linker to deduplicate. The duplication, must be from different + // tranlation unit, can come from: + // 1. Inline functions defined in header files; + // 2. ThinLTO imported funcions; + // 3. Weak-linkage definitions. + // Use a concatenation of the section name and the function name as the + // group name so that descriptor-only groups won't be folded with groups of + // code. + auto ObjFileType = Ctx->getObjectFileType(); + if (ObjFileType == MCContext::IsELF) { + auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); + auto Flags = S->getFlags() | ELF::SHF_GROUP; + return Ctx->getELFSection(S->getName(), S->getType(), Flags, + S->getEntrySize(), S->getName() + "_" + FuncName, + /*IsComdat=*/true); + } else if (ObjFileType == MCContext::IsCOFF) { + auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection); + unsigned Characteristics = + S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT; + std::string COMDATSymName = (S->getName() + "_" + FuncName).str(); + return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName, + COFF::IMAGE_COMDAT_SELECT_ANY); ---------------- williamweixiao wrote:
IMAGE_COMDAT_SELECT_EXACT_MATCH? https://github.com/llvm/llvm-project/pull/123870 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits