[llvm] r279204 - [XRay] Synthesize a reference to the xray_instr_map
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 21:44:31 PDT 2016
Author: dberris
Date: Thu Aug 18 23:44:30 2016
New Revision: 279204
URL: http://llvm.org/viewvc/llvm-project?rev=279204&view=rev
Log:
[XRay] Synthesize a reference to the xray_instr_map
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.
Reviewers: chandlerc, echristo, majnemer, mehdi_amini
Subscribers: mehdi_amini, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D23398
Modified:
llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll
Modified: llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCInstLower.cpp?rev=279204&r1=279203&r2=279204&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCInstLower.cpp Thu Aug 18 23:44:30 2016
@@ -1109,7 +1109,19 @@ void X86AsmPrinter::EmitXRayTable() {
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);
Modified: llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll?rev=279204&r1=279203&r2=279204&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xray-attribute-instrumentation.ll Thu Aug 18 23:44:30 2016
@@ -12,3 +12,9 @@ define i32 @foo() nounwind noinline uwta
; 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
More information about the llvm-commits
mailing list