Skip to content

Commit 5d33d81

Browse files
committed
Add a GOT.func import test
1 parent 993fd52 commit 5d33d81

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

test/ld/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WASM_LD?=wasm-ld-10
1414
MO_LD?=../../src/mo-ld
1515

1616
_out/%.lib.o: %.c | _out
17-
$(WASM_CLANG) --compile -fpic --std=c11 --target=wasm32-unknown-unknown-wasm -fvisibility=hidden --optimize=3 \
17+
$(WASM_CLANG) --compile -fPIC --target=wasm32-unknown-emscripten --optimize=3 \
1818
-fno-builtin -Wall \
1919
$< --output $@
2020

@@ -30,7 +30,7 @@ _out/%.linked.wasm: _out/%.base.wasm _out/%.lib.wasm
3030
$(MO_LD) -b _out/$*.base.wasm -l _out/$*.lib.wasm -o _out/$*.linked.wasm
3131

3232
_out/%.wat: _out/%.wasm
33-
wasm2wat --no-check $< -o $@
33+
wasm2wat $< -o $@
3434

3535
_out/%.valid: _out/%.wasm
3636
wasm-validate $< > $@ 2>&1 || true

test/ld/fun-ptr.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__attribute__ ((visibility("default")))
2+
int f(int x, int y)
3+
{
4+
return x + y;
5+
}
6+
7+
__attribute__ ((visibility("default")))
8+
int (*exported(void)) (int x, int y)
9+
{
10+
return &f;
11+
}

test/ld/fun-ptr.wat

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(module
2+
(type (;0;) (func (result i32)))
3+
(type (;1;) (func (param i32) (param i32) (result i32)))
4+
(import "rts" "exported" (func $exported (result i32)))
5+
(table (;0;) 0 0 anyfunc)
6+
(memory (;0;) 2)
7+
(global $heap_base i32 (i32.const 65536))
8+
(export "__heap_base" (global $heap_base))
9+
(func $call_imported (type 0)
10+
call $exported
11+
i32.const 3
12+
i32.const 5
13+
call_indirect (type 1)
14+
)
15+
)

test/ld/ok/fun-ptr.linked.wat.ok

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(module
2+
(type (;0;) (func (result i32)))
3+
(type (;1;) (func (param i32 i32) (result i32)))
4+
(type (;2;) (func))
5+
(func $call_imported (type 0) (result i32)
6+
call $exported
7+
i32.const 3
8+
i32.const 5
9+
call_indirect (type 1))
10+
(func $__wasm_call_ctors (type 2)
11+
call $__wasm_apply_relocs)
12+
(func $__wasm_apply_relocs (type 2))
13+
(func $f (type 1) (param i32 i32) (result i32)
14+
local.get 1
15+
local.get 0
16+
i32.add)
17+
(func $exported (type 0) (result i32)
18+
global.get 1)
19+
(func $link_start (type 2)
20+
call $__wasm_call_ctors)
21+
(table (;0;) 1 1 funcref)
22+
(memory (;0;) 2)
23+
(global (;0;) i32 (i32.const 65536))
24+
(global (;1;) (mut i32) (i32.const 0))
25+
(start $link_start)
26+
(elem (i32.const 0) func $f))

0 commit comments

Comments
 (0)