[compiler-rt] r274727 - [esan|cfrag] Handle binaries built with -esan-aux-field-info=false

Qin Zhao via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 20:20:25 PDT 2016


Author: zhaoqin
Date: Wed Jul  6 22:20:24 2016
New Revision: 274727

URL: http://llvm.org/viewvc/llvm-project?rev=274727&view=rev
Log:
[esan|cfrag] Handle binaries built with -esan-aux-field-info=false

Summary:
Handles binaries built with -esan-aux-field-info=false and print less
information.

Updates test struct-simple.cpp.

Reviewers: aizatsky

Subscribers: llvm-commits, bruening, eugenis, kcc, zhaoqin, kubabrecka, vitalybuka

Differential Revision: http://reviews.llvm.org/D22020

Modified:
    compiler-rt/trunk/lib/esan/cache_frag.cpp
    compiler-rt/trunk/test/esan/TestCases/struct-simple.cpp

Modified: compiler-rt/trunk/lib/esan/cache_frag.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/cache_frag.cpp?rev=274727&r1=274726&r2=274727&view=diff
==============================================================================
--- compiler-rt/trunk/lib/esan/cache_frag.cpp (original)
+++ compiler-rt/trunk/lib/esan/cache_frag.cpp Wed Jul  6 22:20:24 2016
@@ -28,11 +28,12 @@ struct StructInfo {
   const char *StructName;
   u32 Size;
   u32 NumFields;
-  u32 *FieldOffsets;
-  u32 *FieldSize;
-  const char **FieldTypeNames;
+  u32 *FieldOffset;           // auxiliary struct field info.
+  u32 *FieldSize;             // auxiliary struct field info.
+  const char **FieldTypeName; // auxiliary struct field info.
   u64 *FieldCounters;
   u64 *ArrayCounter;
+  bool hasAuxFieldInfo() { return FieldOffset != nullptr; }
 };
 
 // This should be kept consistent with LLVM's EfficiencySanitizer CacheFragInfo.
