Index: lib/Target/X86/X86MCInstLower.cpp =================================================================== --- lib/Target/X86/X86MCInstLower.cpp +++ lib/Target/X86/X86MCInstLower.cpp @@ -1096,11 +1096,18 @@ if (Sleds.empty()) return; if (Subtarget->isTargetELF()) { - auto *Section = OutContext.getELFSection( - "xray_instr_map", ELF::SHT_PROGBITS, - ELF::SHF_ALLOC | ELF::SHF_GROUP | ELF::SHF_MERGE, 0, - CurrentFnSym->getName()); auto PrevSection = OutStreamer->getCurrentSectionOnly(); + auto Fn = MF->getFunction(); + MCSection *Section = nullptr; + if (Fn->hasComdat()) { + Section = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS, + ELF::SHF_ALLOC | ELF::SHF_GROUP, 0, + Fn->getComdat()->getName()); + OutStreamer->SwitchSection(Section); + } else { + Section = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS, + ELF::SHF_ALLOC); + } OutStreamer->SwitchSection(Section); for (const auto &Sled : Sleds) { OutStreamer->EmitSymbolValue(Sled.Sled, 8); Index: test/CodeGen/X86/xray-section-group.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/xray-section-group.ll @@ -0,0 +1,14 @@ +; RUN: llc -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu -function-sections < %s | FileCheck %s + +define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" { +; CHECK: .section .text.foo,"ax",@progbits + ret i32 0 +; CHECK: .section xray_instr_map,"a",@progbits +} + +$bar = comdat any +define i32 @comdat() nounwind noinline uwtable "function-instrument"="xray-always" comdat($bar) { +; CHECK: .section .text.comdat,"axG",@progbits,bar,comdat + ret i32 1 +; CHECK: .section xray_instr_map,"aG",@progbits,bar,comdat +}