diff options
author | Alon Zakai <azakai@google.com> | 2020-03-27 17:25:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-27 17:25:49 -0700 |
commit | d595a45b66cbb4d59472d2954131ee1f4cf6ad8e (patch) | |
tree | aa4c8116f9d57d8b1018b77b1db7ad7e3018ccc4 /test/lld | |
parent | 9101f65c7b18ab607c472a3d50b52db66497402f (diff) | |
download | binaryen-d595a45b66cbb4d59472d2954131ee1f4cf6ad8e.tar.gz binaryen-d595a45b66cbb4d59472d2954131ee1f4cf6ad8e.tar.bz2 binaryen-d595a45b66cbb4d59472d2954131ee1f4cf6ad8e.zip |
Avoid fp$ access in MAIN_MODULES (#2704)
Depends on emscripten-core/emscripten#10741
which ensures that table indexes are unique. With that guarantee,
a main module can just add its function pointers into the table, and
use them based on that index. The loader will then see them in the
table and then give other modules the identical function pointer for
a function, ensuring function pointer equality.
This avoids calling fp$ functions during startup for the main
module's own functions (which are slow). We do still call fp$s
of things we import from outside, as we don't have anything to
put in the table for them, we depend on the loader for that.
I suspect this can also be done with SIDE_MODULES, but did not
want to try too much at once.
Diffstat (limited to 'test/lld')
-rw-r--r-- | test/lld/main_module_table.wat | 9 | ||||
-rw-r--r-- | test/lld/main_module_table.wat.out | 106 | ||||
-rw-r--r-- | test/lld/main_module_table_2.wat | 10 | ||||
-rw-r--r-- | test/lld/main_module_table_2.wat.out | 106 | ||||
-rw-r--r-- | test/lld/main_module_table_3.wat | 11 | ||||
-rw-r--r-- | test/lld/main_module_table_3.wat.out | 106 | ||||
-rw-r--r-- | test/lld/main_module_table_4.wat | 12 | ||||
-rw-r--r-- | test/lld/main_module_table_4.wat.out | 108 | ||||
-rw-r--r-- | test/lld/main_module_table_5.wat | 16 | ||||
-rw-r--r-- | test/lld/main_module_table_5.wat.out | 114 |
10 files changed, 598 insertions, 0 deletions
diff --git a/test/lld/main_module_table.wat b/test/lld/main_module_table.wat new file mode 100644 index 000000000..b63b4d8fe --- /dev/null +++ b/test/lld/main_module_table.wat @@ -0,0 +1,9 @@ +(module + (import "env" "__stack_pointer" (global $sp (mut i32))) + (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) + (global $global i32 (i32.const 42)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (func $__stdio_write + ) +) diff --git a/test/lld/main_module_table.wat.out b/test/lld/main_module_table.wat.out new file mode 100644 index 000000000..fd292809f --- /dev/null +++ b/test/lld/main_module_table.wat.out @@ -0,0 +1,106 @@ +(module + (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "__stack_pointer" (global $sp_import i32)) + (table $0 1 funcref) + (elem (i32.const 0) $__stdio_write) + (global $gimport$9 (mut i32) (i32.const 0)) + (global $global i32 (i32.const 42)) + (global $sp (mut i32) (global.get $sp_import)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (export "stackSave" (func $stackSave)) + (export "stackAlloc" (func $stackAlloc)) + (export "stackRestore" (func $stackRestore)) + (export "__growWasmMemory" (func $__growWasmMemory)) + (export "__assign_got_enties" (func $__assign_got_enties)) + (export "dynCall_v" (func $dynCall_v)) + (func $__stdio_write (; 0 ;) + (nop) + ) + (func $stackSave (; 1 ;) (result i32) + (global.get $sp) + ) + (func $stackAlloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (global.set $sp + (local.tee $1 + (i32.and + (i32.sub + (global.get $sp) + (local.get $0) + ) + (i32.const -16) + ) + ) + ) + (local.get $1) + ) + (func $stackRestore (; 3 ;) (param $0 i32) + (global.set $sp + (local.get $0) + ) + ) + (func $__growWasmMemory (; 4 ;) (param $newSize i32) (result i32) + (memory.grow + (local.get $newSize) + ) + ) + (func $__assign_got_enties (; 5 ;) + (global.set $gimport$9 + (i32.add + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $dynCall_v (; 6 ;) (param $fptr i32) + (call_indirect (type $none_=>_none) + (local.get $fptr) + ) + ) +) +(; +--BEGIN METADATA -- +{ + "staticBump": 4294966770, + "tableSize": 1, + "initializers": [ + "__assign_got_enties" + ], + "declares": [ + ], + "externs": [ + "___stack_pointer" + ], + "implementedFunctions": [ + "___stdio_write", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "___assign_got_enties", + "_dynCall_v" + ], + "exports": [ + "__stdio_write", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "__assign_got_enties", + "dynCall_v" + ], + "namedGlobals": { + "__data_end" : "42" + }, + "invokeFuncs": [ + ], + "features": [ + ], + "mainReadsParams": 0 +} +-- END METADATA -- +;) diff --git a/test/lld/main_module_table_2.wat b/test/lld/main_module_table_2.wat new file mode 100644 index 000000000..2ccc1fbcc --- /dev/null +++ b/test/lld/main_module_table_2.wat @@ -0,0 +1,10 @@ +(module + (import "env" "__stack_pointer" (global $sp (mut i32))) + (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) + (import "env" "table" (table $timport$9 1 funcref)) + (global $global i32 (i32.const 42)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (func $__stdio_write + ) +) diff --git a/test/lld/main_module_table_2.wat.out b/test/lld/main_module_table_2.wat.out new file mode 100644 index 000000000..92a40d5f2 --- /dev/null +++ b/test/lld/main_module_table_2.wat.out @@ -0,0 +1,106 @@ +(module + (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "table" (table $0 2 funcref)) + (elem (i32.const 0) $__stdio_write) + (import "env" "__stack_pointer" (global $sp_import i32)) + (global $gimport$9 (mut i32) (i32.const 0)) + (global $global i32 (i32.const 42)) + (global $sp (mut i32) (global.get $sp_import)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (export "stackSave" (func $stackSave)) + (export "stackAlloc" (func $stackAlloc)) + (export "stackRestore" (func $stackRestore)) + (export "__growWasmMemory" (func $__growWasmMemory)) + (export "__assign_got_enties" (func $__assign_got_enties)) + (export "dynCall_v" (func $dynCall_v)) + (func $__stdio_write (; 0 ;) + (nop) + ) + (func $stackSave (; 1 ;) (result i32) + (global.get $sp) + ) + (func $stackAlloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (global.set $sp + (local.tee $1 + (i32.and + (i32.sub + (global.get $sp) + (local.get $0) + ) + (i32.const -16) + ) + ) + ) + (local.get $1) + ) + (func $stackRestore (; 3 ;) (param $0 i32) + (global.set $sp + (local.get $0) + ) + ) + (func $__growWasmMemory (; 4 ;) (param $newSize i32) (result i32) + (memory.grow + (local.get $newSize) + ) + ) + (func $__assign_got_enties (; 5 ;) + (global.set $gimport$9 + (i32.add + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $dynCall_v (; 6 ;) (param $fptr i32) + (call_indirect (type $none_=>_none) + (local.get $fptr) + ) + ) +) +(; +--BEGIN METADATA -- +{ + "staticBump": 4294966770, + "tableSize": 2, + "initializers": [ + "__assign_got_enties" + ], + "declares": [ + ], + "externs": [ + "___stack_pointer" + ], + "implementedFunctions": [ + "___stdio_write", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "___assign_got_enties", + "_dynCall_v" + ], + "exports": [ + "__stdio_write", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "__assign_got_enties", + "dynCall_v" + ], + "namedGlobals": { + "__data_end" : "42" + }, + "invokeFuncs": [ + ], + "features": [ + ], + "mainReadsParams": 0 +} +-- END METADATA -- +;) diff --git a/test/lld/main_module_table_3.wat b/test/lld/main_module_table_3.wat new file mode 100644 index 000000000..2f7d92ebf --- /dev/null +++ b/test/lld/main_module_table_3.wat @@ -0,0 +1,11 @@ +(module + (import "env" "__stack_pointer" (global $sp (mut i32))) + (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) + (import "env" "table" (table $timport$9 1 funcref)) + (elem (i32.const 0)) + (global $global i32 (i32.const 42)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (func $__stdio_write + ) +) diff --git a/test/lld/main_module_table_3.wat.out b/test/lld/main_module_table_3.wat.out new file mode 100644 index 000000000..92a40d5f2 --- /dev/null +++ b/test/lld/main_module_table_3.wat.out @@ -0,0 +1,106 @@ +(module + (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "table" (table $0 2 funcref)) + (elem (i32.const 0) $__stdio_write) + (import "env" "__stack_pointer" (global $sp_import i32)) + (global $gimport$9 (mut i32) (i32.const 0)) + (global $global i32 (i32.const 42)) + (global $sp (mut i32) (global.get $sp_import)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (export "stackSave" (func $stackSave)) + (export "stackAlloc" (func $stackAlloc)) + (export "stackRestore" (func $stackRestore)) + (export "__growWasmMemory" (func $__growWasmMemory)) + (export "__assign_got_enties" (func $__assign_got_enties)) + (export "dynCall_v" (func $dynCall_v)) + (func $__stdio_write (; 0 ;) + (nop) + ) + (func $stackSave (; 1 ;) (result i32) + (global.get $sp) + ) + (func $stackAlloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (global.set $sp + (local.tee $1 + (i32.and + (i32.sub + (global.get $sp) + (local.get $0) + ) + (i32.const -16) + ) + ) + ) + (local.get $1) + ) + (func $stackRestore (; 3 ;) (param $0 i32) + (global.set $sp + (local.get $0) + ) + ) + (func $__growWasmMemory (; 4 ;) (param $newSize i32) (result i32) + (memory.grow + (local.get $newSize) + ) + ) + (func $__assign_got_enties (; 5 ;) + (global.set $gimport$9 + (i32.add + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $dynCall_v (; 6 ;) (param $fptr i32) + (call_indirect (type $none_=>_none) + (local.get $fptr) + ) + ) +) +(; +--BEGIN METADATA -- +{ + "staticBump": 4294966770, + "tableSize": 2, + "initializers": [ + "__assign_got_enties" + ], + "declares": [ + ], + "externs": [ + "___stack_pointer" + ], + "implementedFunctions": [ + "___stdio_write", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "___assign_got_enties", + "_dynCall_v" + ], + "exports": [ + "__stdio_write", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "__assign_got_enties", + "dynCall_v" + ], + "namedGlobals": { + "__data_end" : "42" + }, + "invokeFuncs": [ + ], + "features": [ + ], + "mainReadsParams": 0 +} +-- END METADATA -- +;) diff --git a/test/lld/main_module_table_4.wat b/test/lld/main_module_table_4.wat new file mode 100644 index 000000000..a991de4bb --- /dev/null +++ b/test/lld/main_module_table_4.wat @@ -0,0 +1,12 @@ +(module + (import "env" "__stack_pointer" (global $sp (mut i32))) + (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) + (import "env" "__table_base" (global $tb i32)) + (import "env" "table" (table $timport$9 1 funcref)) + (elem (global.get $tb)) + (global $global i32 (i32.const 42)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (func $__stdio_write + ) +) diff --git a/test/lld/main_module_table_4.wat.out b/test/lld/main_module_table_4.wat.out new file mode 100644 index 000000000..db2ef3cd8 --- /dev/null +++ b/test/lld/main_module_table_4.wat.out @@ -0,0 +1,108 @@ +(module + (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "table" (table $0 2 funcref)) + (elem (global.get $tb) $__stdio_write) + (import "env" "__stack_pointer" (global $sp_import i32)) + (import "env" "__table_base" (global $tb i32)) + (global $gimport$9 (mut i32) (i32.const 0)) + (global $global i32 (i32.const 42)) + (global $sp (mut i32) (global.get $sp_import)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (export "stackSave" (func $stackSave)) + (export "stackAlloc" (func $stackAlloc)) + (export "stackRestore" (func $stackRestore)) + (export "__growWasmMemory" (func $__growWasmMemory)) + (export "__assign_got_enties" (func $__assign_got_enties)) + (export "dynCall_v" (func $dynCall_v)) + (func $__stdio_write (; 0 ;) + (nop) + ) + (func $stackSave (; 1 ;) (result i32) + (global.get $sp) + ) + (func $stackAlloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (global.set $sp + (local.tee $1 + (i32.and + (i32.sub + (global.get $sp) + (local.get $0) + ) + (i32.const -16) + ) + ) + ) + (local.get $1) + ) + (func $stackRestore (; 3 ;) (param $0 i32) + (global.set $sp + (local.get $0) + ) + ) + (func $__growWasmMemory (; 4 ;) (param $newSize i32) (result i32) + (memory.grow + (local.get $newSize) + ) + ) + (func $__assign_got_enties (; 5 ;) + (global.set $gimport$9 + (i32.add + (global.get $tb) + (i32.const 0) + ) + ) + ) + (func $dynCall_v (; 6 ;) (param $fptr i32) + (call_indirect (type $none_=>_none) + (local.get $fptr) + ) + ) +) +(; +--BEGIN METADATA -- +{ + "staticBump": 4294966770, + "tableSize": 2, + "initializers": [ + "__assign_got_enties" + ], + "declares": [ + ], + "externs": [ + "___stack_pointer", + "___table_base" + ], + "implementedFunctions": [ + "___stdio_write", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "___assign_got_enties", + "_dynCall_v" + ], + "exports": [ + "__stdio_write", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "__assign_got_enties", + "dynCall_v" + ], + "namedGlobals": { + "__data_end" : "42" + }, + "invokeFuncs": [ + ], + "features": [ + ], + "mainReadsParams": 0 +} +-- END METADATA -- +;) diff --git a/test/lld/main_module_table_5.wat b/test/lld/main_module_table_5.wat new file mode 100644 index 000000000..ee15deee5 --- /dev/null +++ b/test/lld/main_module_table_5.wat @@ -0,0 +1,16 @@ +(module + (import "env" "__stack_pointer" (global $sp (mut i32))) + (import "GOT.func" "__stdio_write" (global $gimport$9 (mut i32))) + (import "env" "__table_base" (global $tb i32)) + (import "env" "table" (table $timport$9 1 funcref)) + (elem (global.get $tb) $other $stuff) + (global $global i32 (i32.const 42)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (func $__stdio_write + ) + (func $other + ) + (func $stuff + ) +) diff --git a/test/lld/main_module_table_5.wat.out b/test/lld/main_module_table_5.wat.out new file mode 100644 index 000000000..590164b0f --- /dev/null +++ b/test/lld/main_module_table_5.wat.out @@ -0,0 +1,114 @@ +(module + (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "table" (table $0 2 funcref)) + (elem (global.get $tb) $other $stuff $__stdio_write) + (import "env" "__stack_pointer" (global $sp_import i32)) + (import "env" "__table_base" (global $tb i32)) + (global $gimport$9 (mut i32) (i32.const 0)) + (global $global i32 (i32.const 42)) + (global $sp (mut i32) (global.get $sp_import)) + (export "__stdio_write" (func $__stdio_write)) + (export "__data_end" (global $global)) + (export "stackSave" (func $stackSave)) + (export "stackAlloc" (func $stackAlloc)) + (export "stackRestore" (func $stackRestore)) + (export "__growWasmMemory" (func $__growWasmMemory)) + (export "__assign_got_enties" (func $__assign_got_enties)) + (export "dynCall_v" (func $dynCall_v)) + (func $__stdio_write (; 0 ;) + (nop) + ) + (func $other (; 1 ;) + (nop) + ) + (func $stuff (; 2 ;) + (nop) + ) + (func $stackSave (; 3 ;) (result i32) + (global.get $sp) + ) + (func $stackAlloc (; 4 ;) (param $0 i32) (result i32) + (local $1 i32) + (global.set $sp + (local.tee $1 + (i32.and + (i32.sub + (global.get $sp) + (local.get $0) + ) + (i32.const -16) + ) + ) + ) + (local.get $1) + ) + (func $stackRestore (; 5 ;) (param $0 i32) + (global.set $sp + (local.get $0) + ) + ) + (func $__growWasmMemory (; 6 ;) (param $newSize i32) (result i32) + (memory.grow + (local.get $newSize) + ) + ) + (func $__assign_got_enties (; 7 ;) + (global.set $gimport$9 + (i32.add + (global.get $tb) + (i32.const 2) + ) + ) + ) + (func $dynCall_v (; 8 ;) (param $fptr i32) + (call_indirect (type $none_=>_none) + (local.get $fptr) + ) + ) +) +(; +--BEGIN METADATA -- +{ + "staticBump": 4294966770, + "tableSize": 2, + "initializers": [ + "__assign_got_enties" + ], + "declares": [ + ], + "externs": [ + "___stack_pointer", + "___table_base" + ], + "implementedFunctions": [ + "___stdio_write", + "_stackSave", + "_stackAlloc", + "_stackRestore", + "___growWasmMemory", + "___assign_got_enties", + "_dynCall_v" + ], + "exports": [ + "__stdio_write", + "stackSave", + "stackAlloc", + "stackRestore", + "__growWasmMemory", + "__assign_got_enties", + "dynCall_v" + ], + "namedGlobals": { + "__data_end" : "42" + }, + "invokeFuncs": [ + ], + "features": [ + ], + "mainReadsParams": 0 +} +-- END METADATA -- +;) |