Skip to content

Commit 44b8a3c

Browse files
committed
Use kMaxStackFrameSize and remove local true_start.
Update test to passing.
1 parent d31eea6 commit 44b8a3c

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

compiler-rt/lib/asan/asan_fake_stack.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ FakeStack *FakeStack::Create(uptr stack_size_log) {
5454
stack_size_log = kMinStackSizeLog;
5555
if (stack_size_log > kMaxStackSizeLog)
5656
stack_size_log = kMaxStackSizeLog;
57+
CHECK_LE(kMaxStackFrameSizeLog, stack_size_log);
5758
uptr size = RequiredSize(stack_size_log);
58-
uptr padded_size = size + (1 << kMaxStackFrameSizeLog);
59+
uptr padded_size = size + kMaxStackFrameSize;
5960
void *true_res = reinterpret_cast<void *>(
6061
flags()->uar_noreserve ? MmapNoReserveOrDie(padded_size, "FakeStack")
6162
: MmapOrDie(padded_size, "FakeStack"));
@@ -64,7 +65,7 @@ FakeStack *FakeStack::Create(uptr stack_size_log) {
6465
// (1 << kMaxStackFrameSizeLog).
6566
// We didn't use MmapAlignedOrDieOnFatalError, because it requires that the
6667
// *size* is a power of 2, which is an overly strong condition.
67-
static_assert(alignof(FakeStack) <= (1 << kMaxStackFrameSizeLog));
68+
static_assert(alignof(FakeStack) <= kMaxStackFrameSize);
6869
FakeStack *res = reinterpret_cast<FakeStack *>(
6970
RoundUpTo(
7071
(uptr)true_res + kFlagsOffset + SizeRequiredForFlags(stack_size_log),
@@ -94,8 +95,7 @@ void FakeStack::Destroy(int tid) {
9495
Report("T%d: FakeStack destroyed: %s\n", tid, str.data());
9596
}
9697
uptr size = RequiredSize(stack_size_log_);
97-
uptr padded_size = size + (1 << kMaxStackFrameSizeLog);
98-
void *true_start = this->true_start;
98+
uptr padded_size = size + kMaxStackFrameSize;
9999
FlushUnneededASanShadowMemory(reinterpret_cast<uptr>(true_start),
100100
padded_size);
101101
UnmapOrDie(true_start, padded_size);

compiler-rt/lib/asan/asan_fake_stack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct FakeFrame {
5656
class FakeStack {
5757
static const uptr kMinStackFrameSizeLog = 6; // Min frame is 64B.
5858
static const uptr kMaxStackFrameSizeLog = 16; // Max stack frame is 64K.
59+
static_assert(kMaxStackFrameSizeLog >= kMinStackFrameSizeLog);
60+
61+
static const u64 kMaxStackFrameSize = 1 << kMaxStackFrameSizeLog;
5962

6063
public:
6164
static const uptr kNumberOfSizeClasses =

compiler-rt/test/asan/TestCases/fakestack_alignment.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Regression test 1:
2-
// This deterministically fails: when the stack size is 1<<16, FakeStack's
3-
// GetFrame() is out of alignment, because SizeRequiredForFlags(16) == 2K.
2+
// When the stack size is 1<<16, SizeRequiredForFlags(16) == 2KB. This forces
3+
// FakeStack's GetFrame() out of alignment if the FakeStack isn't padded.
44
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=4096 -DTHREAD_COUNT=1 -DTHREAD_STACK_SIZE=65536 %s -o %t && %run %t 2>&1
55

66
// Regression test 2:
7-
// The FakeStack frame is not guaranteed to be aligned, but alignment can
8-
// happen by chance, so try this on many threads.
7+
// Check that the FakeStack frame is aligned, beyond the typical 4KB page
8+
// alignment. Alignment can happen by chance, so try this on many threads.
99
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=8192 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=131072 %s -o %t && %run %t 2>&1
1010
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=16384 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=131072 %s -o %t && %run %t 2>&1
1111

@@ -17,8 +17,6 @@
1717
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=8192 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=131072 %s -o %t && %run %t 2>&1
1818
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=16384 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=131072 %s -o %t && %run %t 2>&1
1919

20-
// XFAIL: *
21-
2220
#include <assert.h>
2321
#include <pthread.h>
2422
#include <stdio.h>

0 commit comments

Comments
 (0)