-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[asan] Add test case for alignment of FakeStack frames #152889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b8dd31d
115b11b
ad9be29
cd20b4a
b370e6a
53b138e
0584edf
1f1f404
2ec235b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 %s -o %t && %run %t 2>&1 | ||
// XFAIL: * | ||
|
||
#include <assert.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
struct alignas(4096) page { | ||
int x; | ||
}; | ||
|
||
struct alignas(16384) larry { | ||
int x; | ||
}; | ||
|
||
bool misaligned = false; | ||
|
||
// Check whether the FakeStack frame is sufficiently aligned. Alignment can | ||
// happen by chance, so try this on many threads. | ||
void *Thread(void *unused) { | ||
larry l1; | ||
uint alignment = (unsigned long)&l1 % alignof(larry); | ||
printf("Thread: address modulo alignment is %u\n", alignment); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to print this 32 times? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
if (alignment != 0) | ||
misaligned = true; | ||
|
||
child(); | ||
|
||
return NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is C++, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
int main(int argc, char **argv) { | ||
pthread_attr_t attr; | ||
pthread_attr_init(&attr); | ||
|
||
pthread_t t[32]; | ||
for (int i = 0; i < 32; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. braces There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
pthread_create(&t[i], &attr, Thread, 0); | ||
} | ||
pthread_attr_destroy(&attr); | ||
for (int i = 0; i < 32; i++) { | ||
pthread_join(t[i], 0); | ||
} | ||
|
||
if (misaligned) { | ||
printf("Test failed: not perfectly aligned\n"); | ||
exit(1); | ||
} | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unused? Can we merge this with the other test, and make the alignas / thread count a define instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged and #define'd