1 ; RUN: llc -O2 -filetype=obj %s -o - | llvm-readobj -r -s -expand-relocs | FileCheck %s 2 3 target triple = "wasm32-unknown-unknown" 4 5 declare i32 @import1() 6 declare i32 @import2() 7 declare i32 @import3() 8 9 ; call the imports to make sure they are included in the imports section 10 define hidden void @call_imports() #0 { 11 entry: 12 %call = call i32 @import1() 13 %call1 = call i32 @import2() 14 ret void 15 } 16 17 ; take the address of the third import. This should generate a TABLE_INDEX 18 ; relocation with index of 0 since its the first and only address taken 19 ; function. 20 define hidden void @call_indirect() #0 { 21 entry: 22 %adr = alloca i32 ()*, align 4 23 store i32 ()* @import3, i32 ()** %adr, align 4 24 ret void 25 } 26 27 ; CHECK: Type: ELEM (0x9) 28 ; CHECK-NEXT: Size: 7 29 30 ; CHECK: Relocations [ 31 ; CHECK-NEXT: Section (5) CODE { 32 ; CHECK-NEXT: Relocation { 33 ; CHECK-NEXT: Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB (0) 34 ; CHECK-NEXT: Offset: 0x4 35 ; CHECK-NEXT: Symbol: import1 36 ; CHECK-NEXT: } 37 ; CHECK-NEXT: Relocation { 38 ; CHECK-NEXT: Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB (0) 39 ; CHECK-NEXT: Offset: 0xB 40 ; CHECK-NEXT: Symbol: import2 41 ; CHECK-NEXT: } 42 ; CHECK-NEXT: Relocation { 43 ; CHECK-NEXT: Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB (7) 44 ; CHECK-NEXT: Offset: 0x15 45 ; CHECK-NEXT: Symbol: __stack_pointer 46 ; CHECK-NEXT: } 47 ; CHECK-NEXT: Relocation { 48 ; CHECK-NEXT: Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB (1) 49 ; CHECK-NEXT: Offset: 0x1E 50 ; CHECK-NEXT: Symbol: import3 51 ; CHECK-NEXT: } 52 ; CHECK-NEXT: } 53 ; CHECK-NEXT: ] 54