diff options
author | Sam Clegg <sbc@chromium.org> | 2019-10-25 14:19:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-25 14:19:12 -0700 |
commit | 4f9151dec445abb901ae22d8d4db5c5ea8e4c528 (patch) | |
tree | f44ae7589260843095321db5f159aeb768921649 | |
parent | 8d19d00268a4b1af556008bea933ede869d8a757 (diff) | |
download | binaryen-4f9151dec445abb901ae22d8d4db5c5ea8e4c528.tar.gz binaryen-4f9151dec445abb901ae22d8d4db5c5ea8e4c528.tar.bz2 binaryen-4f9151dec445abb901ae22d8d4db5c5ea8e4c528.zip |
When renaming functions ensure the corresponding GOT.func entry is also renamed (#2382)
Fixes https://github.com/WebAssembly/binaryen/issues/2180
-rwxr-xr-x | scripts/test/generate_lld_tests.py | 3 | ||||
-rw-r--r-- | scripts/test/shared.py | 3 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 7 | ||||
-rw-r--r-- | test/lld/shared_longjmp.c | 16 | ||||
-rw-r--r-- | test/lld/shared_longjmp.wast | 144 | ||||
-rw-r--r-- | test/lld/shared_longjmp.wast.out | 213 |
6 files changed, 383 insertions, 3 deletions
diff --git a/scripts/test/generate_lld_tests.py b/scripts/test/generate_lld_tests.py index b5cb6b140..2279482eb 100755 --- a/scripts/test/generate_lld_tests.py +++ b/scripts/test/generate_lld_tests.py @@ -50,7 +50,8 @@ def generate_wast_files(llvm_bin, emscripten_root): compile_cmd = [ os.path.join(llvm_bin, 'clang'), src_path, '-o', obj_path, - '--target=wasm32-unknown-unknown-wasm', + '--target=wasm32-emscripten', + '-mllvm', '-enable-emscripten-sjlj', '-c', '-nostdinc', '-Xclang', '-nobuiltininc', diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 8d30ecaa0..f8d575656 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -43,7 +43,6 @@ def parse_args(args): action='store_false', help=('If set, the whole test suite will run to completion independent of' ' earlier errors.')) - parser.add_argument( '--interpreter', dest='interpreter', default='', help='Specifies the wasm interpreter executable to run tests on.') @@ -60,7 +59,7 @@ def parse_args(args): parser.add_argument( '--out-dir', dest='out_dir', default='', help=('Specifies a path to the output directory for temp files, which ' - 'is also where the test runner changes directory into.', + 'is also where the test runner changes directory into.' ' Default:. out/test under the binaryen root.')) parser.add_argument( '--valgrind', dest='valgrind', default='', diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 6710c7cd8..37cd2f431 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -1041,6 +1041,13 @@ struct FixInvokeFunctionNamesWalker wasm.removeFunction(importName); } ModuleUtils::renameFunctions(wasm, importRenames); + ImportInfo imports(wasm); + for (auto& pair : importRenames) { + // Update any associated GOT.func import. + if (auto g = imports.getImportedGlobal("GOT.func", pair.first)) { + g->base = pair.second; + } + } } }; diff --git a/test/lld/shared_longjmp.c b/test/lld/shared_longjmp.c new file mode 100644 index 000000000..52c1012c1 --- /dev/null +++ b/test/lld/shared_longjmp.c @@ -0,0 +1,16 @@ +typedef struct jmp_buf_buf { + int thing; +} jmp_buf; + +void longjmp(jmp_buf env, int val); +int setjmp(jmp_buf env); + +int __THREW__; +int __threwValue; + +void _start() { + jmp_buf jmp; + if (setjmp(jmp) == 0) { + longjmp(jmp, 1); + } +} diff --git a/test/lld/shared_longjmp.wast b/test/lld/shared_longjmp.wast new file mode 100644 index 000000000..235e1fadf --- /dev/null +++ b/test/lld/shared_longjmp.wast @@ -0,0 +1,144 @@ +(module + (type $0 (func (param i32) (result i32))) + (type $1 (func (param i32 i32 i32 i32) (result i32))) + (type $2 (func (result i32))) + (type $3 (func (param i32 i32))) + (type $4 (func (param i32 i32 i32))) + (type $5 (func (param i32 i32 i32) (result i32))) + (type $6 (func (param i32))) + (type $7 (func)) + (import "env" "memory" (memory $0 0)) + (data (global.get $gimport$2) "\00\00\00\00\00\00\00\00") + (import "env" "__indirect_function_table" (table $timport$1 0 funcref)) + (import "env" "__memory_base" (global $gimport$2 i32)) + (import "env" "__table_base" (global $gimport$3 i32)) + (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 $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 $__wasm_call_ctors)) + (export "_start" (func $_start)) + (export "__THREW__" (global $global$0)) + (export "__threwValue" (global $global$1)) + (func $__wasm_call_ctors (; 9 ;) (type $7) + (call $__wasm_apply_relocs) + ) + (func $__wasm_apply_relocs (; 10 ;) (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 $malloc + (i32.const 40) + ) + ) + (i32.const 0) + ) + (local.set $1 + (call $saveSetjmp + (local.get $0) + (i32.const 1) + (local.get $0) + (i32.const 4) + ) + ) + (local.set $2 + (call $getTempRet0) + ) + (local.set $0 + (i32.const 0) + ) + (block $label$1 + (block $label$2 + (loop $label$3 + (br_if $label$2 + (local.get $0) + ) + (i32.store + (local.tee $0 + (global.get $gimport$13) + ) + (i32.const 0) + ) + (call $__invoke_void_i32_i32 + (global.get $gimport$14) + (local.get $0) + (i32.const 1) + ) + (local.set $3 + (i32.load + (local.get $0) + ) + ) + (i32.store + (local.get $0) + (i32.const 0) + ) + (local.set $0 + (global.get $gimport$15) + ) + (block $label$4 + (br_if $label$4 + (i32.eqz + (local.get $3) + ) + ) + (br_if $label$4 + (i32.eqz + (local.tee $0 + (i32.load + (local.get $0) + ) + ) + ) + ) + (br_if $label$1 + (i32.eqz + (call $testSetjmp + (i32.load + (local.get $3) + ) + (local.get $1) + (local.get $2) + ) + ) + ) + (call $setTempRet0 + (local.get $0) + ) + ) + (local.set $0 + (call $getTempRet0) + ) + (br $label$3) + ) + ) + (call $free + (local.get $1) + ) + (return) + ) + (call $emscripten_longjmp + (local.get $3) + (local.get $0) + ) + (unreachable) + ) + ;; custom section "dylink", size 5 + ;; custom section "producers", size 112 +) + diff --git a/test/lld/shared_longjmp.wast.out b/test/lld/shared_longjmp.wast.out new file mode 100644 index 000000000..c6bdf1c17 --- /dev/null +++ b/test/lld/shared_longjmp.wast.out @@ -0,0 +1,213 @@ +(module + (type $0 (func (param i32) (result i32))) + (type $1 (func (param i32 i32 i32 i32) (result i32))) + (type $2 (func (result i32))) + (type $3 (func (param i32 i32))) + (type $4 (func (param i32 i32 i32))) + (type $5 (func (param i32 i32 i32) (result i32))) + (type $6 (func (param i32))) + (type $7 (func)) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$i (func (result i32))) + (import "env" "memory" (memory $0 0)) + (data (global.get $gimport$2) "\00\00\00\00\00\00\00\00") + (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 $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))) + (global $gimport$13 (mut i32) (i32.const 0)) + (global $gimport$14 (mut i32) (i32.const 0)) + (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 $_start)) + (export "__THREW__" (global $global$0)) + (export "__threwValue" (global $global$1)) + (export "dynCall_vii" (func $dynCall_vii)) + (export "__post_instantiate" (func $__post_instantiate)) + (func $__wasm_call_ctors (; 11 ;) (type $7) + (call $__wasm_apply_relocs) + ) + (func $__wasm_apply_relocs (; 12 ;) (type $7) + (nop) + ) + (func $_start (; 13 ;) (type $7) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (i32.store + (local.tee $0 + (call $malloc + (i32.const 40) + ) + ) + (i32.const 0) + ) + (local.set $1 + (call $saveSetjmp + (local.get $0) + (i32.const 1) + (local.get $0) + (i32.const 4) + ) + ) + (local.set $2 + (call $getTempRet0) + ) + (local.set $0 + (i32.const 0) + ) + (block $label$1 + (block $label$2 + (loop $label$3 + (br_if $label$2 + (local.get $0) + ) + (i32.store + (local.tee $0 + (global.get $gimport$13) + ) + (i32.const 0) + ) + (call $invoke_vii + (global.get $gimport$14) + (local.get $0) + (i32.const 1) + ) + (local.set $3 + (i32.load + (local.get $0) + ) + ) + (i32.store + (local.get $0) + (i32.const 0) + ) + (local.set $0 + (global.get $gimport$15) + ) + (block $label$4 + (br_if $label$4 + (i32.eqz + (local.get $3) + ) + ) + (br_if $label$4 + (i32.eqz + (local.tee $0 + (i32.load + (local.get $0) + ) + ) + ) + ) + (br_if $label$1 + (i32.eqz + (call $testSetjmp + (i32.load + (local.get $3) + ) + (local.get $1) + (local.get $2) + ) + ) + ) + (call $setTempRet0 + (local.get $0) + ) + ) + (local.set $0 + (call $getTempRet0) + ) + (br $label$3) + ) + ) + (call $free + (local.get $1) + ) + (return) + ) + (call $emscripten_longjmp + (local.get $3) + (local.get $0) + ) + (unreachable) + ) + (func $dynCall_vii (; 14 ;) (param $fptr i32) (param $0 i32) (param $1 i32) + (call_indirect (type $FUNCSIG$vii) + (local.get $0) + (local.get $1) + (local.get $fptr) + ) + ) + (func $__post_instantiate (; 15 ;) + (call $__assign_got_enties) + (call $__wasm_call_ctors) + ) + (func $__assign_got_enties (; 16 ;) + (global.set $gimport$13 + (call $g$__THREW__) + ) + (global.set $gimport$15 + (call $g$__threwValue) + ) + (global.set $gimport$14 + (call $fp$emscripten_longjmp$vii) + ) + ) +) +(; +--BEGIN METADATA -- +{ + "staticBump": 0, + "tableSize": 0, + "declares": [ + "malloc", + "saveSetjmp", + "getTempRet0", + "testSetjmp", + "setTempRet0", + "free", + "emscripten_longjmp", + "g$__THREW__", + "g$__threwValue", + "fp$emscripten_longjmp$vii" + ], + "externs": [ + "___memory_base", + "___table_base" + ], + "implementedFunctions": [ + "__start", + "_dynCall_vii", + "___post_instantiate" + ], + "exports": [ + "_start", + "dynCall_vii", + "__post_instantiate" + ], + "namedGlobals": { + "__THREW__" : "0", + "__threwValue" : "4" + }, + "invokeFuncs": [ + "invoke_vii" + ], + "features": [ + ], + "mainReadsParams": 0 +} +-- END METADATA -- +;) |