248 lines · plain
1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten -o %t.o %s2# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-emscripten %S/Inputs/internal_func.s -o %t.internal_func.o3# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --unresolved-symbols=import-dynamic -o %t.wasm %t.o %t.internal_func.o4# RUN: obj2yaml %t.wasm | FileCheck %s5# RUN: llvm-objdump --disassemble-symbols=__wasm_call_ctors,__wasm_apply_data_relocs --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DISASSEM6 7.functype external_func () -> ()8.functype internal_func1 () -> (i32)9.functype internal_func2 () -> (i32)10.globaltype __stack_pointer, i3211 12.section .data,"",@13.p2align 214data:15 .int32 216 .size data, 417 18indirect_func:19 .int32 foo20 .size indirect_func, 421 22data_addr:23 .int32 data24 .size data_addr, 425 26data_addr_external:27 .int32 data_external28 .size data_addr_external, 429 30.section .text,"",@31foo:32 .functype foo () -> (i32)33 34 global.get data@GOT35 i32.load 036 drop37 38 global.get indirect_func@GOT39 i32.load 040 call_indirect () -> (i32)41 drop42 43 global.get __stack_pointer44 end_function45 46get_data_address:47 .functype get_data_address () -> (i32)48 global.get data_addr_external@GOT49 end_function50 51get_internal_func1_address:52 .functype get_internal_func1_address () -> (i32)53 global.get internal_func1@GOT54 end_function55 56get_internal_func2_address:57 .functype get_internal_func2_address () -> (i32)58 global.get internal_func2@GOT59 end_function60 61.globl _start62_start:63 .functype _start () -> ()64 call external_func65 end_function66 67.section .custom_section.target_features,"",@68.int8 269.int8 4370.int8 771.ascii "atomics"72.int8 4373.int8 1174.ascii "bulk-memory"75 76# CHECK: Sections:77# CHECK-NEXT: - Type: CUSTOM78# CHECK-NEXT: Name: dylink.079# CHECK-NEXT: MemorySize: 1680# CHECK-NEXT: MemoryAlignment: 281# CHECK-NEXT: TableSize: 382# CHECK-NEXT: TableAlignment: 083# CHECK-NEXT: Needed: []84 85# CHECK: - Type: IMPORT86# CHECK-NEXT: Imports:87# CHECK-NEXT: - Module: env88# CHECK-NEXT: Field: __indirect_function_table89# CHECK-NEXT: Kind: TABLE90# CHECK-NEXT: Table:91# CHECK-NEXT: Index: 092# CHECK-NEXT: ElemType: FUNCREF93# CHECK-NEXT: Limits:94# CHECK-NEXT: Minimum: 0x395# CHECK-NEXT: - Module: env96# CHECK-NEXT: Field: __stack_pointer97# CHECK-NEXT: Kind: GLOBAL98# CHECK-NEXT: GlobalType: I3299# CHECK-NEXT: GlobalMutable: true100# CHECK-NEXT: - Module: env101# CHECK-NEXT: Field: __memory_base102# CHECK-NEXT: Kind: GLOBAL103# CHECK-NEXT: GlobalType: I32104# CHECK-NEXT: GlobalMutable: false105# CHECK-NEXT: - Module: env106# CHECK-NEXT: Field: __table_base107# CHECK-NEXT: Kind: GLOBAL108# CHECK-NEXT: GlobalType: I32109# CHECK-NEXT: GlobalMutable: false110 111# CHECK: - Type: START112# CHECK-NEXT: StartFunction: 3113 114# CHECK: - Type: CUSTOM115# CHECK-NEXT: Name: name116# CHECK-NEXT: FunctionNames:117# CHECK-NEXT: - Index: 0118# CHECK-NEXT: Name: external_func119# CHECK-NEXT: - Index: 1120# CHECK-NEXT: Name: __wasm_call_ctors121# CHECK-NEXT: - Index: 2122# CHECK-NEXT: Name: __wasm_apply_data_relocs123# CHECK-NEXT: - Index: 3124# CHECK-NEXT: Name: __wasm_apply_global_relocs125# CHECK-NEXT: - Index: 4126# CHECK-NEXT: Name: foo127# CHECK-NEXT: - Index: 5128# CHECK-NEXT: Name: get_data_address129# CHECK-NEXT: - Index: 6130# CHECK-NEXT: Name: get_internal_func1_address131# CHECK-NEXT: - Index: 7132# CHECK-NEXT: Name: get_internal_func2_address133# CHECK-NEXT: - Index: 8134# CHECK-NEXT: Name: _start135# CHECK-NEXT: - Index: 9136# CHECK-NEXT: Name: internal_func1137# CHECK-NEXT: - Index: 10138# CHECK-NEXT: Name: internal_func2139# CHECK-NEXT: GlobalNames:140 141# DISASSEM-LABEL: <__wasm_call_ctors>:142# DISASSEM-EMPTY:143# DISASSEM-NEXT: end144 145# DISASSEM-LABEL: <__wasm_apply_data_relocs>:146# DISASSEM: end147 148# Run the same test with extended-const support. When this is available149# we don't need __wasm_apply_global_relocs and instead rely on the add150# instruction in the InitExpr. We also, therefore, do not need these globals151# to be mutable.152 153# RUN: wasm-ld --no-gc-sections --experimental-pic -pie --unresolved-symbols=import-dynamic --extra-features=extended-const -o %t.extended.wasm %t.o %t.internal_func.o154# RUN: obj2yaml %t.extended.wasm | FileCheck %s --check-prefix=EXTENDED-CONST155 156# EXTENDED-CONST-NOT: __wasm_apply_global_relocs157 158# EXTENDED-CONST: - Type: GLOBAL159# EXTENDED-CONST-NEXT: Globals:160# EXTENDED-CONST-NEXT: - Index: 4161# EXTENDED-CONST-NEXT: Type: I32162# EXTENDED-CONST-NEXT: Mutable: false163# EXTENDED-CONST-NEXT: InitExpr:164# EXTENDED-CONST-NEXT: Opcode: GLOBAL_GET165# EXTENDED-CONST-NEXT: Index: 1166# EXTENDED-CONST-NEXT: - Index: 5167# EXTENDED-CONST-NEXT: Type: I32168# EXTENDED-CONST-NEXT: Mutable: false169# EXTENDED-CONST-NEXT: InitExpr:170# EXTENDED-CONST-NEXT: Extended: true171# EXTENDED-CONST-NEXT: Body: 230141046A0B172# EXTENDED-CONST-NEXT: - Index: 6173# EXTENDED-CONST-NEXT: Type: I32174# EXTENDED-CONST-NEXT: Mutable: false175# EXTENDED-CONST-NEXT: InitExpr:176# EXTENDED-CONST-NEXT: Extended: true177# This instruction sequence decodes to:178# (global.get[0x23] 0x1 i32.const[0x41] 0x0C i32.add[0x6A] end[0x0b])179# EXTENDED-CONST-NEXT: Body: 2301410C6A0B180# EXTENDED-CONST-NEXT: - Index: 7181# EXTENDED-CONST-NEXT: Type: I32182# EXTENDED-CONST-NEXT: Mutable: false183# EXTENDED-CONST-NEXT: InitExpr:184# EXTENDED-CONST-NEXT: Opcode: GLOBAL_GET185# EXTENDED-CONST-NEXT: Index: 2186# EXTENDED-CONST-NEXT: - Index: 8187# EXTENDED-CONST-NEXT: Type: I32188# EXTENDED-CONST-NEXT: Mutable: false189# EXTENDED-CONST-NEXT: InitExpr:190# EXTENDED-CONST-NEXT: Extended: true191# This instruction sequence decodes to:192# (global.get[0x23] 0x2 i32.const[0x41] 0x1 i32.add[0x6A] end[0x0b])193# EXTENDED-CONST-NEXT: Body: 230241016A0B194 195# EXTENDED-CONST-NOT: - Type: START196 197# EXTENDED-CONST: FunctionNames:198# EXTENDED-CONST-NEXT: - Index: 0199# EXTENDED-CONST-NEXT: Name: external_func200# EXTENDED-CONST-NEXT: - Index: 1201# EXTENDED-CONST-NEXT: Name: __wasm_call_ctors202# EXTENDED-CONST-NEXT: - Index: 2203# EXTENDED-CONST-NEXT: Name: __wasm_apply_data_relocs204 205# Run the same test with threading support. In this mode206# we expect __wasm_init_memory and __wasm_apply_data_relocs207# to be generated along with __wasm_start as the start208# function.209 210# RUN: wasm-ld --no-gc-sections --shared-memory --experimental-pic -pie --unresolved-symbols=import-dynamic -o %t.shmem.wasm %t.o %t.internal_func.o211# RUN: obj2yaml %t.shmem.wasm | FileCheck %s --check-prefix=SHMEM212# RUN: llvm-objdump --disassemble-symbols=__wasm_start --no-show-raw-insn --no-leading-addr %t.shmem.wasm | FileCheck %s --check-prefix DISASSEM-SHMEM213 214# SHMEM: - Type: START215# SHMEM-NEXT: StartFunction: 6216 217# DISASSEM-SHMEM-LABEL: <__wasm_start>:218# DISASSEM-SHMEM-EMPTY:219# DISASSEM-SHMEM-NEXT: call 5220# DISASSEM-SHMEM-NEXT: call 4221# DISASSEM-SHMEM-NEXT: end222 223# SHMEM: FunctionNames:224# SHMEM-NEXT: - Index: 0225# SHMEM-NEXT: Name: external_func226# SHMEM-NEXT: - Index: 1227# SHMEM-NEXT: Name: __wasm_call_ctors228# SHMEM-NEXT: - Index: 2229# SHMEM-NEXT: Name: __wasm_init_tls230# SHMEM-NEXT: - Index: 3231# SHMEM-NEXT: Name: __wasm_apply_data_relocs232# SHMEM-NEXT: - Index: 4233# SHMEM-NEXT: Name: __wasm_init_memory234# SHMEM-NEXT: - Index: 5235# SHMEM-NEXT: Name: __wasm_apply_global_relocs236# SHMEM-NEXT: - Index: 6237# SHMEM-NEXT: Name: __wasm_start238# SHMEM-NEXT: - Index: 7239# SHMEM-NEXT: Name: foo240# SHMEM-NEXT: - Index: 8241# SHMEM-NEXT: Name: get_data_address242# SHMEM-NEXT: - Index: 9243# SHMEM-NEXT: Name: get_internal_func1_address244# SHMEM-NEXT: - Index: 10245# SHMEM-NEXT: Name: get_internal_func2_address246# SHMEM-NEXT: - Index: 11247# SHMEM-NEXT: Name: _start248