-
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b8dd31d
[asan] Add test case for alignment of FakeStack frames
thurstond 115b11b
clang-format
thurstond ad9be29
Simplify test case by removing useless steps
thurstond cd20b4a
Merge with other test case: FakeStack frames for 4KB objects with sma…
thurstond b370e6a
Hide redundant test output, add more test combinations
thurstond 53b138e
Hide output (it's too much bother making printing the first instance
thurstond 0584edf
clang-format
thurstond 1f1f404
C++-ize
thurstond 2ec235b
clang-format
thurstond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Regression test 1: | ||
// This deterministically fails: when the stack size is 1<<16, FakeStack's | ||
// GetFrame() is out of alignment, because SizeRequiredForFlags(16) == 2K. | ||
// 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 | ||
|
||
// Regression test 2: | ||
// The FakeStack frame is not guaranteed to be aligned, but alignment can | ||
// happen by chance, so try this on many threads. | ||
// 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 | ||
// 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 | ||
|
||
// Extra tests: | ||
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=4096 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=65536 %s -o %t && %run %t 2>&1 | ||
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=8192 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=65536 %s -o %t && %run %t 2>&1 | ||
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=16384 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=65536 %s -o %t && %run %t 2>&1 | ||
// RUN: %clangxx_asan -fsanitize-address-use-after-return=always -O0 -DALIGNMENT=4096 -DTHREAD_COUNT=32 -DTHREAD_STACK_SIZE=131072 %s -o %t && %run %t 2>&1 | ||
// 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 | ||
// 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 | ||
|
||
// XFAIL: * | ||
|
||
#include <assert.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
struct alignas(ALIGNMENT) big_object { | ||
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) { | ||
big_object x; | ||
uint alignment = (unsigned long)&x % alignof(big_object); | ||
|
||
if (alignment != 0) | ||
misaligned = true; | ||
|
||
return NULL; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
pthread_attr_t attr; | ||
pthread_attr_init(&attr); | ||
#ifdef THREAD_STACK_SIZE | ||
pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE); | ||
#endif | ||
|
||
pthread_t t[THREAD_COUNT]; | ||
for (int i = 0; i < THREAD_COUNT; 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. optionally, if you think it's an improvement: we can use range based for loops for all of these.
etc 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 |
||
pthread_create(&t[i], &attr, Thread, 0); | ||
|
||
pthread_attr_destroy(&attr); | ||
|
||
for (int i = 0; i < THREAD_COUNT; i++) | ||
pthread_join(t[i], 0); | ||
|
||
if (misaligned) { | ||
printf("Test failed: not perfectly aligned\n"); | ||
exit(1); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 C++, use
nullptr
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.
Done