Skip to content

Commit

Permalink
[esan|cfrag] Handle binaries built with -esan-aux-field-info=false
Browse files Browse the repository at this point in the history
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

llvm-svn: 274727
  • Loading branch information
zhaoqin committed Jul 7, 2016
1 parent c35b2cb commit 7f92eab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
22 changes: 15 additions & 7 deletions compiler-rt/lib/esan/cache_frag.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -99,10 +100,17 @@ static void reportStructCounter(StructHashMap::Handle &Handle) {
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]);
}
}
}

Expand Down
26 changes: 13 additions & 13 deletions compiler-rt/test/esan/TestCases/struct-simple.cpp
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 7f92eab

Please sign in to comment.