[compiler-rt] 9c491c8 - [sanitizer] Hook up LZW into stack store
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 3 23:38:49 PST 2021
Author: Vitaly Buka
Date: 2021-12-03T23:38:41-08:00
New Revision: 9c491c873c2ba239e1e48c050bc28cd08738181d
URL: https://github.com/llvm/llvm-project/commit/9c491c873c2ba239e1e48c050bc28cd08738181d
DIFF: https://github.com/llvm/llvm-project/commit/9c491c873c2ba239e1e48c050bc28cd08738181d.diff
LOG: [sanitizer] Hook up LZW into stack store
Depends on D114503.
Reviewed By: morehouse
Differential Revision: https://reviews.llvm.org/D114924
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_stack_store_test.cpp
compiler-rt/test/sanitizer_common/TestCases/compress_stack_depot.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
index 416e3b8c29fdc..af10f3a4011cd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
@@ -12,6 +12,8 @@
#include "sanitizer_common.h"
#include "sanitizer_internal_defs.h"
#include "sanitizer_leb128.h"
+#include "sanitizer_lzw.h"
+#include "sanitizer_placement_new.h"
#include "sanitizer_stacktrace.h"
namespace __sanitizer {
@@ -203,6 +205,22 @@ static uptr *UncompressDelta(const u8 *from, const u8 *from_end, uptr *to,
return to;
}
+static u8 *CompressLzw(const uptr *from, const uptr *from_end, u8 *to,
+ u8 *to_end) {
+ SLeb128Encoder encoder(to, to_end);
+ encoder = LzwEncode<uptr>(from, from_end, encoder);
+ return encoder.base();
+}
+
+static uptr *UncompressLzw(const u8 *from, const u8 *from_end, uptr *to,
+ uptr *to_end) {
+ SLeb128Decoder decoder(from, from_end);
+ SLeb128Decoder end(from_end, from_end);
+ to = LzwDecode<uptr>(decoder, end, to);
+ CHECK_EQ(to, to_end);
+ return to;
+}
+
namespace {
struct PackedHeader {
uptr size;
@@ -240,6 +258,10 @@ uptr *StackStore::BlockInfo::GetOrUnpack() {
unpacked_end = UncompressDelta(header->data, ptr + header->size, unpacked,
unpacked + kBlockSizeFrames);
break;
+ case Compression::LZW:
+ unpacked_end = UncompressLzw(header->data, ptr + header->size, unpacked,
+ unpacked + kBlockSizeFrames);
+ break;
default:
UNREACHABLE("Unexpected type");
break;
@@ -283,6 +305,10 @@ uptr StackStore::BlockInfo::Pack(Compression type) {
packed_end =
CompressDelta(ptr, ptr + kBlockSizeFrames, header->data, alloc_end);
break;
+ case Compression::LZW:
+ packed_end =
+ CompressLzw(ptr, ptr + kBlockSizeFrames, header->data, alloc_end);
+ break;
default:
UNREACHABLE("Unexpected type");
break;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
index 3ebad61c68e76..31f13bf6002bf 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
@@ -26,6 +26,7 @@ class StackStore {
enum class Compression : u8 {
None = 0,
Delta,
+ LZW,
};
constexpr StackStore() = default;
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stack_store_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stack_store_test.cpp
index 031f2d9cd8ecf..ab491359bfe51 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stack_store_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stack_store_test.cpp
@@ -137,6 +137,8 @@ INSTANTIATE_TEST_SUITE_P(
::testing::ValuesIn({
StackStorePackTest::ParamType(StackStore::Compression::Delta,
FIRST_32_SECOND_64(2, 6)),
+ StackStorePackTest::ParamType(StackStore::Compression::LZW,
+ FIRST_32_SECOND_64(60, 130)),
}));
TEST_P(StackStorePackTest, PackUnpack) {
diff --git a/compiler-rt/test/sanitizer_common/TestCases/compress_stack_depot.cpp b/compiler-rt/test/sanitizer_common/TestCases/compress_stack_depot.cpp
index 859d6e295d8f4..c64c9392a107b 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/compress_stack_depot.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/compress_stack_depot.cpp
@@ -1,6 +1,7 @@
// RUN: %clangxx %s -fsanitize-memory-track-origins=1 -o %t
// RUN: %env_tool_opts="compress_stack_depot=0:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --implicit-check-not="StackDepot released"
// RUN: %env_tool_opts="compress_stack_depot=1:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS
+// RUN: %env_tool_opts="compress_stack_depot=2:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS
// Ubsan does not store stacks.
// UNSUPPORTED: ubsan
More information about the llvm-commits
mailing list