-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add multithread support to ASan #9076
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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7d66de4
Allow ASan to be used with threads
quantum5 234da42
Set up ASan thread local storage
quantum5 cf6a402
Add comments regarding constructor priorities
quantum5 7f2a33b
Override pthread_create for ASan
quantum5 f96268a
Remove sched_yield warning
quantum5 c75a088
Raise the thread limit to 128
quantum5 871ace0
Correctly handle pthread_create proxying
quantum5 8433e54
Reuse LSan tests for ASan
quantum5 30a095b
Add threaded use-after-free test
quantum5 a8833b9
Build ASan-instrumented and multithreaded libraries
quantum5 2ef11ba
ThreadStartParam is no longer needed
quantum5 151f64b
Add a comment saying that we are reusing LSan tests
quantum5 e865fee
Merge remote-tracking branch 'origin/incoming' into asan-mt
quantum5 8c35421
Explain why we need to disable LSan in EM_PROXIED_PTHREAD_CREATE
quantum5 7833eb2
Adapt to ASan priority changing to 50
quantum5 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
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
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
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
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
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
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
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
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
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
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,16 @@ | ||
#include <cstdio> | ||
#include <thread> | ||
|
||
std::atomic<bool> thread_done; | ||
|
||
void f(int *a) { | ||
delete [] a; | ||
a[0] = 1; | ||
std::atomic_store(&thread_done, true); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
std::thread t(f, new int[10]); | ||
t.detach(); | ||
while (!std::atomic_load(&thread_done)); | ||
} |
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,25 @@ | ||
(function () { | ||
var output = []; | ||
Module['printErr'] = function (text) { | ||
if (text == '==42==ABORTING') { | ||
var result = output.join('\n'); | ||
var passed = [ | ||
'ERROR: AddressSanitizer: heap-use-after-free on address', | ||
'WRITE of size 4', | ||
'is located 0 bytes inside of 40-byte region', | ||
'freed by thread T2 here:', | ||
'previously allocated by thread T1 here:', | ||
'Thread T2 created by T1 here:', | ||
'SUMMARY: AddressSanitizer: heap-use-after-free', | ||
'Shadow bytes around the buggy address:', | ||
'Shadow byte legend (one shadow byte represents 8 application bytes):', | ||
].every(function (snippet) { | ||
return result.indexOf(snippet) >= 0; | ||
}); | ||
reportResultToServer(passed ? 1 : 0); | ||
return; | ||
} | ||
output.push(text); | ||
console.log(text); | ||
}; | ||
})(); |
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
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 |
---|---|---|
|
@@ -3911,6 +3911,20 @@ def test_pthread_tls_main(self): | |
def test_pthread_lsan(self, name, args=[]): | ||
self.btest(path_from_root('tests', 'pthread', name + '.cpp'), expected='1', args=['-fsanitize=leak', '-s', 'TOTAL_MEMORY=256MB', '-s', 'USE_PTHREADS', '-s', 'PROXY_TO_PTHREAD', '-std=c++11', '--pre-js', path_from_root('tests', 'pthread', name + '.js')] + args) | ||
|
||
@parameterized({ | ||
# Reusing the LSan test files for ASan. | ||
'leak': ['test_pthread_lsan_leak', ['-g4']], | ||
'no_leak': ['test_pthread_lsan_no_leak'], | ||
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.
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. No. We are reusing the test_pthread_lsan* for ASan. I'll add a comment to say this is not an error. |
||
}) | ||
@no_fastcomp('ASan is only supported on WASM backend') | ||
@requires_threads | ||
def test_pthread_asan(self, name, args=[]): | ||
self.btest(path_from_root('tests', 'pthread', name + '.cpp'), expected='1', args=['-fsanitize=address', '-s', 'TOTAL_MEMORY=256MB', '-s', 'USE_PTHREADS', '-s', 'PROXY_TO_PTHREAD', '-std=c++11', '--pre-js', path_from_root('tests', 'pthread', name + '.js')] + args) | ||
|
||
@no_fastcomp('ASan is only supported on WASM backend') | ||
def test_pthread_asan_use_after_free(self): | ||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_asan_use_after_free.cpp'), expected='1', args=['-fsanitize=address', '-s', 'TOTAL_MEMORY=256MB', '-s', 'USE_PTHREADS', '-s', 'PROXY_TO_PTHREAD', '-std=c++11', '--pre-js', path_from_root('tests', 'pthread', 'test_pthread_asan_use_after_free.js')]) | ||
|
||
# Tests MAIN_THREAD_EM_ASM_INT() function call signatures. | ||
@no_wasm_backend('MAIN_THREAD_EM_ASM() not yet implemented in Wasm backend') | ||
def test_main_thread_em_asm_signatures(self): | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.