@@ -99,10 +100,17 @@ static void reportStructCounter(StructHa
   Report("  %s %.*s\n", type, end - start, start);
   Report("   size = %u, count = %llu, ratio = %llu, array access = %llu\n",
          Struct->Size, Handle->Count, Handle->Ratio, *Struct->ArrayCounter);
-  for (u32 i = 0; i < Struct->NumFields; ++i) {
-    Report("   #%2u: offset = %u,\t size = %u,\t count = %llu,\t type = %.*s\n",
-           i, Struct->FieldOffsets[i], Struct->FieldSize[i],
-           Struct->FieldCounters[i], TypePrintLimit, Struct->FieldTypeNames[i]);
+  if (Struct->hasAuxFieldInfo()) {
+    for (u32 i = 0; i < Struct->NumFields; ++i) {
+      Report("   #%2u: offset = %u,\t size = %u,"
+             "\t count = %llu,\t type = %.*s\n",
+             i, Struct->FieldOffset[i], Struct->FieldSize[i],
+             Struct->FieldCounters[i], TypePrintLimit, Struct->FieldTypeName[i]);
+    }
+  } else {
+    for (u32 i = 0; i < Struct->NumFields; ++i) {
+      Report("   #%2u: count = %llu\n", i, Struct->FieldCounters[i]);
+    }
   }
 }
 

Modified: compiler-rt/trunk/test/esan/TestCases/struct-simple.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/esan/TestCases/struct-simple.cpp?rev=274727&r1=274726&r2=274727&view=diff
==============================================================================
--- compiler-rt/trunk/test/esan/TestCases/struct-simple.cpp (original)
+++ compiler-rt/trunk/test/esan/TestCases/struct-simple.cpp Wed Jul  6 22:20:24 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_esan_frag -O0 %s -DPART1 -c -o %t-part1.o 2>&1
+// RUN: %clang_esan_frag -O0 %s -DPART1 -mllvm -esan-aux-field-info=0 -c -o %t-part1.o 2>&1
 // RUN: %clang_esan_frag -O0 %s -DPART2 -c -o %t-part2.o 2>&1
 // RUN: %clang_esan_frag -O0 %s -DMAIN -c -o %t-main.o 2>&1
 // RUN: %clang_esan_frag -O0 %t-part1.o %t-part2.o %t-main.o -o %t 2>&1
@@ -163,8 +163,8 @@ int main(int argc, char **argv) {
   // CHECK-NEXT:  Unregister struct.S#2#11#11:    2 fields
   // CHECK-NEXT:   {{.*}} struct S
   // CHECK-NEXT:   {{.*}}  size = 8, count = 2, ratio = 2, array access = 0
-  // CHECK-NEXT:   {{.*}}  # 0: offset = 0, size = 4, count = 2, type = i32
-  // CHECK-NEXT:   {{.*}}  # 1: offset = 4, size = 4, count = 0, type = i32
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2
+  // CHECK-NEXT:   {{.*}}  # 1: count = 0
   // CHECK-NEXT:  Unregister struct.D#3#11#11#11: 3 fields
   // CHECK-NEXT:   {{.*}} struct D
   // CHECK-NEXT:   {{.*}}  size = 12, count = 2, ratio = 2, array access = 0
@@ -178,27 +178,27 @@ int main(int argc, char **argv) {
   // CHECK-NEXT:  Unregister struct.A#2#11#11:    2 fields
   // CHECK-NEXT:   {{.*}} struct A
   // CHECK-NEXT:   {{.*}}  size = 8, count = 2049, ratio = 2048, array access = 0
-  // CHECK-NEXT:   {{.*}}  # 0: offset = 0, size = 4, count = 2048, type = i32
-  // CHECK-NEXT:   {{.*}}  # 1: offset = 4, size = 4, count = 1, type = i32
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2048
+  // CHECK-NEXT:   {{.*}}  # 1: count = 1
   // CHECK-NEXT:  Unregister struct.B#2#3#2:      2 fields
   // CHECK-NEXT:   {{.*}} struct B
   // CHECK-NEXT:   {{.*}}  size = 16, count = 2097153, ratio = 2097152, array access = 0
-  // CHECK-NEXT:   {{.*}}  # 0: offset = 0, size = 4, count = 1, type = float
-  // CHECK-NEXT:   {{.*}}  # 1: offset = 8, size = 8, count = 2097152, type = double
+  // CHECK-NEXT:   {{.*}}  # 0: count = 1
+  // CHECK-NEXT:   {{.*}}  # 1: count = 2097152
   // CHECK-NEXT:  Unregister union.U#1#3:         1 fields
   // CHECK-NEXT:  Duplicated struct.S#2#11#11:    2 fields
   // CHECK-NEXT:  Unregister struct.D#3#14#11#11: 3 fields
   // CHECK-NEXT:  {{.*}} struct D
   // CHECK-NEXT:  {{.*}}  size = 128, count = 2097153, ratio = 2097153, array access = 0
-  // CHECK-NEXT:  {{.*}}  # 0: offset = 0, size = 4, count = 1, type = i32
-  // CHECK-NEXT:  {{.*}}  # 1: offset = 4, size = 4, count = 0, type = i32
-  // CHECK-NEXT:  {{.*}}  # 2: offset = 8, size = 120, count = 2097152, type = [10 x %struct.anon]
+  // CHECK-NEXT:  {{.*}}  # 0: count = 1
+  // CHECK-NEXT:  {{.*}}  # 1: count = 0
+  // CHECK-NEXT:  {{.*}}  # 2: count = 2097152
   // CHECK-NEXT:  Unregister struct.anon#3#11#11#11: 3 fields
   // CHECK-NEXT:  {{.*}} struct anon
   // CHECK-NEXT:  {{.*}}  size = 12, count = 2097152, ratio = 4194304, array access = 2097152
-  // CHECK-NEXT:  {{.*}}  # 0: offset = 0, size = 4, count = 0, type = i32
-  // CHECK-NEXT:  {{.*}}  # 1: offset = 4, size = 4, count = 2097152, type = i32
-  // CHECK-NEXT:  {{.*}}  # 2: offset = 8, size = 4, count = 0, type = i32
+  // CHECK-NEXT:  {{.*}}  # 0: count = 0
+  // CHECK-NEXT:  {{.*}}  # 1: count = 2097152
+  // CHECK-NEXT:  {{.*}}  # 2: count = 0
   // CHECK-NEXT: {{.*}}EfficiencySanitizer: total struct field access count = 6293518
 }
 #endif // MAIN




More information about the llvm-commits mailing list