1 # Checks handling of undefined weak external functions. When the
2 # static linker decides they are undefined, check GOT relocations
3 # resolve to zero (i.e. a global that contains zero.).
5 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
6 # RUN: wasm-ld %t.o -o %t1.wasm
7 # RUN: obj2yaml %t1.wasm | FileCheck %s
9 # With `--unresolved-symbols=ignore-all` the behaviour should be the same
12 # RUN: wasm-ld --unresolved-symbols=ignore-all %t.o -o %t2.wasm
13 # RUN: obj2yaml %t2.wasm | FileCheck %s
15 .functype foo () -> (i32)
19 .functype get_foo_addr () -> (i32)
25 .functype _start () -> (i32)
33 # Verify that we do not generate dynamic relocations for the GOT entry.
35 # CHECK-NOT: __wasm_apply_global_relocs
37 # Verify that we do not generate an import for foo
39 # CHECK-NOT: - Type: IMPORT
41 # CHECK: - Type: GLOBAL
42 # CHECK-NEXT: Globals:
43 # CHECK-NEXT: - Index: 0
44 # CHECK-NEXT: Type: I32
45 # CHECK-NEXT: Mutable: true
46 # CHECK-NEXT: InitExpr:
47 # CHECK-NEXT: Opcode: I32_CONST
48 # CHECK-NEXT: Value: 66560
49 # Global 'undefined_weak:foo' representing the GOT entry for foo
50 # Unlike other internal GOT entries that need to be mutable this one
51 # is immutable and not updated by `__wasm_apply_global_relocs`
52 # CHECK-NEXT: - Index: 1
53 # CHECK-NEXT: Type: I32
54 # CHECK-NEXT: Mutable: false
55 # CHECK-NEXT: InitExpr:
56 # CHECK-NEXT: Opcode: I32_CONST
57 # CHECK-NEXT: Value: 0
59 # CHECK: - Type: CUSTOM
60 # CHECK-NEXT: Name: name
61 # CHECK-NEXT: FunctionNames:
62 # CHECK-NEXT: - Index: 0
63 # CHECK-NEXT: Name: 'undefined_weak:foo'
64 # CHECK-NEXT: - Index: 1
65 # CHECK-NEXT: Name: get_foo_addr
66 # CHECK-NEXT: - Index: 2
67 # CHECK-NEXT: Name: _start
68 # CHECK-NEXT: GlobalNames:
69 # CHECK-NEXT: - Index: 0
70 # CHECK-NEXT: Name: __stack_pointer
71 # CHECK-NEXT: - Index: 1
72 # CHECK-NEXT: Name: 'GOT.func.internal.undefined_weak:foo'
74 # With `-pie` or `-shared` the resolution should be deferred to the dynamic
75 # linker and the function address should be imported as GOT.func.foo.
77 # RUN: wasm-ld --experimental-pic -pie %t.o -o %t3.wasm
78 # RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT
80 # IMPORT: - Type: IMPORT
82 # IMPORT-NEXT: Kind: FUNCTION
83 # IMPORT-NEXT: SigIndex: 0
84 # IMPORT-NEXT: - Module: GOT.func
85 # IMPORT-NEXT: Field: foo
86 # IMPORT-NEXT: Kind: GLOBAL
87 # IMPORT-NEXT: GlobalType: I32
88 # IMPORT-NEXT: GlobalMutable: true
90 # IMPORT: GlobalNames:
91 # IMPORT-NEXT: - Index: 0
92 # IMPORT-NEXT: Name: __memory_base
93 # IMPORT-NEXT: - Index: 1
94 # IMPORT-NEXT: Name: __table_base
95 # IMPORT-NEXT: - Index: 2
96 # IMPORT-NEXT: Name: foo