[compiler-rt] 9dad344 - tsan: strip __libc_start_main frame
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 28 11:26:47 PDT 2021
Author: Dmitry Vyukov
Date: 2021-07-28T20:26:42+02:00
New Revision: 9dad34423b649f8d8ff2f4e6cee0c600f28f2d57
URL: https://github.com/llvm/llvm-project/commit/9dad34423b649f8d8ff2f4e6cee0c600f28f2d57
DIFF: https://github.com/llvm/llvm-project/commit/9dad34423b649f8d8ff2f4e6cee0c600f28f2d57.diff
LOG: tsan: strip __libc_start_main frame
We strip all frames below main but in some cases it may be not enough.
Namely, when main is instrumented but does not call any other instrumented code.
In this case __tsan_func_entry in main obtains PC pointing to __libc_start_main
(as we pass caller PC to __tsan_func_entry), but nothing obtains PC pointing
to main itself (as main does not call any instrumented code).
In such case we will not have main in the stack, and stripping everything
below main won't work.
So strip __libc_start_main explicitly as well.
But keep stripping of main because __libc_start_main is glibc/linux-specific,
so looking for main is more reliable (and usually main is present in stacks).
Depends on D106957.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D106958
Added:
Modified:
compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
compiler-rt/test/tsan/java_symbolization.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
index 708ee7f21708..46374fc953c0 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
@@ -68,8 +68,10 @@ static void StackStripMain(SymbolizedStack *frames) {
} else if (last && 0 == internal_strcmp(last, "__tsan_thread_start_func")) {
last_frame->ClearAll();
last_frame2->next = nullptr;
- // Strip global ctors init.
- } else if (last && 0 == internal_strcmp(last, "__do_global_ctors_aux")) {
+ // Strip global ctors init, .preinit_array and main caller.
+ } else if (last && (0 == internal_strcmp(last, "__do_global_ctors_aux") ||
+ 0 == internal_strcmp(last, "__libc_csu_init") ||
+ 0 == internal_strcmp(last, "__libc_start_main"))) {
last_frame->ClearAll();
last_frame2->next = nullptr;
// If both are 0, then we probably just failed to symbolize.
diff --git a/compiler-rt/test/tsan/java_symbolization.cpp b/compiler-rt/test/tsan/java_symbolization.cpp
index 34e18a771b75..a0187acc991a 100644
--- a/compiler-rt/test/tsan/java_symbolization.cpp
+++ b/compiler-rt/test/tsan/java_symbolization.cpp
@@ -62,11 +62,9 @@ int main() {
// CHECK: #1 MyOuterFunc MyOuterFile.java:4321:65
// CHECK: #2 Caller1 CallerFile.java:111:22
// CHECK: #3 Caller2 CallerFile.java:333:44
-// On Linux/glibc #4 is __libc_start_main, but can be something else elsewhere.
-// CHECK: #4
+// CHECK-NOT: #4
// CHECK: Location is heap block of size 32 at {{.*}} allocated by main thread:
// CHECK: #0 Allocer1 Alloc.java:11:222
// CHECK: #1 Allocer2 Alloc.java:33:444
-// On Linux/glibc #2 is __libc_start_main, but can be something else elsewhere.
-// CHECK: #2
+// CHECK-NOT: #2
// CHECK: DONE
More information about the llvm-commits
mailing list