Skip to content

Commit 71e5652

Browse files
authored
[sanitizer] Select non-internal frames in ReportErrorSummary (llvm#77406)
Summary contains one line and should point to user code instead of internal compiler-rt location. TSAN already does that.
1 parent 4e8986f commit 71e5652

File tree

10 files changed

+58
-42
lines changed

10 files changed

+58
-42
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,33 @@ void ReportErrorSummary(const char *error_type, const StackTrace *stack,
9595
#if !SANITIZER_GO
9696
if (!common_flags()->print_summary)
9797
return;
98-
if (stack->size == 0) {
99-
ReportErrorSummary(error_type);
100-
return;
98+
99+
// Find first non-internal stack frame.
100+
for (uptr i = 0; i < stack->size; ++i) {
101+
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[i]);
102+
SymbolizedStackHolder symbolized_stack(
103+
Symbolizer::GetOrInit()->SymbolizePC(pc));
104+
if (const SymbolizedStack *frame = symbolized_stack.get()) {
105+
if (const SymbolizedStack *summary_frame = SkipInternalFrames(frame)) {
106+
ReportErrorSummary(error_type, summary_frame->info, alt_tool_name);
107+
return;
108+
}
109+
}
110+
}
111+
112+
// Fallback to the top one.
113+
if (stack->size) {
114+
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
115+
SymbolizedStackHolder symbolized_stack(
116+
Symbolizer::GetOrInit()->SymbolizePC(pc));
117+
if (const SymbolizedStack *frame = symbolized_stack.get()) {
118+
ReportErrorSummary(error_type, frame->info, alt_tool_name);
119+
return;
120+
}
101121
}
102-
// Currently, we include the first stack frame into the report summary.
103-
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
104-
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
105-
SymbolizedStackHolder symbolized_stack(
106-
Symbolizer::GetOrInit()->SymbolizePC(pc));
107-
const SymbolizedStack *frame = symbolized_stack.get();
108-
ReportErrorSummary(error_type, frame->info, alt_tool_name);
122+
123+
// Fallback to a summary without location.
124+
ReportErrorSummary(error_type);
109125
#endif
110126
}
111127

compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main() {
1414
// CHECK: ERROR: HWAddressSanitizer: invalid alignment requested in aligned_alloc: 17
1515
// CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
1616
// CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cpp:}}[[@LINE-3]]
17-
// CHECK: SUMMARY: HWAddressSanitizer: invalid-aligned-alloc-alignment {{.*}} in aligned_alloc
17+
// CHECK: SUMMARY: HWAddressSanitizer: invalid-aligned-alloc-alignment {{.*}} in main
1818

1919
printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
2020
// CHECK-NULL: pointer after failed aligned_alloc: 0

compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ int main(int argc, char *argv[]) {
3939
// CHECK: {{ERROR: HWAddressSanitizer: pvalloc parameters overflow: size .* rounded up to system page size .* cannot be represented in type size_t}}
4040
// CHECK: {{#0 0x.* in .*pvalloc}}
4141
// CHECK: {{#1 0x.* in main .*pvalloc-overflow.cpp:}}
42-
// CHECK: SUMMARY: HWAddressSanitizer: pvalloc-overflow {{.*}} in pvalloc
42+
// CHECK: SUMMARY: HWAddressSanitizer: pvalloc-overflow {{.*}} in main
4343

4444
// CHECK-NULL: errno: 12

compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int main() {
1111
// CHECK: ERROR: HWAddressSanitizer: invalid alignment requested in posix_memalign: 17
1212
// CHECK: {{#0 0x.* in .*posix_memalign}}
1313
// CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cpp:}}[[@LINE-3]]
14-
// CHECK: SUMMARY: HWAddressSanitizer: invalid-posix-memalign-alignment {{.*}} in posix_memalign
14+
// CHECK: SUMMARY: HWAddressSanitizer: invalid-posix-memalign-alignment {{.*}} in main
1515

1616
printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
1717
// CHECK-NULL: pointer after failed posix_memalign: 42

compiler-rt/test/hwasan/TestCases/allocator_returns_null.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ int main(int argc, char **argv) {
8787
}
8888

8989
// CHECK-mCRASH: malloc:
90-
// CHECK-mCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in malloc
90+
// CHECK-mCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in main
9191
// CHECK-cCRASH: calloc:
92-
// CHECK-cCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in calloc
92+
// CHECK-cCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in main
9393
// CHECK-coCRASH: calloc-overflow:
94-
// CHECK-coCRASH: SUMMARY: HWAddressSanitizer: calloc-overflow {{.*}} in calloc
94+
// CHECK-coCRASH: SUMMARY: HWAddressSanitizer: calloc-overflow {{.*}} in main
9595
// CHECK-rCRASH: realloc:
96-
// CHECK-rCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in realloc
96+
// CHECK-rCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in main
9797
// CHECK-mrCRASH: realloc-after-malloc:
98-
// CHECK-mrCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in realloc
98+
// CHECK-mrCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in main
9999
// CHECK-nCRASH: new:
100-
// CHECK-nCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in operator new
100+
// CHECK-nCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in main
101101
// CHECK-nCRASH-OOM: new:
102-
// CHECK-nCRASH-OOM: SUMMARY: HWAddressSanitizer: out-of-memory {{.*}} in operator new
102+
// CHECK-nCRASH-OOM: SUMMARY: HWAddressSanitizer: out-of-memory {{.*}} in main
103103
// CHECK-nnCRASH: new-nothrow:
104-
// CHECK-nnCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in operator new
104+
// CHECK-nnCRASH: SUMMARY: HWAddressSanitizer: allocation-size-too-big {{.*}} in main
105105

106106
// CHECK-mNULL: malloc:
107107
// CHECK-mNULL: errno: 12

compiler-rt/test/hwasan/TestCases/halt-on-error.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ int main() {
2626
// COMMON: READ of size 4 at
2727
// When instrumenting with callbacks, main is actually #1, and #0 is __hwasan_load4.
2828
// COMMON: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-3]]
29-
// COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
29+
// COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
3030

3131
// RECOVER: READ of size 1 at
3232
// RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-7]]
33-
// RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
33+
// RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
3434

3535
// RECOVER: READ of size 1 at
3636
// RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-11]]
37-
// RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
37+
// RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
3838

3939
// COMMON-NOT: tag-mismatch
4040
}

compiler-rt/test/hwasan/TestCases/report-unmapped.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ int main(int argc, char **argv) {
3636
// CHECK: Tags for short granules around
3737

3838
// Check that report is complete.
39-
// CHECK: SUMMARY: HWAddressSanitizer
39+
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main

compiler-rt/test/hwasan/TestCases/use-after-free.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ int main() {
3838
// CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-24]]
3939
// CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes):
4040
// CHECK: =>{{.*}}[[MEM_TAG]]
41-
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch
41+
// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
4242
return r;
4343
}

compiler-rt/test/sanitizer_common/TestCases/allocator_returns_null.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,28 @@ int main(int argc, char **argv) {
9595

9696
// CHECK-mCRASH: malloc:
9797
// CHECK-mCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
98-
// CHECK-mCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}} in {{.*}}lloc
98+
// CHECK-mCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
9999
// CHECK-cCRASH: calloc:
100100
// CHECK-cCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
101-
// CHECK-cCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}} in {{.*}}lloc
101+
// CHECK-cCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
102102
// CHECK-coCRASH: calloc-overflow:
103103
// CHECK-coCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
104-
// CHECK-coCRASH: {{SUMMARY: .*Sanitizer: calloc-overflow.*}} in {{.*}}lloc
104+
// CHECK-coCRASH: {{SUMMARY: .*Sanitizer: calloc-overflow.*allocator_returns_null.cpp.*}} in main
105105
// CHECK-rCRASH: realloc:
106106
// CHECK-rCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
107-
// CHECK-rCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}} in {{.*}}lloc
107+
// CHECK-rCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
108108
// CHECK-mrCRASH: realloc-after-malloc:
109109
// CHECK-mrCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
110-
// CHECK-mrCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}} in {{.*}}lloc
110+
// CHECK-mrCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
111111
// CHECK-nCRASH: new:
112112
// CHECK-nCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
113-
// CHECK-nCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}} in {{operator new|.*lloc}}
113+
// CHECK-nCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
114114
// CHECK-nCRASH-OOM: new:
115115
// CHECK-nCRASH-O#{{[0-9]+.*}}allocator_returns_null.cpp
116-
// CHECK-nCRASH-OOM: {{SUMMARY: .*Sanitizer: out-of-memory.*}} in {{operator new|.*lloc}}
116+
// CHECK-nCRASH-OOM: {{SUMMARY: .*Sanitizer: out-of-memory.*allocator_returns_null.cpp.*}} in main
117117
// CHECK-nnCRASH: new-nothrow:
118118
// CHECK-nnCRASH: #{{[0-9]+.*}}allocator_returns_null.cpp
119-
// CHECK-nnCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}} in {{operator new|.*lloc}}
119+
// CHECK-nnCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*allocator_returns_null.cpp.*}} in main
120120

121121
// CHECK-NULL: {{malloc|calloc|calloc-overflow|realloc|realloc-after-malloc|new-nothrow}}
122122
// CHECK-NULL: errno: 12, x: 0

compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,28 @@ int main(int Argc, char **Argv) {
124124

125125
// CHECK-mCRASH: malloc:
126126
// CHECK-mCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
127-
// CHECK-mCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
127+
// CHECK-mCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.* in allocate}}
128128
// CHECK-cCRASH: calloc:
129129
// CHECK-cCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
130-
// CHECK-cCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
130+
// CHECK-cCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.* in allocate}}
131131
// CHECK-rCRASH: realloc:
132132
// CHECK-rCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
133-
// CHECK-rCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
133+
// CHECK-rCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.* in allocate}}
134134
// CHECK-mrCRASH: realloc-after-malloc:
135135
// CHECK-mrCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
136-
// CHECK-mrCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
136+
// CHECK-mrCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.* in allocate}}
137137
// CHECK-nCRASH: new:
138138
// CHECK-nCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
139-
// CHECK-nCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
139+
// CHECK-nCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.* in allocate}}
140140
// CHECK-nCRASH-OOM: new:
141141
// CHECK-nCRASH-OOM: #{{[0-9]+.*}}max_allocation_size.cpp
142-
// CHECK-nCRASH-OOM: {{SUMMARY: .*Sanitizer: out-of-memory}}
142+
// CHECK-nCRASH-OOM: {{SUMMARY: .*Sanitizer: out-of-memory.* in allocate}}
143143
// CHECK-nnCRASH: new-nothrow:
144144
// CHECK-nnCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
145-
// CHECK-nnCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
145+
// CHECK-nnCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.* in allocate}}
146146
// CHECK-sCRASH: strndup:
147147
// CHECK-sCRASH: #{{[0-9]+.*}}max_allocation_size.cpp
148-
// CHECK-sCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
148+
// CHECK-sCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big.*}}
149149

150150
// CHECK-NULL: {{malloc|calloc|calloc-overflow|realloc|realloc-after-malloc|new-nothrow|strndup}}
151151
// CHECK-NULL: errno: 12, P: 0

0 commit comments

Comments
 (0)