Files
clang-p2996/lld/test/wasm/command-exports.s
Dan Gohman 6cd8511e59 [WebAssembly] New-style command support
This adds support for new-style command support. In this mode, all exports
are considered command entrypoints, and the linker inserts calls to
`__wasm_call_ctors` and `__wasm_call_dtors` for all such entrypoints.

This enables support for:

 - Command entrypoints taking arguments other than strings and return values
   other than `int`.
 - Multicall executables without requiring on the use of string-based
   command-line arguments.

This new behavior is disabled when the input has an explicit call to
`__wasm_call_ctors`, indicating code not expecting new-style command
support.

This change does mean that wasm-ld no longer supports DCE-ing the
`__wasm_call_ctors` function when there are no calls to it. If there are no
calls to it, and there are ctors present, we assume it's wasm-ld's job to
insert the calls. This seems ok though, because if there are ctors present,
the program is expecting them to be called. This change affects the
init-fini-gc.ll test.
2020-09-30 19:02:40 -07:00

114 lines
3.1 KiB
ArmAsm

# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: wasm-ld --no-entry %t.o -o %t.wasm
# RUN: obj2yaml %t.wasm | FileCheck %s
# This test defines a command with two exported functions, as well as a static
# constructor and a static destructor. Check that the exports, constructor, and
# destructor are all set up properly.
.globl foo_i32
foo_i32:
.functype foo_i32 (i32, i32) -> (i32)
local.get 0
local.get 1
i32.add
end_function
.globl foo_f64
foo_f64:
.functype foo_f64 (f64, f64) -> (f64)
local.get 0
local.get 1
f64.add
end_function
.globl some_ctor
some_ctor:
.functype some_ctor () -> ()
end_function
.globl some_dtor
some_dtor:
.functype some_dtor () -> ()
end_function
.hidden __cxa_atexit
.globl __cxa_atexit
__cxa_atexit:
.functype __cxa_atexit (i32, i32, i32) -> (i32)
i32.const 0
end_function
.section .text..Lcall_dtors.1,"",@
.Lcall_dtors.1:
.functype .Lcall_dtors.1 (i32) -> ()
call some_dtor
end_function
.section .text..Lregister_call_dtors.1,"",@
.Lregister_call_dtors.1:
.functype .Lregister_call_dtors.1 () -> ()
block
i32.const .Lcall_dtors.1
i32.const 0
i32.const 0
call __cxa_atexit
i32.eqz
br_if 0
unreachable
.LBB6_2:
end_block
end_function
.section .init_array.1,"",@
.p2align 2
.int32 some_ctor
.int32 .Lregister_call_dtors.1
.export_name foo_i32, foo_i32
.export_name foo_f64, foo_f64
# CHECK: - Type: EXPORT
# CHECK-NEXT: Exports:
# CHECK-NEXT: - Name: memory
# CHECK-NEXT: Kind: MEMORY
# CHECK-NEXT: Index: 0
# CHECK-NEXT: - Name: foo_i32
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: Index: 8
# CHECK-NEXT: - Name: foo_f64
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: Index: 9
# CHECK: - Type: CODE
# CHECK: - Index: 8
# CHECK-NEXT: Locals: []
# CHECK-NEXT: Body: 10002000200110010B
# CHECK-NEXT: - Index: 9
# CHECK-NEXT: Locals: []
# CHECK-NEXT: Body: 10002000200110020B
# CHECK: - Type: CUSTOM
# CHECK-NEXT: Name: name
# CHECK-NEXT: FunctionNames:
# CHECK-NEXT: - Index: 0
# CHECK-NEXT: Name: __wasm_call_ctors
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Name: foo_i32
# CHECK-NEXT: - Index: 2
# CHECK-NEXT: Name: foo_f64
# CHECK-NEXT: - Index: 3
# CHECK-NEXT: Name: some_ctor
# CHECK-NEXT: - Index: 4
# CHECK-NEXT: Name: some_dtor
# CHECK-NEXT: - Index: 5
# CHECK-NEXT: Name: __cxa_atexit
# CHECK-NEXT: - Index: 6
# CHECK-NEXT: Name: .Lcall_dtors.1
# CHECK-NEXT: - Index: 7
# CHECK-NEXT: Name: .Lregister_call_dtors.1
# CHECK-NEXT: - Index: 8
# CHECK-NEXT: Name: foo_i32.command_export
# CHECK-NEXT: - Index: 9
# CHECK-NEXT: Name: foo_f64.command_export