summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-12-19 10:58:06 -0800
committerGitHub <noreply@github.com>2019-12-19 10:58:06 -0800
commit81c16df401347e8e067fe9ccf0c26ae532bc03d5 (patch)
tree87ca0baff5fdc5f6efb2a0031c5cd64b33075258
parent4d28d3f32e7f213e300b24bc61c3f0ac9d6e1ab6 (diff)
downloadbinaryen-81c16df401347e8e067fe9ccf0c26ae532bc03d5.tar.gz
binaryen-81c16df401347e8e067fe9ccf0c26ae532bc03d5.tar.bz2
binaryen-81c16df401347e8e067fe9ccf0c26ae532bc03d5.zip
Revert "Fix renaming in FixInvokeFunctionNamesWalker (#2513)" (#2541)
This reverts commit f0a2e2c75c7bb3008f10b6edbb8dc4cfd27b7d28.
-rwxr-xr-xscripts/test/generate_lld_tests.py16
-rw-r--r--scripts/test/shared.py7
-rw-r--r--src/wasm/wasm-emscripten.cpp21
-rw-r--r--test/lld/shared_longjmp.wat48
-rw-r--r--test/lld/shared_longjmp.wat.out46
5 files changed, 65 insertions, 73 deletions
diff --git a/scripts/test/generate_lld_tests.py b/scripts/test/generate_lld_tests.py
index 005e09f15..64fcff2ac 100755
--- a/scripts/test/generate_lld_tests.py
+++ b/scripts/test/generate_lld_tests.py
@@ -30,8 +30,8 @@ def files_with_extensions(path, extensions):
yield file, ext
-def generate_wat_files(llvm_bin, emscripten_root):
- print('\n[ building wat files from C sources... ]\n')
+def generate_wast_files(llvm_bin, emscripten_root):
+ print('\n[ building wast files from C sources... ]\n')
lld_path = os.path.join(shared.options.binaryen_test, 'lld')
for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']):
@@ -42,11 +42,11 @@ def generate_wat_files(llvm_bin, emscripten_root):
obj_path = os.path.join(lld_path, obj_file)
wasm_file = src_file.replace(ext, '.wasm')
- wat_file = src_file.replace(ext, '.wat')
+ wast_file = src_file.replace(ext, '.wast')
obj_path = os.path.join(lld_path, obj_file)
wasm_path = os.path.join(lld_path, wasm_file)
- wat_path = os.path.join(lld_path, wat_file)
+ wast_path = os.path.join(lld_path, wast_file)
is_shared = 'shared' in src_file
compile_cmd = [
@@ -70,10 +70,6 @@ def generate_wat_files(llvm_bin, emscripten_root):
'--export', '__data_end',
'--global-base=568',
]
- # We had a regression where this test only worked if debug names
- # were included.
- if 'shared_longjmp' in src_file:
- link_cmd.append('--strip-debug')
if is_shared:
compile_cmd.append('-fPIC')
compile_cmd.append('-fvisibility=default')
@@ -84,7 +80,7 @@ def generate_wat_files(llvm_bin, emscripten_root):
try:
support.run_command(compile_cmd)
support.run_command(link_cmd)
- support.run_command(shared.WASM_DIS + [wasm_path, '-o', wat_path])
+ support.run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path])
finally:
# Don't need the .o or .wasm files, don't leave them around
shared.delete_from_orbit(obj_path)
@@ -95,4 +91,4 @@ if __name__ == '__main__':
if len(shared.options.positional_args) != 2:
print('Usage: generate_lld_tests.py [llvm/bin/dir] [path/to/emscripten]')
sys.exit(1)
- generate_wat_files(*shared.options.positional_args)
+ generate_wast_files(*shared.options.positional_args)
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 44a8dcc52..1ec42bc59 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -87,7 +87,6 @@ def parse_args(args):
options = parse_args(sys.argv[1:])
requested = options.positional_args
-script_dir = os.path.dirname(os.path.abspath(__file__))
num_failures = 0
warnings = []
@@ -124,7 +123,8 @@ if not any(os.path.isfile(os.path.join(options.binaryen_bin, f))
# Locate Binaryen source directory if not specified.
if not options.binaryen_root:
- options.binaryen_root = os.path.dirname(os.path.dirname(script_dir))
+ path_parts = os.path.abspath(__file__).split(os.path.sep)
+ options.binaryen_root = os.path.sep.join(path_parts[:-3])
options.binaryen_test = os.path.join(options.binaryen_root, 'test')
@@ -207,7 +207,8 @@ if options.valgrind:
def in_binaryen(*args):
- return os.path.join(options.binaryen_root, *args)
+ __rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
+ return os.path.join(__rootpath__, *args)
os.environ['BINARYEN'] = in_binaryen()
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index ae7e7f871..f069e558d 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -996,9 +996,8 @@ struct FixInvokeFunctionNamesWalker
std::vector<Name> toRemove;
std::set<Name> newImports;
std::set<Signature> invokeSigs;
- ImportInfo imports;
- FixInvokeFunctionNamesWalker(Module& _wasm) : wasm(_wasm), imports(wasm) {}
+ FixInvokeFunctionNamesWalker(Module& _wasm) : wasm(_wasm) {}
// Converts invoke wrapper names generated by LLVM backend to real invoke
// wrapper names that are expected by JavaScript glue code.
@@ -1053,18 +1052,15 @@ struct FixInvokeFunctionNamesWalker
return;
}
- BYN_TRACE("renaming import: " << curr->module << "." << curr->base << " ("
- << curr->name << ") -> " << newname << "\n");
- assert(importRenames.count(curr->base) == 0);
- importRenames[curr->base] = newname;
+ assert(importRenames.count(curr->name) == 0);
+ BYN_TRACE("renaming: " << curr->name << " -> " << newname << "\n");
+ importRenames[curr->name] = newname;
// Either rename or remove the existing import
- if (imports.getImportedFunction(curr->module, newname) ||
- !newImports.insert(newname).second) {
- BYN_TRACE("using existing import\n");
+ if (wasm.getFunctionOrNull(newname) || !newImports.insert(newname).second) {
toRemove.push_back(curr->name);
} else {
- BYN_TRACE("renaming import\n");
curr->base = newname;
+ curr->name = newname;
}
}
@@ -1073,11 +1069,10 @@ struct FixInvokeFunctionNamesWalker
wasm.removeFunction(importName);
}
ModuleUtils::renameFunctions(wasm, importRenames);
- // Update any associated GOT.func imports.
+ ImportInfo imports(wasm);
for (auto& pair : importRenames) {
+ // Update any associated GOT.func import.
if (auto g = imports.getImportedGlobal("GOT.func", pair.first)) {
- BYN_TRACE("renaming corresponding GOT entry: " << g->base << " -> "
- << pair.second << "\n");
g->base = pair.second;
}
}
diff --git a/test/lld/shared_longjmp.wat b/test/lld/shared_longjmp.wat
index b5179676c..235e1fadf 100644
--- a/test/lld/shared_longjmp.wat
+++ b/test/lld/shared_longjmp.wat
@@ -15,41 +15,41 @@
(import "GOT.mem" "__THREW__" (global $gimport$13 (mut i32)))
(import "GOT.func" "emscripten_longjmp_jmpbuf" (global $gimport$14 (mut i32)))
(import "GOT.mem" "__threwValue" (global $gimport$15 (mut i32)))
- (import "env" "malloc" (func $fimport$4 (param i32) (result i32)))
- (import "env" "saveSetjmp" (func $fimport$5 (param i32 i32 i32 i32) (result i32)))
- (import "env" "getTempRet0" (func $fimport$6 (result i32)))
- (import "env" "emscripten_longjmp_jmpbuf" (func $fimport$7 (param i32 i32)))
- (import "env" "__invoke_void_i32_i32" (func $fimport$8 (param i32 i32 i32)))
- (import "env" "testSetjmp" (func $fimport$9 (param i32 i32 i32) (result i32)))
- (import "env" "setTempRet0" (func $fimport$10 (param i32)))
- (import "env" "free" (func $fimport$11 (param i32)))
- (import "env" "emscripten_longjmp" (func $fimport$12 (param i32 i32)))
+ (import "env" "malloc" (func $malloc (param i32) (result i32)))
+ (import "env" "saveSetjmp" (func $saveSetjmp (param i32 i32 i32 i32) (result i32)))
+ (import "env" "getTempRet0" (func $getTempRet0 (result i32)))
+ (import "env" "emscripten_longjmp_jmpbuf" (func $emscripten_longjmp_jmpbuf (param i32 i32)))
+ (import "env" "__invoke_void_i32_i32" (func $__invoke_void_i32_i32 (param i32 i32 i32)))
+ (import "env" "testSetjmp" (func $testSetjmp (param i32 i32 i32) (result i32)))
+ (import "env" "setTempRet0" (func $setTempRet0 (param i32)))
+ (import "env" "free" (func $free (param i32)))
+ (import "env" "emscripten_longjmp" (func $emscripten_longjmp (param i32 i32)))
(global $global$0 i32 (i32.const 0))
(global $global$1 i32 (i32.const 4))
- (export "__wasm_call_ctors" (func $0))
- (export "_start" (func $2))
+ (export "__wasm_call_ctors" (func $__wasm_call_ctors))
+ (export "_start" (func $_start))
(export "__THREW__" (global $global$0))
(export "__threwValue" (global $global$1))
- (func $0 (; 9 ;) (type $7)
- (call $1)
+ (func $__wasm_call_ctors (; 9 ;) (type $7)
+ (call $__wasm_apply_relocs)
)
- (func $1 (; 10 ;) (type $7)
+ (func $__wasm_apply_relocs (; 10 ;) (type $7)
)
- (func $2 (; 11 ;) (type $7)
+ (func $_start (; 11 ;) (type $7)
(local $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(i32.store
(local.tee $0
- (call $fimport$4
+ (call $malloc
(i32.const 40)
)
)
(i32.const 0)
)
(local.set $1
- (call $fimport$5
+ (call $saveSetjmp
(local.get $0)
(i32.const 1)
(local.get $0)
@@ -57,7 +57,7 @@
)
)
(local.set $2
- (call $fimport$6)
+ (call $getTempRet0)
)
(local.set $0
(i32.const 0)
@@ -74,7 +74,7 @@
)
(i32.const 0)
)
- (call $fimport$8
+ (call $__invoke_void_i32_i32
(global.get $gimport$14)
(local.get $0)
(i32.const 1)
@@ -108,7 +108,7 @@
)
(br_if $label$1
(i32.eqz
- (call $fimport$9
+ (call $testSetjmp
(i32.load
(local.get $3)
)
@@ -117,22 +117,22 @@
)
)
)
- (call $fimport$10
+ (call $setTempRet0
(local.get $0)
)
)
(local.set $0
- (call $fimport$6)
+ (call $getTempRet0)
)
(br $label$3)
)
)
- (call $fimport$11
+ (call $free
(local.get $1)
)
(return)
)
- (call $fimport$12
+ (call $emscripten_longjmp
(local.get $3)
(local.get $0)
)
diff --git a/test/lld/shared_longjmp.wat.out b/test/lld/shared_longjmp.wat.out
index 871e26b27..083fcb3cc 100644
--- a/test/lld/shared_longjmp.wat.out
+++ b/test/lld/shared_longjmp.wat.out
@@ -12,14 +12,14 @@
(import "env" "table" (table $0 0 funcref))
(import "env" "__memory_base" (global $gimport$2 i32))
(import "env" "__table_base" (global $gimport$3 i32))
- (import "env" "malloc" (func $fimport$4 (param i32) (result i32)))
- (import "env" "saveSetjmp" (func $fimport$5 (param i32 i32 i32 i32) (result i32)))
- (import "env" "getTempRet0" (func $fimport$6 (result i32)))
- (import "env" "invoke_vii" (func $fimport$8 (param i32 i32 i32)))
- (import "env" "testSetjmp" (func $fimport$9 (param i32 i32 i32) (result i32)))
- (import "env" "setTempRet0" (func $fimport$10 (param i32)))
- (import "env" "free" (func $fimport$11 (param i32)))
- (import "env" "emscripten_longjmp" (func $fimport$12 (param i32 i32)))
+ (import "env" "malloc" (func $malloc (param i32) (result i32)))
+ (import "env" "saveSetjmp" (func $saveSetjmp (param i32 i32 i32 i32) (result i32)))
+ (import "env" "getTempRet0" (func $getTempRet0 (result i32)))
+ (import "env" "invoke_vii" (func $invoke_vii (param i32 i32 i32)))
+ (import "env" "testSetjmp" (func $testSetjmp (param i32 i32 i32) (result i32)))
+ (import "env" "setTempRet0" (func $setTempRet0 (param i32)))
+ (import "env" "free" (func $free (param i32)))
+ (import "env" "emscripten_longjmp" (func $emscripten_longjmp (param i32 i32)))
(import "env" "g$__THREW__" (func $g$__THREW__ (result i32)))
(import "env" "g$__threwValue" (func $g$__threwValue (result i32)))
(import "env" "fp$emscripten_longjmp$vii" (func $fp$emscripten_longjmp$vii (result i32)))
@@ -28,32 +28,32 @@
(global $gimport$15 (mut i32) (i32.const 0))
(global $global$0 i32 (i32.const 0))
(global $global$1 i32 (i32.const 4))
- (export "_start" (func $2))
+ (export "_start" (func $_start))
(export "__THREW__" (global $global$0))
(export "__threwValue" (global $global$1))
(export "dynCall_vii" (func $dynCall_vii))
(export "__post_instantiate" (func $__post_instantiate))
- (func $0 (; 11 ;)
- (call $1)
+ (func $__wasm_call_ctors (; 11 ;)
+ (call $__wasm_apply_relocs)
)
- (func $1 (; 12 ;)
+ (func $__wasm_apply_relocs (; 12 ;)
(nop)
)
- (func $2 (; 13 ;)
+ (func $_start (; 13 ;)
(local $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(i32.store
(local.tee $0
- (call $fimport$4
+ (call $malloc
(i32.const 40)
)
)
(i32.const 0)
)
(local.set $1
- (call $fimport$5
+ (call $saveSetjmp
(local.get $0)
(i32.const 1)
(local.get $0)
@@ -61,7 +61,7 @@
)
)
(local.set $2
- (call $fimport$6)
+ (call $getTempRet0)
)
(local.set $0
(i32.const 0)
@@ -78,7 +78,7 @@
)
(i32.const 0)
)
- (call $fimport$8
+ (call $invoke_vii
(global.get $gimport$14)
(local.get $0)
(i32.const 1)
@@ -112,7 +112,7 @@
)
(br_if $label$1
(i32.eqz
- (call $fimport$9
+ (call $testSetjmp
(i32.load
(local.get $3)
)
@@ -121,22 +121,22 @@
)
)
)
- (call $fimport$10
+ (call $setTempRet0
(local.get $0)
)
)
(local.set $0
- (call $fimport$6)
+ (call $getTempRet0)
)
(br $label$3)
)
)
- (call $fimport$11
+ (call $free
(local.get $1)
)
(return)
)
- (call $fimport$12
+ (call $emscripten_longjmp
(local.get $3)
(local.get $0)
)
@@ -151,7 +151,7 @@
)
(func $__post_instantiate (; 15 ;)
(call $__assign_got_enties)
- (call $0)
+ (call $__wasm_call_ctors)
)
(func $__assign_got_enties (; 16 ;)
(global.set $gimport$13