2018-08-14 09:23:54 +08:00
|
|
|
; RUN: llc -filetype=obj %s -o %t.o
|
2020-05-21 12:35:18 +08:00
|
|
|
; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/call-indirect.s -o %t2.o
|
2018-09-28 05:06:25 +08:00
|
|
|
; RUN: wasm-ld --export-dynamic -o %t.wasm %t2.o %t.o
|
2017-11-18 02:14:09 +08:00
|
|
|
; RUN: obj2yaml %t.wasm | FileCheck %s
|
|
|
|
|
|
|
|
; bitcode generated from the following C code:
|
|
|
|
; int foo(void) { return 1; }
|
|
|
|
; int (*indirect_func)(void) = &foo;
|
|
|
|
; void _start(void) { indirect_func(); }
|
|
|
|
|
2018-05-11 01:59:41 +08:00
|
|
|
target triple = "wasm32-unknown-unknown"
|
2018-01-24 11:29:47 +08:00
|
|
|
|
2017-12-03 10:38:04 +08:00
|
|
|
@indirect_func = local_unnamed_addr global i32 ()* @foo, align 4
|
2017-11-18 02:14:09 +08:00
|
|
|
|
|
|
|
; Function Attrs: norecurse nounwind readnone
|
2017-12-03 10:38:04 +08:00
|
|
|
define i32 @foo() #0 {
|
2017-11-18 02:14:09 +08:00
|
|
|
entry:
|
2017-12-12 08:22:21 +08:00
|
|
|
ret i32 2
|
2017-11-18 02:14:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; Function Attrs: nounwind
|
2018-02-02 08:30:03 +08:00
|
|
|
define void @_start() local_unnamed_addr #1 {
|
2017-11-18 02:14:09 +08:00
|
|
|
entry:
|
|
|
|
%0 = load i32 ()*, i32 ()** @indirect_func, align 4
|
2017-12-20 09:17:45 +08:00
|
|
|
%call = call i32 %0() #2
|
2018-02-02 08:30:03 +08:00
|
|
|
ret void
|
2017-11-18 02:14:09 +08:00
|
|
|
}
|
|
|
|
|
2017-12-20 09:17:45 +08:00
|
|
|
; Indirect function call where no function actually has this type.
|
|
|
|
; Ensures that the type entry is still created in this case.
|
|
|
|
define void @call_ptr(i64 (i64)* %arg) {
|
|
|
|
%1 = call i64 %arg(i64 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK: !WASM
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: FileHeader:
|
2020-11-18 16:59:49 +08:00
|
|
|
; CHECK-NEXT: Version: 0x1
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Sections:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: TYPE
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Signatures:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Index: 0
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: ParamTypes:
|
2019-10-19 04:27:30 +08:00
|
|
|
; CHECK-NEXT: ReturnTypes:
|
|
|
|
; CHECK-NEXT: - I64
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Index: 1
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: ParamTypes:
|
2019-10-19 04:27:30 +08:00
|
|
|
; CHECK-NEXT: ReturnTypes:
|
|
|
|
; CHECK-NEXT: - I32
|
2017-12-20 09:17:45 +08:00
|
|
|
; CHECK-NEXT: - Index: 2
|
2018-01-23 09:25:56 +08:00
|
|
|
; CHECK-NEXT: ParamTypes:
|
2018-02-01 07:48:14 +08:00
|
|
|
; CHECK-NEXT: - I64
|
2019-10-19 04:27:30 +08:00
|
|
|
; CHECK-NEXT: ReturnTypes:
|
|
|
|
; CHECK-NEXT: - I64
|
2018-01-23 09:25:56 +08:00
|
|
|
; CHECK-NEXT: - Index: 3
|
2018-01-24 08:22:53 +08:00
|
|
|
; CHECK-NEXT: ParamTypes:
|
2019-10-19 04:27:30 +08:00
|
|
|
; CHECK-NEXT: ReturnTypes: []
|
2018-01-23 09:25:56 +08:00
|
|
|
; CHECK-NEXT: - Index: 4
|
2018-01-24 08:22:53 +08:00
|
|
|
; CHECK-NEXT: ParamTypes:
|
2018-02-01 07:48:14 +08:00
|
|
|
; CHECK-NEXT: - I32
|
2019-10-19 04:27:30 +08:00
|
|
|
; CHECK-NEXT: ReturnTypes: []
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: FUNCTION
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: FunctionTypes: [ 0, 3, 1, 3, 4 ]
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: TABLE
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Tables:
|
2020-10-13 22:13:10 +08:00
|
|
|
; CHECK-NEXT: - Index: 0
|
|
|
|
; CHECK-NEXT: ElemType: FUNCREF
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Limits:
|
2017-12-14 08:34:25 +08:00
|
|
|
; CHECK-NEXT: Flags: [ HAS_MAX ]
|
2021-03-23 21:46:32 +08:00
|
|
|
; CHECK-NEXT: Minimum: 0x3
|
2020-11-18 16:59:49 +08:00
|
|
|
; CHECK-NEXT: Maximum: 0x3
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: MEMORY
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Memories:
|
2021-03-23 21:46:32 +08:00
|
|
|
; CHECK-NEXT: - Minimum: 0x2
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: GLOBAL
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Globals:
|
2018-01-10 05:47:36 +08:00
|
|
|
; CHECK-NEXT: - Index: 0
|
|
|
|
; CHECK-NEXT: Type: I32
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: Mutable: true
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: InitExpr:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: Opcode: I32_CONST
|
|
|
|
; CHECK-NEXT: Value: 66576
|
2018-01-17 09:34:31 +08:00
|
|
|
; CHECK-NEXT: - Index: 1
|
|
|
|
; CHECK-NEXT: Type: I32
|
|
|
|
; CHECK-NEXT: Mutable: false
|
|
|
|
; CHECK-NEXT: InitExpr:
|
|
|
|
; CHECK-NEXT: Opcode: I32_CONST
|
2018-03-02 22:51:36 +08:00
|
|
|
; CHECK-NEXT: Value: 1032
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: EXPORT
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Exports:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Name: memory
|
|
|
|
; CHECK-NEXT: Kind: MEMORY
|
|
|
|
; CHECK-NEXT: Index: 0
|
|
|
|
; CHECK-NEXT: - Name: bar
|
|
|
|
; CHECK-NEXT: Kind: FUNCTION
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: Index: 0
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Name: call_bar_indirect
|
|
|
|
; CHECK-NEXT: Kind: FUNCTION
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: Index: 1
|
2018-01-19 07:40:49 +08:00
|
|
|
; CHECK-NEXT: - Name: foo
|
|
|
|
; CHECK-NEXT: Kind: FUNCTION
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: Index: 2
|
2018-08-04 08:04:06 +08:00
|
|
|
; CHECK-NEXT: - Name: _start
|
|
|
|
; CHECK-NEXT: Kind: FUNCTION
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: Index: 3
|
2018-03-02 22:51:36 +08:00
|
|
|
; CHECK-NEXT: - Name: indirect_func
|
|
|
|
; CHECK-NEXT: Kind: GLOBAL
|
2019-06-01 06:51:59 +08:00
|
|
|
; CHECK-NEXT: Index: 1
|
2017-12-20 09:17:45 +08:00
|
|
|
; CHECK-NEXT: - Name: call_ptr
|
|
|
|
; CHECK-NEXT: Kind: FUNCTION
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: Index: 4
|
2017-12-12 08:22:21 +08:00
|
|
|
; CHECK-NEXT: - Type: ELEM
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Segments:
|
|
|
|
; CHECK-NEXT: - Offset:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: Opcode: I32_CONST
|
|
|
|
; CHECK-NEXT: Value: 1
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: Functions: [ 0, 2 ]
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: CODE
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Functions:
|
2018-01-10 05:47:36 +08:00
|
|
|
; CHECK-NEXT: - Index: 0
|
|
|
|
; CHECK-NEXT: Locals:
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Body: 42010B
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 1
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Locals:
|
2021-01-20 06:29:05 +08:00
|
|
|
; CHECK-NEXT: Body: 410028028088808000118080808000001A410028028488808000118180808000001A0B
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 2
|
2018-01-10 05:47:36 +08:00
|
|
|
; CHECK-NEXT: Locals:
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Body: 41020B
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 3
|
2018-01-10 05:47:36 +08:00
|
|
|
; CHECK-NEXT: Locals:
|
2021-01-20 06:29:05 +08:00
|
|
|
; CHECK-NEXT: Body: 410028028888808000118180808000001A0B
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 4
|
2018-01-13 02:35:13 +08:00
|
|
|
; CHECK-NEXT: Locals:
|
2021-01-20 06:29:05 +08:00
|
|
|
; CHECK-NEXT: Body: 42012000118280808000001A0B
|
2017-12-12 08:22:21 +08:00
|
|
|
; CHECK-NEXT: - Type: DATA
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Segments:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - SectionOffset: 7
|
2019-02-20 06:56:19 +08:00
|
|
|
; CHECK-NEXT: InitFlags: 0
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: Offset:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: Opcode: I32_CONST
|
|
|
|
; CHECK-NEXT: Value: 1024
|
2017-12-12 06:00:56 +08:00
|
|
|
; CHECK-NEXT: Content: '010000000200000002000000'
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Type: CUSTOM
|
|
|
|
; CHECK-NEXT: Name: name
|
2017-12-13 04:00:30 +08:00
|
|
|
; CHECK-NEXT: FunctionNames:
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: - Index: 0
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Name: bar
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 1
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Name: call_bar_indirect
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 2
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Name: foo
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 3
|
2017-11-18 02:14:09 +08:00
|
|
|
; CHECK-NEXT: Name: _start
|
2019-03-02 06:35:47 +08:00
|
|
|
; CHECK-NEXT: - Index: 4
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: Name: call_ptr
|
2020-11-19 13:38:23 +08:00
|
|
|
; CHECK-NEXT: GlobalNames:
|
|
|
|
; CHECK-NEXT: - Index: 0
|
|
|
|
; CHECK-NEXT: Name: __stack_pointer
|
2020-12-09 13:47:19 +08:00
|
|
|
; CHECK-NEXT: DataSegmentNames:
|
|
|
|
; CHECK-NEXT: - Index: 0
|
|
|
|
; CHECK-NEXT: Name: .data
|
2018-03-12 23:44:07 +08:00
|
|
|
; CHECK-NEXT: ...
|