Skip to content

Commit dcd3304

Browse files
committed
[asan] Add test case for alignment of FakeStack frames for 4KB objects
This test case demonstrates that ASan does not currently align FakeStack frames correctly for 4KB objects. It deliberately uses a smaller thread stack size (64KB), which forces the FakeStack frames to no longer be 4KB aligned. This differs from llvm#152889, which is a test case for objects >4KB, which relies on the fact that the default 4KB alignment for fake stack sizes >64KB is insufficient. llvm#152819 will fix both issues.
1 parent 97f0ff0 commit dcd3304

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 %s -o %t && %run %t 2>&1
2+
// XFAIL: *
3+
4+
#include <assert.h>
5+
#include <pthread.h>
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
10+
struct alignas(4096) page {
11+
int x;
12+
};
13+
14+
void *Thread(void *unused) {
15+
page p1;
16+
uint alignment = (unsigned long)&p1 % alignof(page);
17+
printf ("Thread: address modulo alignment is %u\n", alignment);
18+
assert(alignment == 0);
19+
20+
return NULL;
21+
}
22+
23+
int main(int argc, char **argv) {
24+
pthread_attr_t attr;
25+
pthread_attr_init(&attr);
26+
27+
// When the stack size is 1<<16, FakeStack's GetFrame() is out of alignment,
28+
// because SizeRequiredForFlags(16) == 2K.
29+
pthread_attr_setstacksize(&attr, 1<<16);
30+
31+
pthread_t t;
32+
pthread_create(&t, &attr, Thread, 0);
33+
pthread_attr_destroy(&attr);
34+
pthread_join(t, 0);
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)