[compiler-rt] af77e5e - [msan] Extract SetAllocaOrigin
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 10 20:53:21 PDT 2022
Author: Vitaly Buka
Date: 2022-08-10T20:53:02-07:00
New Revision: af77e5e4c08eac78d9395568167fdca2fa1bf914
URL: https://github.com/llvm/llvm-project/commit/af77e5e4c08eac78d9395568167fdca2fa1bf914
DIFF: https://github.com/llvm/llvm-project/commit/af77e5e4c08eac78d9395568167fdca2fa1bf914.diff
LOG: [msan] Extract SetAllocaOrigin
Added:
Modified:
compiler-rt/lib/msan/msan.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp
index c1c6805439ae..380753bfddec 100644
--- a/compiler-rt/lib/msan/msan.cpp
+++ b/compiler-rt/lib/msan/msan.cpp
@@ -303,6 +303,31 @@ u32 ChainOrigin(u32 id, StackTrace *stack) {
return chained.raw_id();
}
+// 'descr' is created at compile time and contains '----' in the beginning.
+// When we see descr for the first time we replace '----' with a uniq id
+// and set the origin to (id | (31-th bit)).
+static inline void SetAllocaOrigin(void *a, uptr size, char *descr, uptr pc) {
+ static const u32 dash = '-';
+ static const u32 first_timer =
+ dash + (dash << 8) + (dash << 16) + (dash << 24);
+ u32 *id_ptr = (u32 *)descr;
+ bool print = false; // internal_strstr(descr + 4, "AllocaTOTest") != 0;
+ u32 id = *id_ptr;
+ if (id == first_timer) {
+ u32 idx = atomic_fetch_add(&NumStackOriginDescrs, 1, memory_order_relaxed);
+ CHECK_LT(idx, kNumStackOriginDescrs);
+ StackOriginDescr[idx] = descr + 4;
+ StackOriginPC[idx] = pc;
+ id = Origin::CreateStackOrigin(idx).raw_id();
+ *id_ptr = id;
+ if (print)
+ Printf("First time: idx=%d id=%d %s 0x%zx \n", idx, id, descr + 4, pc);
+ }
+ if (print)
+ Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
+ __msan_set_origin(a, size, id);
+}
+
} // namespace __msan
void __sanitizer::BufferedStackTrace::UnwindImpl(
@@ -581,34 +606,17 @@ void __msan_set_origin(const void *a, uptr size, u32 origin) {
if (__msan_get_track_origins()) SetOrigin(a, size, origin);
}
-// 'descr' is created at compile time and contains '----' in the beginning.
-// When we see descr for the first time we replace '----' with a uniq id
-// and set the origin to (id | (31-th bit)).
void __msan_set_alloca_origin(void *a, uptr size, char *descr) {
- __msan_set_alloca_origin4(
- a, size, descr, StackTrace::GetPreviousInstructionPc(GET_CALLER_PC()));
+ SetAllocaOrigin(a, size, descr,
+ StackTrace::GetPreviousInstructionPc(GET_CALLER_PC()));
}
void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) {
- static const u32 dash = '-';
- static const u32 first_timer =
- dash + (dash << 8) + (dash << 16) + (dash << 24);
- u32 *id_ptr = (u32*)descr;
- bool print = false; // internal_strstr(descr + 4, "AllocaTOTest") != 0;
- u32 id = *id_ptr;
- if (id == first_timer) {
- u32 idx = atomic_fetch_add(&NumStackOriginDescrs, 1, memory_order_relaxed);
- CHECK_LT(idx, kNumStackOriginDescrs);
- StackOriginDescr[idx] = descr + 4;
- StackOriginPC[idx] = pc;
- id = Origin::CreateStackOrigin(idx).raw_id();
- *id_ptr = id;
- if (print)
- Printf("First time: idx=%d id=%d %s 0x%zx \n", idx, id, descr + 4, pc);
- }
- if (print)
- Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
- __msan_set_origin(a, size, id);
+ // Intentionally ignore pc and use return address. This function is here for
+ // compatibility, in case program is linked with library instrumented by
+ // older clang.
+ SetAllocaOrigin(a, size, descr,
+ StackTrace::GetPreviousInstructionPc(GET_CALLER_PC()));
}
u32 __msan_chain_origin(u32 id) {
More information about the llvm-commits
mailing list