From e479ac85d5b2f79eb765701933b2de640aa94525 Mon Sep 17 00:00:00 2001 From: Dean Michael Berris Date: Wed, 21 Jun 2017 06:39:42 +0000 Subject: [PATCH] [XRay] Reduce synthetic references emitted by XRay Summary: When we're building with XRay instrumentation, we use a trick that preserves references from the function to a function sled index. This index table lives in a separate section, and without this trick the linker is free to garbage-collect this section and all the segments it refers to. Until we're able to tell the linkers to preserve these sections, we use this reference trick to keep around both the index and the entries in the instrumentation map. Before this change we emitted both a synthetic reference to the label in the instrumentation map, and to the entry in the function map index. This change removes the first synthetic reference and only emits one synthetic reference to the index -- the index entry has the references to the labels in the instrumentation map, so the linker will still preserve those if the function itself is preserved. This reduces the amount of synthetic references we emit from 16 bytes to just 8 bytes in x86_64, and similarly to other platforms. Reviewers: dblaikie Subscribers: javed.absar, kpw, pelikan, llvm-commits Differential Revision: https://reviews.llvm.org/D34340 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305880 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 +++++------- .../AArch64/xray-attribute-instrumentation.ll | 4 ++-- test/CodeGen/AArch64/xray-tail-call-sled.ll | 22 +++++++++---------- .../xray-armv6-attribute-instrumentation.ll | 9 ++++---- .../xray-armv7-attribute-instrumentation.ll | 9 ++++---- .../X86/xray-attribute-instrumentation.ll | 18 +++++++-------- test/CodeGen/X86/xray-custom-log.ll | 2 +- test/CodeGen/X86/xray-log-args.ll | 4 ++-- test/CodeGen/X86/xray-tail-call-sled.ll | 18 +++++++-------- 9 files changed, 45 insertions(+), 55 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index ad348d723ba..c48fcaa7b0d 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2801,26 +2801,24 @@ void AsmPrinter::emitXRayTable() { } // Before we switch over, we force a reference to a label inside the - // xray_instr_map and xray_fn_idx sections. Since this function is always - // called just before the function's end, we assume that this is happening - // after the last return instruction. We also use the synthetic label in the - // xray_inster_map as a delimeter for the range of sleds for this function in - // the index. + // xray_fn_idx sections. This makes sure that the xray_fn_idx section is kept + // live by the linker if the function is not garbage-collected. Since this + // function is always called just before the function's end, we assume that + // this is happening after the last return instruction. auto WordSizeBytes = MAI->getCodePointerSize(); - MCSymbol *SledsStart = OutContext.createTempSymbol("xray_synthetic_", true); MCSymbol *IdxRef = OutContext.createTempSymbol("xray_fn_idx_synth_", true); OutStreamer->EmitCodeAlignment(16); - OutStreamer->EmitSymbolValue(SledsStart, WordSizeBytes, false); OutStreamer->EmitSymbolValue(IdxRef, WordSizeBytes, false); // Now we switch to the instrumentation map section. Because this is done // per-function, we are able to create an index entry that will represent the // range of sleds associated with a function. + MCSymbol *SledsStart = OutContext.createTempSymbol("xray_sleds_start", true); OutStreamer->SwitchSection(InstMap); OutStreamer->EmitLabel(SledsStart); for (const auto &Sled : Sleds) Sled.emit(WordSizeBytes, OutStreamer.get(), CurrentFnSym); - MCSymbol *SledsEnd = OutContext.createTempSymbol("xray_synthetic_end", true); + MCSymbol *SledsEnd = OutContext.createTempSymbol("xray_sleds_end", true); OutStreamer->EmitLabel(SledsEnd); // We then emit a single entry in the index per function. We use the symbols diff --git a/test/CodeGen/AArch64/xray-attribute-instrumentation.ll b/test/CodeGen/AArch64/xray-attribute-instrumentation.ll index 38b62a72a20..5f01c7c8be8 100644 --- a/test/CodeGen/AArch64/xray-attribute-instrumentation.ll +++ b/test/CodeGen/AArch64/xray-attribute-instrumentation.ll @@ -25,9 +25,9 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" ; CHECK-NEXT: ret } ; CHECK: .p2align 4 -; CHECK-NEXT: .xword .Lxray_synthetic_0 ; CHECK-NEXT: .xword .Lxray_fn_idx_synth_0 ; CHECK-NEXT: .section xray_instr_map,{{.*}} -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0 ; CHECK: .xword .Lxray_sled_0 ; CHECK: .xword .Lxray_sled_1 +; CHECK-LABEL: Lxray_sleds_end0 diff --git a/test/CodeGen/AArch64/xray-tail-call-sled.ll b/test/CodeGen/AArch64/xray-tail-call-sled.ll index fb89950b99c..a7e993b3dba 100644 --- a/test/CodeGen/AArch64/xray-tail-call-sled.ll +++ b/test/CodeGen/AArch64/xray-tail-call-sled.ll @@ -28,21 +28,20 @@ define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-alway ; CHECK-NEXT: ret } ; CHECK: .p2align 4 -; CHECK-NEXT: .xword .Lxray_synthetic_0 ; CHECK-NEXT: .xword .Lxray_fn_idx_synth_0 ; CHECK-NEXT: .section xray_instr_map,{{.*}} -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .xword .Lxray_sled_0 ; CHECK: .xword .Lxray_sled_1 -; CHECK-LABEL: Lxray_synthetic_end0: +; CHECK-LABEL: Lxray_sleds_end0: ; CHECK: .section xray_fn_idx,{{.*}} ; CHECK-LABEL: Lxray_fn_idx_synth_0: -; CHECK: .xword .Lxray_synthetic_0 -; CHECK-NEXT: .xword .Lxray_synthetic_end0 +; CHECK: .xword .Lxray_sleds_start0 +; CHECK-NEXT: .xword .Lxray_sleds_end0 define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" { ; CHECK: .p2align 2 -; CHECK-LABEL: .Lxray_sled_2: +; CHECK-LABEL: Lxray_sled_2: ; CHECK-NEXT: b #32 ; CHECK-NEXT: nop ; CHECK-NEXT: nop @@ -53,7 +52,7 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway ; CHECK-NEXT: nop ; CHECK-LABEL: .Ltmp2: ; CHECK: .p2align 2 -; CHECK-LABEL: .Lxray_sled_3: +; CHECK-LABEL: Lxray_sled_3: ; CHECK-NEXT: b #32 ; CHECK-NEXT: nop ; CHECK-NEXT: nop @@ -68,14 +67,13 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway ret i32 %retval } ; CHECK: .p2align 4 -; CHECK-NEXT: .xword .Lxray_synthetic_1 ; CHECK-NEXT: .xword .Lxray_fn_idx_synth_1 ; CHECK-NEXT: .section xray_instr_map,{{.*}} -; CHECK-LABEL: Lxray_synthetic_1: +; CHECK-LABEL: Lxray_sleds_start1: ; CHECK: .xword .Lxray_sled_2 ; CHECK: .xword .Lxray_sled_3 -; CHECK-LABEL: Lxray_synthetic_end1: +; CHECK-LABEL: Lxray_sleds_end1: ; CHECK: .section xray_fn_idx,{{.*}} ; CHECK-LABEL: Lxray_fn_idx_synth_1: -; CHECK: .xword .Lxray_synthetic_1 -; CHECK-NEXT: .xword .Lxray_synthetic_end1 +; CHECK: .xword .Lxray_sleds_start1 +; CHECK-NEXT: .xword .Lxray_sleds_end1 diff --git a/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll b/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll index 5e3c45c3454..5017de835b5 100644 --- a/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll +++ b/test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll @@ -24,14 +24,13 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" ; CHECK-NEXT: bx lr } ; CHECK: .p2align 4 -; CHECK-NEXT: .long {{.*}}Lxray_synthetic_0 ; CHECK-NEXT: .long {{.*}}Lxray_fn_idx_synth_0 ; CHECK-NEXT: .section {{.*}}xray_instr_map{{.*}} -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .long {{.*}}Lxray_sled_0 ; CHECK: .long {{.*}}Lxray_sled_1 -; CHECK-LABEL: Lxray_synthetic_end0: +; CHECK-LABEL: Lxray_sleds_end0: ; CHECK: .section {{.*}}xray_fn_idx{{.*}} ; CHECK-LABEL: Lxray_fn_idx_synth_0: -; CHECK: .long {{.*}}Lxray_synthetic_0 -; CHECK-NEXT: .long {{.*}}Lxray_synthetic_end0 +; CHECK: .long {{.*}}Lxray_sleds_start0 +; CHECK-NEXT: .long {{.*}}Lxray_sleds_end0 diff --git a/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll b/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll index 739151fbdd5..118c02adeb8 100644 --- a/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll +++ b/test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll @@ -24,15 +24,14 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" ; CHECK-NEXT: bx lr } ; CHECK: .p2align 4 -; CHECK-NEXT: .long {{.*}}Lxray_synthetic_0 ; CHECK-NEXT: .long {{.*}}Lxray_fn_idx_synth_0 ; CHECK-NEXT: .section {{.*}}xray_instr_map{{.*}} -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .long {{.*}}Lxray_sled_0 ; CHECK: .long {{.*}}Lxray_sled_1 -; CHECK-LABEL: Lxray_synthetic_end0: +; CHECK-LABEL: Lxray_sleds_end0: ; CHECK: .section {{.*}}xray_fn_idx{{.*}} ; CHECK-LABEL: Lxray_fn_idx_synth_0: -; CHECK: .long {{.*}}xray_synthetic_0 -; CHECK-NEXT: .long {{.*}}xray_synthetic_end0 +; CHECK: .long {{.*}}xray_sleds_start0 +; CHECK-NEXT: .long {{.*}}xray_sleds_end0 diff --git a/test/CodeGen/X86/xray-attribute-instrumentation.ll b/test/CodeGen/X86/xray-attribute-instrumentation.ll index 7c60327d2c3..00b45f8d95b 100644 --- a/test/CodeGen/X86/xray-attribute-instrumentation.ll +++ b/test/CodeGen/X86/xray-attribute-instrumentation.ll @@ -14,17 +14,16 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" ; CHECK-NEXT: nopw %cs:512(%rax,%rax) } ; CHECK: .p2align 4, 0x90 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_0 ; CHECK-NEXT: .quad {{.*}}xray_fn_idx_synth_0 ; CHECK-NEXT: .section {{.*}}xray_instr_map -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .quad {{.*}}xray_sled_0 ; CHECK: .quad {{.*}}xray_sled_1 -; CHECK-LABEL: Lxray_synthetic_end0: +; CHECK-LABEL: Lxray_sleds_end0: ; CHECK: .section {{.*}}xray_fn_idx ; CHECK-LABEL: Lxray_fn_idx_synth_0: -; CHECK: .quad {{.*}}xray_synthetic_0 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_end0 +; CHECK: .quad {{.*}}xray_sleds_start0 +; CHECK-NEXT: .quad {{.*}}xray_sleds_end0 ; We test multiple returns in a single function to make sure we're getting all @@ -52,15 +51,14 @@ NotEqual: ; CHECK-NEXT: nopw %cs:512(%rax,%rax) } ; CHECK: .p2align 4, 0x90 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_1 ; CHECK-NEXT: .quad {{.*}}xray_fn_idx_synth_1 ; CHECK-NEXT: .section {{.*}}xray_instr_map -; CHECK-LABEL: Lxray_synthetic_1: +; CHECK-LABEL: Lxray_sleds_start1: ; CHECK: .quad {{.*}}xray_sled_2 ; CHECK: .quad {{.*}}xray_sled_3 ; CHECK: .quad {{.*}}xray_sled_4 -; CHECK-LABEL: Lxray_synthetic_end1: +; CHECK-LABEL: Lxray_sleds_end1: ; CHECK: .section {{.*}}xray_fn_idx ; CHECK-LABEL: Lxray_fn_idx_synth_1: -; CHECK: .quad {{.*}}xray_synthetic_1 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_end1 +; CHECK: .quad {{.*}}xray_sleds_start1 +; CHECK-NEXT: .quad {{.*}}xray_sleds_end1 diff --git a/test/CodeGen/X86/xray-custom-log.ll b/test/CodeGen/X86/xray-custom-log.ll index 63625d44b4c..69fd0f3e9f7 100644 --- a/test/CodeGen/X86/xray-custom-log.ll +++ b/test/CodeGen/X86/xray-custom-log.ll @@ -17,7 +17,7 @@ define i32 @fn() nounwind noinline uwtable "function-instrument"="xray-always" { ret i32 0 } ; CHECK: .section {{.*}}xray_instr_map -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .quad {{.*}}xray_event_sled_0 declare void @llvm.xray.customevent(i8*, i32) diff --git a/test/CodeGen/X86/xray-log-args.ll b/test/CodeGen/X86/xray-log-args.ll index a551868ffb4..6fe450ac8ad 100644 --- a/test/CodeGen/X86/xray-log-args.ll +++ b/test/CodeGen/X86/xray-log-args.ll @@ -6,7 +6,7 @@ define i32 @callee(i32 %arg) nounwind noinline uwtable "function-instrument"="xray-always" "xray-log-args"="1" { ret i32 %arg } -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .quad {{\.?}}Lxray_sled_0 ; CHECK: .quad {{_?}}callee ; CHECK: .byte 3 @@ -22,7 +22,7 @@ define i32 @caller(i32 %arg) nounwind noinline uwtable "function-instrument"="xr %retval = tail call i32 @callee(i32 %arg) ret i32 %retval } -; CHECK-LABEL: Lxray_synthetic_1: +; CHECK-LABEL: Lxray_sleds_start1: ; CHECK: .quad {{\.?}}Lxray_sled_2 ; CHECK: .quad {{_?}}caller ; CHECK: .byte 3 diff --git a/test/CodeGen/X86/xray-tail-call-sled.ll b/test/CodeGen/X86/xray-tail-call-sled.ll index b12c78a77b2..c4a973e529f 100644 --- a/test/CodeGen/X86/xray-tail-call-sled.ll +++ b/test/CodeGen/X86/xray-tail-call-sled.ll @@ -14,17 +14,16 @@ define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-alway ; CHECK-NEXT: nopw %cs:512(%rax,%rax) } ; CHECK: .p2align 4, 0x90 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_0{{.*}} ; CHECK-NEXT: .quad {{.*}}xray_fn_idx_synth_0{{.*}} ; CHECK-NEXT: .section {{.*}}xray_instr_map -; CHECK-LABEL: Lxray_synthetic_0: +; CHECK-LABEL: Lxray_sleds_start0: ; CHECK: .quad {{.*}}xray_sled_0 ; CHECK: .quad {{.*}}xray_sled_1 -; CHECK-LABEL: Lxray_synthetic_end0: +; CHECK-LABEL: Lxray_sleds_end0: ; CHECK-NEXT: .section {{.*}}xray_fn_idx ; CHECK-LABEL: Lxray_fn_idx_synth_0: -; CHECK: .quad {{.*}}xray_synthetic_0 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_end0 +; CHECK: .quad {{.*}}xray_sleds_start0 +; CHECK-NEXT: .quad {{.*}}xray_sleds_end0 define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" { ; CHECK: .p2align 1, 0x90 @@ -42,13 +41,12 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway ret i32 %retval } ; CHECK: .p2align 4, 0x90 -; CHECK-NEXT: .quad {{.*}}xray_synthetic_1{{.*}} ; CHECK-NEXT: .quad {{.*}}xray_fn_idx_synth_1{{.*}} -; CHECK-LABEL: Lxray_synthetic_1: +; CHECK-LABEL: Lxray_sleds_start1: ; CHECK: .quad {{.*}}xray_sled_2 ; CHECK: .quad {{.*}}xray_sled_3 -; CHECK-LABEL: Lxray_synthetic_end1: +; CHECK-LABEL: Lxray_sleds_end1: ; CHECK: .section {{.*}}xray_fn_idx ; CHECK-LABEL: Lxray_fn_idx_synth_1: -; CHECK: .quad {{.*}}xray_synthetic_1 -; CHECK: .quad {{.*}}xray_synthetic_end1 +; CHECK: .quad {{.*}}xray_sleds_start1 +; CHECK: .quad {{.*}}xray_sleds_end1 -- 2.40.0