Skip to content

[compiler-rt] [HWASan] leave BufferedStackTrace uninit #102247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Aug 6, 2024

Otherwise we have to memset 2040 bytes (255 * 8) for each call to a
malloc-like function.

This caused noticable slowdown on AOSP.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Florian Mayer (fmayer)

Changes

Otherwise we have to memset 2040 bytes (255 * 8) for each call to a
malloc-like function.

This caused noticable slowdown on AOSP.


Full diff: https://github.com/llvm/llvm-project/pull/102247.diff

1 Files Affected:

  • (modified) compiler-rt/lib/hwasan/hwasan.h (+4-4)
diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h
index df21375e81671..b918368fe8658 100644
--- a/compiler-rt/lib/hwasan/hwasan.h
+++ b/compiler-rt/lib/hwasan/hwasan.h
@@ -139,15 +139,15 @@ void hwasan_free(void *ptr, StackTrace *stack);
 void InstallAtExitHandler();
 
 #define GET_MALLOC_STACK_TRACE                                            \
-  BufferedStackTrace stack;                                               \
+  __attribute__((uninitialized)) BufferedStackTrace stack;                \
   if (hwasan_inited)                                                      \
     stack.Unwind(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(),         \
                  nullptr, common_flags()->fast_unwind_on_malloc,          \
                  common_flags()->malloc_context_size)
 
-#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp)              \
-  BufferedStackTrace stack;                              \
-  if (hwasan_inited)                                     \
+#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp)                \
+  __attribute__((uninitialized)) BufferedStackTrace stack; \
+  if (hwasan_inited)                                       \
     stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal)
 
 void HwasanTSDInit();

Copy link

github-actions bot commented Aug 6, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 84cc1865ef9202af39404ff4524a9b13df80cfc1 f112952c5abfe9d4a6e25ebdef203e4c9f1b3818 --extensions h -- compiler-rt/lib/hwasan/hwasan.h
View the diff from clang-format here.
diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h
index 1ae463f845..7c9feef0c7 100644
--- a/compiler-rt/lib/hwasan/hwasan.h
+++ b/compiler-rt/lib/hwasan/hwasan.h
@@ -138,17 +138,17 @@ void hwasan_free(void *ptr, StackTrace *stack);
 
 void InstallAtExitHandler();
 
-#define GET_MALLOC_STACK_TRACE                                            \
-  UNINITIALIZED BufferedStackTrace stack;                                 \
-  if (hwasan_inited)                                                      \
-    stack.Unwind(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(),         \
-                 nullptr, common_flags()->fast_unwind_on_malloc,          \
-                 common_flags()->malloc_context_size)
-
-#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp)              \
-  UNINITIALIZED BufferedStackTrace stack;                \
-  if (hwasan_inited)                                     \
-    stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal)
+#define GET_MALLOC_STACK_TRACE                                           \
+  UNINITIALIZED BufferedStackTrace stack;                                \
+  if (hwasan_inited)                                                     \
+  stack.Unwind(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), nullptr, \
+               common_flags()->fast_unwind_on_malloc,                    \
+               common_flags()->malloc_context_size)
+
+#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) \
+  UNINITIALIZED BufferedStackTrace stack;   \
+  if (hwasan_inited)                        \
+  stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal)
 
 void HwasanTSDInit();
 void HwasanTSDThreadInit();

@fmayer fmayer requested a review from vitalybuka August 6, 2024 23:35
fmayer added 2 commits August 6, 2024 16:43
Created using spr 1.3.4
Created using spr 1.3.4
@vitalybuka vitalybuka merged commit ee870e5 into main Aug 7, 2024
5 of 6 checks passed
@vitalybuka vitalybuka deleted the users/fmayer/spr/compiler-rt-hwasan-leave-bufferedstacktrace-uninit branch August 7, 2024 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants