[PATCH] D23398: [XRay] Synthesize a reference to the xray_instr_map

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 11 03:16:34 PDT 2016


dberris created this revision.
dberris added reviewers: chandlerc, echristo, majnemer, mehdi_amini.
dberris added a subscriber: llvm-commits.
Herald added subscribers: dberris, mehdi_amini.

Without the synthesized reference to a symbol in the xray_instr_map,
linker section garbage collection will helpfully remove the whole
xray_instr_map section from the final executable (or archive). This will
cause the runtime to not be able to identify the sleds and hot-patch the
calls/jumps into the runtime trampolines.

This change adds a reference from the text section at the end of the
function to keep around the associated xray_instr_map section as well.

We also make sure that we catch this reference in the test.

https://reviews.llvm.org/D23398

Files:
  lib/Target/X86/X86MCInstLower.cpp
  test/CodeGen/X86/xray-attribute-instrumentation.ll

Index: test/CodeGen/X86/xray-attribute-instrumentation.ll
===================================================================
--- test/CodeGen/X86/xray-attribute-instrumentation.ll
+++ test/CodeGen/X86/xray-attribute-instrumentation.ll
@@ -1,14 +1,21 @@
 ; RUN: llc -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+; RUN: llc -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck --check-prefix=CHECK-LABEL %s
 
 define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
 ; CHECK:       .p2align 1, 0x90
-; CHECK-LABEL: Lxray_sled_0:
+; CHECK-LABEL: .Lxray_sled_0:
 ; CHECK-NEXT:  .ascii "\353\t"
 ; CHECK-NEXT:  nopw 512(%rax,%rax)
 ; CHECK-LABEL: Ltmp0:
   ret i32 0
 ; CHECK:       .p2align 1, 0x90
-; CHECK-LABEL: Lxray_sled_1:
+; CHECK-LABEL: .Lxray_sled_1:
 ; CHECK-NEXT:  retq
 ; CHECK-NEXT:  nopw %cs:512(%rax,%rax)
 }
+; CHECK:       .p2align 4, 0x90
+; CHECK-NEXT:  .quad .Lxray_synthetic_0
+; CHECK-NEXT:  .section xray_instr_map,{{.*}}
+; CHECK-LABEL: .Lxray_synthetic_0:
+; CHECK:       .quad .Lxray_sled_0
+; CHECK:       .quad .Lxray_sled_1
Index: lib/Target/X86/X86MCInstLower.cpp
===================================================================
--- lib/Target/X86/X86MCInstLower.cpp
+++ lib/Target/X86/X86MCInstLower.cpp
@@ -1109,7 +1109,19 @@
       Section = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS,
                                          ELF::SHF_ALLOC);
     }
+
+    // Before we switch over, we force a reference to a label inside the
+    // xray_instr_map section. Since EmitXRayTable() is always called just
+    // before the function's end, we assume that this is happening after the
+    // last return instruction.
+    //
+    // We then align the reference to 16 byte boundaries, which we determined
+    // experimentally to be beneficial to avoid causing decoder stalls.
+    MCSymbol *Tmp = OutContext.createTempSymbol("xray_synthetic_", true);
+    OutStreamer->EmitCodeAlignment(16);
+    OutStreamer->EmitSymbolValue(Tmp, 8, false);
     OutStreamer->SwitchSection(Section);
+    OutStreamer->EmitLabel(Tmp);
     for (const auto &Sled : Sleds) {
       OutStreamer->EmitSymbolValue(Sled.Sled, 8);
       OutStreamer->EmitSymbolValue(CurrentFnSym, 8);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23398.67667.patch
Type: text/x-patch
Size: 2282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160811/ae6844b1/attachment.bin>


More information about the llvm-commits mailing list