OSDN Git Service

[XRay] Make the xray_instr_map section specification more correct
authorDean Michael Berris <dberris@google.com>
Wed, 3 Aug 2016 07:21:55 +0000 (07:21 +0000)
committerDean Michael Berris <dberris@google.com>
Wed, 3 Aug 2016 07:21:55 +0000 (07:21 +0000)
Summary:
We also add a test to show what currently happens when we create a
section per function and emit an xray_instr_map. This illustrates the
relationship (or lack thereof) between the per-function section and the
xray_instr_map section.

We also change the code generation slightly so that we don't always
create group sections, but rather only do so if a function where the
table is associated with is in a group.

Also in this change:

  - Remove the "merge" flag on the xray_instr_map section.
  - Test that we're generating the right table for comdat and non-comdat functions.

Reviewers: echristo, majnemer

Subscribers: llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D23104

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277580 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86MCInstLower.cpp
test/CodeGen/X86/xray-section-group.ll [new file with mode: 0644]

index 906e342..18f9b3e 100644 (file)
@@ -1096,11 +1096,18 @@ void X86AsmPrinter::EmitXRayTable() {
   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);
diff --git a/test/CodeGen/X86/xray-section-group.ll b/test/CodeGen/X86/xray-section-group.ll
new file mode 100644 (file)
index 0000000..9f7558f
--- /dev/null
@@ -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
+}