Skip to content

Commit 9c491c8

Browse files
committed
[sanitizer] Hook up LZW into stack store
Depends on D114503. Reviewed By: morehouse Differential Revision: https://reviews.llvm.org/D114924
1 parent 3aed282 commit 9c491c8

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "sanitizer_common.h"
1313
#include "sanitizer_internal_defs.h"
1414
#include "sanitizer_leb128.h"
15+
#include "sanitizer_lzw.h"
16+
#include "sanitizer_placement_new.h"
1517
#include "sanitizer_stacktrace.h"
1618

1719
namespace __sanitizer {
@@ -203,6 +205,22 @@ static uptr *UncompressDelta(const u8 *from, const u8 *from_end, uptr *to,
203205
return to;
204206
}
205207

208+
static u8 *CompressLzw(const uptr *from, const uptr *from_end, u8 *to,
209+
u8 *to_end) {
210+
SLeb128Encoder encoder(to, to_end);
211+
encoder = LzwEncode<uptr>(from, from_end, encoder);
212+
return encoder.base();
213+
}
214+
215+
static uptr *UncompressLzw(const u8 *from, const u8 *from_end, uptr *to,
216+
uptr *to_end) {
217+
SLeb128Decoder decoder(from, from_end);
218+
SLeb128Decoder end(from_end, from_end);
219+
to = LzwDecode<uptr>(decoder, end, to);
220+
CHECK_EQ(to, to_end);
221+
return to;
222+
}
223+
206224
namespace {
207225
struct PackedHeader {
208226
uptr size;
@@ -240,6 +258,10 @@ uptr *StackStore::BlockInfo::GetOrUnpack() {
240258
unpacked_end = UncompressDelta(header->data, ptr + header->size, unpacked,
241259
unpacked + kBlockSizeFrames);
242260
break;
261+
case Compression::LZW:
262+
unpacked_end = UncompressLzw(header->data, ptr + header->size, unpacked,
263+
unpacked + kBlockSizeFrames);
264+
break;
243265
default:
244266
UNREACHABLE("Unexpected type");
245267
break;
@@ -283,6 +305,10 @@ uptr StackStore::BlockInfo::Pack(Compression type) {
283305
packed_end =
284306
CompressDelta(ptr, ptr + kBlockSizeFrames, header->data, alloc_end);
285307
break;
308+
case Compression::LZW:
309+
packed_end =
310+
CompressLzw(ptr, ptr + kBlockSizeFrames, header->data, alloc_end);
311+
break;
286312
default:
287313
UNREACHABLE("Unexpected type");
288314
break;

compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class StackStore {
2626
enum class Compression : u8 {
2727
None = 0,
2828
Delta,
29+
LZW,
2930
};
3031

3132
constexpr StackStore() = default;

compiler-rt/lib/sanitizer_common/tests/sanitizer_stack_store_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ INSTANTIATE_TEST_SUITE_P(
137137
::testing::ValuesIn({
138138
StackStorePackTest::ParamType(StackStore::Compression::Delta,
139139
FIRST_32_SECOND_64(2, 6)),
140+
StackStorePackTest::ParamType(StackStore::Compression::LZW,
141+
FIRST_32_SECOND_64(60, 130)),
140142
}));
141143

142144
TEST_P(StackStorePackTest, PackUnpack) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clangxx %s -fsanitize-memory-track-origins=1 -o %t
22
// 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"
33
// RUN: %env_tool_opts="compress_stack_depot=1:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS
4+
// RUN: %env_tool_opts="compress_stack_depot=2:malloc_context_size=128:verbosity=1" %run %t 2>&1 | FileCheck %s --check-prefixes=COMPRESS
45

56
// Ubsan does not store stacks.
67
// UNSUPPORTED: ubsan

0 commit comments

Comments
 (0)