<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 3, 2016 at 12:21 AM, Dean Michael Berris via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dberris<br>
Date: Wed Aug  3 02:21:55 2016<br>
New Revision: 277580<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277580&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=277580&view=rev</a><br>
Log:<br>
[XRay] Make the xray_instr_map section specification more correct<br>
<br>
Summary:<br>
We also add a test to show what currently happens when we create a<br>
section per function and emit an xray_instr_map. This illustrates the<br>
relationship (or lack thereof) between the per-function section and the<br>
xray_instr_map section.<br>
<br>
We also change the code generation slightly so that we don't always<br>
create group sections, but rather only do so if a function where the<br>
table is associated with is in a group.<br>
<br>
Also in this change:<br>
<br>
  - Remove the "merge" flag on the xray_instr_map section.<br>
  - Test that we're generating the right table for comdat and non-comdat functions.<br>
<br>
Reviewers: echristo, majnemer<br>
<br>
Subscribers: llvm-commits, mehdi_amini<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D23104" rel="noreferrer" target="_blank">https://reviews.llvm.org/D23104</a><br>
<br>
Added:<br>
    llvm/trunk/test/CodeGen/X86/xray-section-group.ll<br>
Modified:<br>
    llvm/trunk/lib/Target/X86/X86MCInstLower.cpp<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86MCInstLower.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCInstLower.cpp?rev=277580&r1=277579&r2=277580&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCInstLower.cpp?rev=277580&r1=277579&r2=277580&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86MCInstLower.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86MCInstLower.cpp Wed Aug  3 02:21:55 2016<br>
@@ -1096,11 +1096,18 @@ void X86AsmPrinter::EmitXRayTable() {<br>
   if (Sleds.empty())<br>
     return;<br>
   if (Subtarget->isTargetELF()) {<br>
-    auto *Section = OutContext.getELFSection(<br>
-        "xray_instr_map", ELF::SHT_PROGBITS,<br>
-        ELF::SHF_ALLOC | ELF::SHF_GROUP | ELF::SHF_MERGE, 0,<br>
-        CurrentFnSym->getName());<br>
     auto PrevSection = OutStreamer->getCurrentSectionOnly();<br>
+    auto Fn = MF->getFunction();<br>
+    MCSection *Section = nullptr;<br>
+    if (Fn->hasComdat()) {<br>
+      Section = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS,<br>
+                                         ELF::SHF_ALLOC | ELF::SHF_GROUP, 0,<br>
+                                         Fn->getComdat()->getName());<br>
+      OutStreamer->SwitchSection(Section);<br>
+    } else {<br></blockquote><div><br></div><div>This will not correctly handle the -ffunction-sections case.  In that case, we want to make it COMDAT associative with Fn.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      Section = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS,<br>
+                                         ELF::SHF_ALLOC);<br>
+    }<br>
     OutStreamer->SwitchSection(Section);<br>
     for (const auto &Sled : Sleds) {<br>
       OutStreamer->EmitSymbolValue(Sled.Sled, 8);<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/xray-section-group.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-section-group.ll?rev=277580&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-section-group.ll?rev=277580&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/xray-section-group.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/xray-section-group.ll Wed Aug  3 02:21:55 2016<br>
@@ -0,0 +1,14 @@<br>
+; RUN: llc -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu -function-sections < %s | FileCheck %s<br>
+<br>
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {<br>
+; CHECK: .section .text.foo,"ax",@progbits<br>
+  ret i32 0<br>
+; CHECK: .section xray_instr_map,"a",@progbits<br>
+}<br>
+<br>
+$bar = comdat any<br>
+define i32 @comdat() nounwind noinline uwtable "function-instrument"="xray-always" comdat($bar) {<br>
+; CHECK: .section .text.comdat,"axG",@progbits,bar,comdat<br>
+  ret i32 1<br>
+; CHECK: .section xray_instr_map,"aG",@progbits,bar,comdat<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>