summaryrefslogtreecommitdiff
path: root/test/lld
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-03-31 15:20:50 -0700
committerGitHub <noreply@github.com>2020-03-31 15:20:50 -0700
commita32102c7dd7b321330c6cce4d0e3b16e7187a007 (patch)
treea704cc3a77fca9fbde7a2e05de4f2b0d2980a39f /test/lld
parentd8179402b3bb991f336b19bcca8ccbc60c842166 (diff)
downloadbinaryen-a32102c7dd7b321330c6cce4d0e3b16e7187a007.tar.gz
binaryen-a32102c7dd7b321330c6cce4d0e3b16e7187a007.tar.bz2
binaryen-a32102c7dd7b321330c6cce4d0e3b16e7187a007.zip
Avoid unnecessary fp$ in side modules (#2717)
Now that we update the dylink section properly, we can do the same optimization in side modules as in main ones: if the module provides a function, don't call an $fp method during startup, instead add it to the table ourselves and use the relative offset to the table base. Fix an issue when the table has no segments initially: the code just added an offset of 0, but that's not right. Instead, an a __table_base import and use that as the offset. As this is ABI-specific I did it on wasm-emscripten-finalize, leaving TableUtils to just assert on having a singleton segment. Add a test of a wasm file with a dylink section to the lld tests.
Diffstat (limited to 'test/lld')
-rw-r--r--test/lld/main_module_table.wat.out8
-rw-r--r--test/lld/main_module_table_2.wat.out8
-rw-r--r--test/lld/main_module_table_3.wat.out6
-rw-r--r--test/lld/shared.wat.out36
-rw-r--r--test/lld/shared_add_to_table.wasmbin0 -> 810 bytes
-rw-r--r--test/lld/shared_add_to_table.wasm.out144
6 files changed, 181 insertions, 21 deletions
diff --git a/test/lld/main_module_table.wat.out b/test/lld/main_module_table.wat.out
index fd292809f..412d1715f 100644
--- a/test/lld/main_module_table.wat.out
+++ b/test/lld/main_module_table.wat.out
@@ -4,8 +4,9 @@
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $none_=>_i32 (func (result i32)))
(import "env" "__stack_pointer" (global $sp_import i32))
+ (import "env" "__table_base" (global $__table_base i32))
(table $0 1 funcref)
- (elem (i32.const 0) $__stdio_write)
+ (elem (global.get $__table_base) $__stdio_write)
(global $gimport$9 (mut i32) (i32.const 0))
(global $global i32 (i32.const 42))
(global $sp (mut i32) (global.get $sp_import))
@@ -51,7 +52,7 @@
(func $__assign_got_enties (; 5 ;)
(global.set $gimport$9
(i32.add
- (i32.const 0)
+ (global.get $__table_base)
(i32.const 0)
)
)
@@ -73,7 +74,8 @@
"declares": [
],
"externs": [
- "___stack_pointer"
+ "___stack_pointer",
+ "___table_base"
],
"implementedFunctions": [
"___stdio_write",
diff --git a/test/lld/main_module_table_2.wat.out b/test/lld/main_module_table_2.wat.out
index 92a40d5f2..1dd833150 100644
--- a/test/lld/main_module_table_2.wat.out
+++ b/test/lld/main_module_table_2.wat.out
@@ -4,8 +4,9 @@
(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)
+ (elem (global.get $__table_base) $__stdio_write)
(import "env" "__stack_pointer" (global $sp_import i32))
+ (import "env" "__table_base" (global $__table_base i32))
(global $gimport$9 (mut i32) (i32.const 0))
(global $global i32 (i32.const 42))
(global $sp (mut i32) (global.get $sp_import))
@@ -51,7 +52,7 @@
(func $__assign_got_enties (; 5 ;)
(global.set $gimport$9
(i32.add
- (i32.const 0)
+ (global.get $__table_base)
(i32.const 0)
)
)
@@ -73,7 +74,8 @@
"declares": [
],
"externs": [
- "___stack_pointer"
+ "___stack_pointer",
+ "___table_base"
],
"implementedFunctions": [
"___stdio_write",
diff --git a/test/lld/main_module_table_3.wat.out b/test/lld/main_module_table_3.wat.out
index 92a40d5f2..f48ab6216 100644
--- a/test/lld/main_module_table_3.wat.out
+++ b/test/lld/main_module_table_3.wat.out
@@ -6,6 +6,7 @@
(import "env" "table" (table $0 2 funcref))
(elem (i32.const 0) $__stdio_write)
(import "env" "__stack_pointer" (global $sp_import i32))
+ (import "env" "__table_base" (global $__table_base i32))
(global $gimport$9 (mut i32) (i32.const 0))
(global $global i32 (i32.const 42))
(global $sp (mut i32) (global.get $sp_import))
@@ -51,7 +52,7 @@
(func $__assign_got_enties (; 5 ;)
(global.set $gimport$9
(i32.add
- (i32.const 0)
+ (global.get $__table_base)
(i32.const 0)
)
)
@@ -73,7 +74,8 @@
"declares": [
],
"externs": [
- "___stack_pointer"
+ "___stack_pointer",
+ "___table_base"
],
"implementedFunctions": [
"___stdio_write",
diff --git a/test/lld/shared.wat.out b/test/lld/shared.wat.out
index 5cc1cf88f..64f97b984 100644
--- a/test/lld/shared.wat.out
+++ b/test/lld/shared.wat.out
@@ -4,13 +4,13 @@
(type $i32_=>_i32 (func (param i32) (result i32)))
(import "env" "memory" (memory $0 0))
(data (global.get $gimport$2) "Hello, world\00\00\00\00\00\00\00\00\00\00\00\00")
- (import "env" "table" (table $0 0 funcref))
+ (import "env" "table" (table $0 1 funcref))
+ (elem (global.get $gimport$3) $print_message\28\29)
(import "env" "__memory_base" (global $gimport$2 i32))
(import "env" "__table_base" (global $gimport$3 i32))
(import "env" "puts" (func $puts (param i32) (result i32)))
(import "env" "g$external_var" (func $g$external_var (result i32)))
(import "env" "fp$puts$ii" (func $fp$puts$ii (result i32)))
- (import "env" "fp$_Z13print_messagev$i" (func $fp$_Z13print_messagev$i (result i32)))
(global $gimport$5 (mut i32) (i32.const 0))
(global $gimport$6 (mut i32) (i32.const 0))
(global $gimport$7 (mut i32) (i32.const 0))
@@ -20,10 +20,11 @@
(export "ptr_puts" (global $global$0))
(export "ptr_local_func" (global $global$1))
(export "__post_instantiate" (func $__post_instantiate))
- (func $__wasm_call_ctors (; 4 ;)
+ (export "dynCall_i" (func $dynCall_i))
+ (func $__wasm_call_ctors (; 3 ;)
(call $__wasm_apply_relocs)
)
- (func $__wasm_apply_relocs (; 5 ;)
+ (func $__wasm_apply_relocs (; 4 ;)
(i32.store
(i32.add
(global.get $gimport$2)
@@ -39,7 +40,7 @@
(global.get $gimport$7)
)
)
- (func $print_message\28\29 (; 6 ;) (result i32)
+ (func $print_message\28\29 (; 5 ;) (result i32)
(drop
(call $puts
(i32.add
@@ -52,11 +53,11 @@
(global.get $gimport$5)
)
)
- (func $__post_instantiate (; 7 ;)
+ (func $__post_instantiate (; 6 ;)
(call $__assign_got_enties)
(call $__wasm_call_ctors)
)
- (func $__assign_got_enties (; 8 ;)
+ (func $__assign_got_enties (; 7 ;)
(global.set $gimport$5
(call $g$external_var)
)
@@ -64,7 +65,15 @@
(call $fp$puts$ii)
)
(global.set $gimport$7
- (call $fp$_Z13print_messagev$i)
+ (i32.add
+ (global.get $gimport$3)
+ (i32.const 0)
+ )
+ )
+ )
+ (func $dynCall_i (; 8 ;) (param $fptr i32) (result i32)
+ (call_indirect (type $none_=>_i32)
+ (local.get $fptr)
)
)
)
@@ -72,12 +81,11 @@
--BEGIN METADATA --
{
"staticBump": 0,
- "tableSize": 0,
+ "tableSize": 1,
"declares": [
"puts",
"g$external_var",
- "fp$puts$ii",
- "fp$_Z13print_messagev$i"
+ "fp$puts$ii"
],
"externs": [
"___memory_base",
@@ -85,11 +93,13 @@
],
"implementedFunctions": [
"__Z13print_messagev",
- "___post_instantiate"
+ "___post_instantiate",
+ "_dynCall_i"
],
"exports": [
"_Z13print_messagev",
- "__post_instantiate"
+ "__post_instantiate",
+ "dynCall_i"
],
"namedGlobals": {
"ptr_puts" : "16",
diff --git a/test/lld/shared_add_to_table.wasm b/test/lld/shared_add_to_table.wasm
new file mode 100644
index 000000000..00ea9f906
--- /dev/null
+++ b/test/lld/shared_add_to_table.wasm
Binary files differ
diff --git a/test/lld/shared_add_to_table.wasm.out b/test/lld/shared_add_to_table.wasm.out
new file mode 100644
index 000000000..c561a89d3
--- /dev/null
+++ b/test/lld/shared_add_to_table.wasm.out
@@ -0,0 +1,144 @@
+(module
+ (type $none_=>_none (func))
+ (type $none_=>_i32 (func (result i32)))
+ (type $i32_=>_i32 (func (param i32) (result i32)))
+ (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
+ (import "env" "memory" (memory $0 0))
+ (data (global.get $gimport$3) "*\00\00\00")
+ (import "env" "table" (table $timport$1 1 funcref))
+ (elem (global.get $gimport$4) $waka_func_mine\28int\29)
+ (import "env" "__memory_base" (global $gimport$3 i32))
+ (import "env" "__table_base" (global $gimport$4 i32))
+ (import "env" "_Z16waka_func_theirsi" (func $waka_func_theirs\28int\29 (param i32) (result i32)))
+ (import "env" "g$waka_mine" (func $g$waka_mine (result i32)))
+ (import "env" "g$waka_others" (func $g$waka_others (result i32)))
+ (import "env" "fp$_Z16waka_func_theirsi$ii" (func $fp$_Z16waka_func_theirsi$ii (result i32)))
+ (global $gimport$6 (mut i32) (i32.const 0))
+ (global $gimport$7 (mut i32) (i32.const 0))
+ (global $gimport$8 (mut i32) (i32.const 0))
+ (global $gimport$9 (mut i32) (i32.const 0))
+ (global $global$0 i32 (i32.const 0))
+ (global $global$1 i32 (i32.const 0))
+ (export "__wasm_apply_relocs" (func $__wasm_apply_relocs))
+ (export "_Z14waka_func_minei" (func $waka_func_mine\28int\29))
+ (export "__original_main" (func $__original_main))
+ (export "waka_mine" (global $global$0))
+ (export "main" (func $main))
+ (export "__dso_handle" (global $global$1))
+ (export "__post_instantiate" (func $__post_instantiate))
+ (export "dynCall_ii" (func $dynCall_ii))
+ (func $__wasm_call_ctors (; 4 ;)
+ (call $__wasm_apply_relocs)
+ )
+ (func $__wasm_apply_relocs (; 5 ;)
+ )
+ (func $waka_func_mine\28int\29 (; 6 ;) (param $0 i32) (result i32)
+ (i32.add
+ (local.get $0)
+ (i32.const 1)
+ )
+ )
+ (func $__original_main (; 7 ;) (result i32)
+ (local $0 i32)
+ (local $1 i32)
+ (local.set $0
+ (global.get $gimport$6)
+ )
+ (local.set $1
+ (global.get $gimport$7)
+ )
+ (i32.add
+ (i32.add
+ (i32.load
+ (global.get $gimport$8)
+ )
+ (i32.add
+ (local.get $1)
+ (local.get $0)
+ )
+ )
+ (i32.load
+ (global.get $gimport$9)
+ )
+ )
+ )
+ (func $main (; 8 ;) (param $0 i32) (param $1 i32) (result i32)
+ (call $__original_main)
+ )
+ (func $__post_instantiate (; 9 ;)
+ (call $__assign_got_enties)
+ (call $__wasm_call_ctors)
+ )
+ (func $__assign_got_enties (; 10 ;)
+ (global.set $gimport$8
+ (call $g$waka_mine)
+ )
+ (global.set $gimport$9
+ (call $g$waka_others)
+ )
+ (global.set $gimport$6
+ (call $fp$_Z16waka_func_theirsi$ii)
+ )
+ (global.set $gimport$7
+ (i32.add
+ (global.get $gimport$4)
+ (i32.const 0)
+ )
+ )
+ )
+ (func $dynCall_ii (; 11 ;) (param $fptr i32) (param $0 i32) (result i32)
+ (call_indirect (type $i32_=>_i32)
+ (local.get $0)
+ (local.get $fptr)
+ )
+ )
+ ;; dylink section
+ ;; memorysize: 4
+ ;; memoryalignment: 2
+ ;; tablesize: 1
+ ;; tablealignment: 0
+ ;; custom section "producers", size 157
+)
+(;
+--BEGIN METADATA --
+{
+ "staticBump": 0,
+ "tableSize": 1,
+ "declares": [
+ "_Z16waka_func_theirsi",
+ "g$waka_mine",
+ "g$waka_others",
+ "fp$_Z16waka_func_theirsi$ii"
+ ],
+ "externs": [
+ "___memory_base",
+ "___table_base"
+ ],
+ "implementedFunctions": [
+ "___wasm_apply_relocs",
+ "__Z14waka_func_minei",
+ "___original_main",
+ "_main",
+ "___post_instantiate",
+ "_dynCall_ii"
+ ],
+ "exports": [
+ "__wasm_apply_relocs",
+ "_Z14waka_func_minei",
+ "__original_main",
+ "main",
+ "__post_instantiate",
+ "dynCall_ii"
+ ],
+ "namedGlobals": {
+ "waka_mine" : "0",
+ "__dso_handle" : "0"
+ },
+ "invokeFuncs": [
+ ],
+ "features": [
+ ],
+ "mainReadsParams": 0
+}
+-- END METADATA --
+;)