97 lines · plain
1# Checks handling of undefined weak external functions. When the2# static linker decides they are undefined, check GOT relocations3# resolve to zero (i.e. a global that contains zero.).4#5# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s6# RUN: wasm-ld %t.o -o %t1.wasm7# RUN: obj2yaml %t1.wasm | FileCheck %s8#9# With `--unresolved-symbols=ignore-all` the behaviour should be the same10# as the default.>11#12# RUN: wasm-ld --unresolved-symbols=ignore-all %t.o -o %t2.wasm13# RUN: obj2yaml %t2.wasm | FileCheck %s14 15.functype foo () -> (i32)16 17.globl get_foo_addr18get_foo_addr:19 .functype get_foo_addr () -> (i32)20 global.get foo@GOT21 end_function22 23.globl _start24_start:25 .functype _start () -> (i32)26 call get_foo_addr27 call foo28 drop29 end_function30 31.weak foo32 33# Verify that we do not generate dynamic relocations for the GOT entry.34 35# CHECK-NOT: __wasm_apply_global_relocs36 37# Verify that we do not generate an import for foo38 39# CHECK-NOT: - Type: IMPORT40 41# CHECK: - Type: GLOBAL42# CHECK-NEXT: Globals:43# CHECK-NEXT: - Index: 044# CHECK-NEXT: Type: I3245# CHECK-NEXT: Mutable: true46# CHECK-NEXT: InitExpr:47# CHECK-NEXT: Opcode: I32_CONST48# CHECK-NEXT: Value: 6553649# Global 'undefined_weak:foo' representing the GOT entry for foo50# Unlike other internal GOT entries that need to be mutable this one51# is immutable and not updated by `__wasm_apply_global_relocs`52# CHECK-NEXT: - Index: 153# CHECK-NEXT: Type: I3254# CHECK-NEXT: Mutable: false55# CHECK-NEXT: InitExpr:56# CHECK-NEXT: Opcode: I32_CONST57# CHECK-NEXT: Value: 058 59# CHECK: - Type: CUSTOM60# CHECK-NEXT: Name: name61# CHECK-NEXT: FunctionNames:62# CHECK-NEXT: - Index: 063# CHECK-NEXT: Name: 'undefined_weak:foo'64# CHECK-NEXT: - Index: 165# CHECK-NEXT: Name: get_foo_addr66# CHECK-NEXT: - Index: 267# CHECK-NEXT: Name: _start68# CHECK-NEXT: GlobalNames:69# CHECK-NEXT: - Index: 070# CHECK-NEXT: Name: __stack_pointer71# CHECK-NEXT: - Index: 172# CHECK-NEXT: Name: 'GOT.func.internal.undefined_weak:foo'73 74# With `-pie` or `-shared` the resolution should be deferred to the dynamic75# linker and the function address should be imported as GOT.func.foo.76#77# RUN: wasm-ld --experimental-pic -pie %t.o -o %t3.wasm78# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT79 80# IMPORT: - Type: IMPORT81# IMPORT: Field: foo82# IMPORT-NEXT: Kind: FUNCTION83# IMPORT-NEXT: SigIndex: 084# IMPORT-NEXT: - Module: GOT.func85# IMPORT-NEXT: Field: foo86# IMPORT-NEXT: Kind: GLOBAL87# IMPORT-NEXT: GlobalType: I3288# IMPORT-NEXT: GlobalMutable: true89 90# IMPORT: GlobalNames:91# IMPORT-NEXT: - Index: 092# IMPORT-NEXT: Name: __memory_base93# IMPORT-NEXT: - Index: 194# IMPORT-NEXT: Name: __table_base95# IMPORT-NEXT: - Index: 296# IMPORT-NEXT: Name: foo97