-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asyncify: Support for new add-list, and updates for binaryen list cha…
…nges (#11438) Add support for the new ASYNCIFY_ADD_LIST, and update existing list names following the updates in Binaryen, so that now we have ASYNCIFY_ADD_LIST to add a function, ASYNCIFY_REMOVE_LIST to remove one (previously this was called ASYNCIFY_BLACKLIST), and ASYNCIFY_ONLY_LIST to set a list of the only functions to instrument and no others (previously this was called ASYNCIFY_WHITELIST). The updated lists also handle indirect calls properly, so that if you use ASYNCIFY_IGNORE_INDIRECT and then add (using either the add-list or the only-list) all the functions that are on the stack when pausing, then things will work (for more, see WebAssembly/binaryen#2913). A new test is added to show this.
- Loading branch information
Showing
11 changed files
with
118 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
File renamed without changes.
This file contains 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,33 @@ | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <emscripten.h> | ||
|
||
int x = 0; | ||
|
||
struct Structy { | ||
virtual int virty() { | ||
if (x == 1337) return virty(); // don't inline me | ||
emscripten_sleep(1); | ||
return 42; | ||
} | ||
}; | ||
|
||
Structy y; | ||
|
||
__attribute__((noinline)) | ||
void virt() { | ||
if (x == 1337) { | ||
// don't inline me | ||
virt(); | ||
} | ||
Structy *z = &y; | ||
printf("virt: %d\n", z->virty()); // but the indirect call itself! | ||
} | ||
|
||
int main() { | ||
EM_ASM({ | ||
Module.counter = (Module.counter || 0) + 1; | ||
if (Module.counter > 10) throw "infinite loop due to asyncify bug?"; | ||
}); | ||
virt(); | ||
} |
This file contains 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 @@ | ||
virt: 42 |
This file contains 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 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 |
---|---|---|
|
@@ -7862,22 +7862,22 @@ def test_asyncify_unused(self): | |
|
||
@parameterized({ | ||
'normal': ([], True), | ||
'blacklist_a': (['-s', 'ASYNCIFY_BLACKLIST=["foo(int, double)"]'], False), | ||
'blacklist_b': (['-s', 'ASYNCIFY_BLACKLIST=["bar()"]'], True), | ||
'blacklist_c': (['-s', 'ASYNCIFY_BLACKLIST=["baz()"]'], False), | ||
'whitelist_a': (['-s', 'ASYNCIFY_WHITELIST=["main","__original_main","foo(int, double)","baz()","c_baz","Structy::funcy()","bar()"]'], True), | ||
'whitelist_b': (['-s', 'ASYNCIFY_WHITELIST=["main","__original_main","foo(int, double)","baz()","c_baz","Structy::funcy()"]'], True), | ||
'whitelist_c': (['-s', 'ASYNCIFY_WHITELIST=["main","__original_main","foo(int, double)","baz()","c_baz"]'], False), | ||
'whitelist_d': (['-s', 'ASYNCIFY_WHITELIST=["foo(int, double)","baz()","c_baz","Structy::funcy()"]'], False), | ||
'whitelist_b_response': ([], True, '["main","__original_main","foo(int, double)","baz()","c_baz","Structy::funcy()"]'), | ||
'whitelist_c_response': ([], False, '["main","__original_main","foo(int, double)","baz()","c_baz"]'), | ||
'removelist_a': (['-s', 'ASYNCIFY_REMOVE_LIST=["foo(int, double)"]'], False), | ||
'removelist_b': (['-s', 'ASYNCIFY_REMOVE_LIST=["bar()"]'], True), | ||
'removelist_c': (['-s', 'ASYNCIFY_REMOVE_LIST=["baz()"]'], False), | ||
'onlylist_a': (['-s', 'ASYNCIFY_ONLY_LIST=["main","__original_main","foo(int, double)","baz()","c_baz","Structy::funcy()","bar()"]'], True), | ||
'onlylist_b': (['-s', 'ASYNCIFY_ONLY_LIST=["main","__original_main","foo(int, double)","baz()","c_baz","Structy::funcy()"]'], True), | ||
'onlylist_c': (['-s', 'ASYNCIFY_ONLY_LIST=["main","__original_main","foo(int, double)","baz()","c_baz"]'], False), | ||
'onlylist_d': (['-s', 'ASYNCIFY_ONLY_LIST=["foo(int, double)","baz()","c_baz","Structy::funcy()"]'], False), | ||
'onlylist_b_response': ([], True, '["main","__original_main","foo(int, double)","baz()","c_baz","Structy::funcy()"]'), | ||
'onlylist_c_response': ([], False, '["main","__original_main","foo(int, double)","baz()","c_baz"]'), | ||
}) | ||
@no_asan('asan is not compatible with asyncify stack operations; may also need to not instrument asan_c_load_4, TODO') | ||
@no_fastcomp('new asyncify only') | ||
def test_asyncify_lists(self, args, should_pass, response=None): | ||
if response is not None: | ||
create_test_file('response.file', response) | ||
self.emcc_args += ['-s', 'ASYNCIFY_WHITELIST[email protected]'] | ||
self.emcc_args += ['-s', 'ASYNCIFY_ONLY_LIST[email protected]'] | ||
self.set_setting('ASYNCIFY', 1) | ||
self.emcc_args += args | ||
try: | ||
|
@@ -7889,6 +7889,25 @@ def test_asyncify_lists(self, args, should_pass, response=None): | |
if should_pass: | ||
raise | ||
|
||
@parameterized({ | ||
'normal': ([], True), | ||
'ignoreindirect': (['-s', 'ASYNCIFY_IGNORE_INDIRECT'], False), | ||
'add': (['-s', 'ASYNCIFY_IGNORE_INDIRECT', '-s', 'ASYNCIFY_ADD_LIST=["main","virt()"]'], True), | ||
}) | ||
@no_asan('asan is not compatible with asyncify stack operations; may also need to not instrument asan_c_load_4, TODO') | ||
@no_fastcomp('new asyncify only') | ||
def test_asyncify_indirect_lists(self, args, should_pass): | ||
self.set_setting('ASYNCIFY', 1) | ||
self.emcc_args += args | ||
try: | ||
self.do_run_in_out_file_test('tests', 'core', 'test_asyncify_indirect_lists', assert_identical=True) | ||
if not should_pass: | ||
should_pass = True | ||
raise Exception('should not have passed') | ||
except Exception: | ||
if should_pass: | ||
raise | ||
|
||
@no_asan('asyncify stack operations confuse asan') | ||
@no_fastcomp('wasm-backend specific feature') | ||
def test_emscripten_scan_registers(self): | ||
|
This file contains 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 |
---|---|---|
|
@@ -8931,7 +8931,7 @@ def test_emcc_parsing(self): | |
|
||
@no_fastcomp('uses new ASYNCIFY') | ||
def test_asyncify_escaping(self): | ||
proc = run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'ASYNCIFY=1', '-s', "ASYNCIFY_WHITELIST=[DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)]"], stdout=PIPE, stderr=PIPE) | ||
proc = run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'ASYNCIFY=1', '-s', "ASYNCIFY_ONLY_LIST=[DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)]"], stdout=PIPE, stderr=PIPE) | ||
self.assertContained('emcc: ASYNCIFY list contains an item without balanced parentheses', proc.stderr) | ||
self.assertContained(' DOS_ReadFile(unsigned short', proc.stderr) | ||
self.assertContained('Try to quote the entire argument', proc.stderr) | ||
|
@@ -8943,10 +8943,10 @@ def test_asyncify_response_file(self): | |
"DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)" | ||
] | ||
''') | ||
proc = run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'ASYNCIFY=1', '-s', "ASYNCIFY_WHITELIST[email protected]"], stdout=PIPE, stderr=PIPE) | ||
proc = run_process([EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'ASYNCIFY=1', '-s', "ASYNCIFY_ONLY_LIST[email protected]"], stdout=PIPE, stderr=PIPE) | ||
# we should parse the response file properly, and then issue a proper warning for the missing function | ||
self.assertContained( | ||
'Asyncify whitelist contained a non-matching pattern: DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)', | ||
'Asyncify onlylist contained a non-matching pattern: DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)', | ||
proc.stderr) | ||
|
||
# Sockets and networking | ||
|