]> granicus.if.org Git - llvm/commitdiff
[XRay] Reduce synthetic references emitted by XRay
authorDean Michael Berris <dberris@google.com>
Wed, 21 Jun 2017 06:39:42 +0000 (06:39 +0000)
committerDean Michael Berris <dberris@google.com>
Wed, 21 Jun 2017 06:39:42 +0000 (06:39 +0000)
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
test/CodeGen/AArch64/xray-attribute-instrumentation.ll
test/CodeGen/AArch64/xray-tail-call-sled.ll
test/CodeGen/ARM/xray-armv6-attribute-instrumentation.ll
test/CodeGen/ARM/xray-armv7-attribute-instrumentation.ll
test/CodeGen/X86/xray-attribute-instrumentation.ll
test/CodeGen/X86/xray-custom-log.ll
test/CodeGen/X86/xray-log-args.ll
test/CodeGen/X86/xray-tail-call-sled.ll

index ad348d723bae000e4588e04ebd1edc56c3c5aadd..c48fcaa7b0d1dd6cb9491d43044180a7979db418 100644 (file)
@@ -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
index 38b62a72a20f5ac7eaf8fe0c2b9c9be5d85db905..5f01c7c8be84c3430a1ce492cde20b81d56285de 100644 (file)
@@ -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
index fb89950b99c844f0ee51a86a7bab3f4da87f7a4d..a7e993b3dbac9bf24d7e24e5371f87be82daff85 100644 (file)
@@ -28,21 +28,20 @@ define i32 @callee() nounwind noinline uwtable "function-instrument"="xray-alway
 ; CHECK-NEXT:  ret\r
 }\r
 ; CHECK:       .p2align 4\r
-; CHECK-NEXT:  .xword .Lxray_synthetic_0\r
 ; CHECK-NEXT:  .xword .Lxray_fn_idx_synth_0\r
 ; CHECK-NEXT:  .section xray_instr_map,{{.*}}\r
-; CHECK-LABEL: Lxray_synthetic_0:\r
+; CHECK-LABEL: Lxray_sleds_start0:\r
 ; CHECK:       .xword .Lxray_sled_0\r
 ; CHECK:       .xword .Lxray_sled_1\r
-; CHECK-LABEL: Lxray_synthetic_end0:\r
+; CHECK-LABEL: Lxray_sleds_end0:\r
 ; CHECK:       .section xray_fn_idx,{{.*}}\r
 ; CHECK-LABEL: Lxray_fn_idx_synth_0:\r
-; CHECK:       .xword .Lxray_synthetic_0\r
-; CHECK-NEXT:  .xword .Lxray_synthetic_end0\r
+; CHECK:       .xword .Lxray_sleds_start0\r
+; CHECK-NEXT:  .xword .Lxray_sleds_end0\r
 \r
 define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-always" {\r
 ; CHECK:       .p2align        2\r
-; CHECK-LABEL: .Lxray_sled_2:\r
+; CHECK-LABEL: Lxray_sled_2:\r
 ; CHECK-NEXT:  b       #32\r
 ; CHECK-NEXT:  nop\r
 ; CHECK-NEXT:  nop\r
@@ -53,7 +52,7 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway
 ; CHECK-NEXT:  nop\r
 ; CHECK-LABEL: .Ltmp2:\r
 ; CHECK:       .p2align        2\r
-; CHECK-LABEL: .Lxray_sled_3:\r
+; CHECK-LABEL: Lxray_sled_3:\r
 ; CHECK-NEXT:  b       #32\r
 ; CHECK-NEXT:  nop\r
 ; CHECK-NEXT:  nop\r
@@ -68,14 +67,13 @@ define i32 @caller() nounwind noinline uwtable "function-instrument"="xray-alway
   ret i32 %retval\r
 }\r
 ; CHECK:       .p2align 4\r
-; CHECK-NEXT:  .xword .Lxray_synthetic_1\r
 ; CHECK-NEXT:  .xword .Lxray_fn_idx_synth_1\r
 ; CHECK-NEXT:  .section xray_instr_map,{{.*}}\r
-; CHECK-LABEL: Lxray_synthetic_1:\r
+; CHECK-LABEL: Lxray_sleds_start1:\r
 ; CHECK:       .xword .Lxray_sled_2\r
 ; CHECK:       .xword .Lxray_sled_3\r
-; CHECK-LABEL: Lxray_synthetic_end1:\r
+; CHECK-LABEL: Lxray_sleds_end1:\r
 ; CHECK:       .section xray_fn_idx,{{.*}}\r
 ; CHECK-LABEL: Lxray_fn_idx_synth_1:\r
-; CHECK:       .xword .Lxray_synthetic_1\r
-; CHECK-NEXT:  .xword .Lxray_synthetic_end1\r
+; CHECK:       .xword .Lxray_sleds_start1\r
+; CHECK-NEXT:  .xword .Lxray_sleds_end1\r
index 5e3c45c3454d850ca25a80434c6ddaaf0bebb16f..5017de835b5dae0d35889e740894e09b36878cc6 100644 (file)
@@ -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
index 739151fbdd5e541f4e4b85d458b0b16e5de1ae2e..118c02adeb8aa011cbb4a8f29d06946b53998bfe 100644 (file)
@@ -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
 
index 7c60327d2c3048bf1de7978c525f8730741ab144..00b45f8d95b7271cbab194170863a68a4bef2cf1 100644 (file)
@@ -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
index 63625d44b4cb21afaf6419140785563f53a93d6d..69fd0f3e9f772e667cd3486c777a9827ab4e2d8f 100644 (file)
@@ -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)
index a551868ffb4a7e2f9be1a14951f626348519c879..6fe450ac8ad33c38769c1c7831efed4079174e91 100644 (file)
@@ -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
index b12c78a77b203f1537ac16e1a8cafe7fe43041ab..c4a973e529f40da51ff795cc55e61be4612a0bbc 100644 (file)
@@ -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