[WebAssembly] New-style command support
authorDan Gohman <dev@sunfishcode.online>
Thu, 1 Oct 2020 00:21:57 +0000 (17:21 -0700)
committerDan Gohman <dev@sunfishcode.online>
Thu, 1 Oct 2020 02:02:40 +0000 (19:02 -0700)
commit6cd8511e5932e4a53b2bb7780f69489355fc7783
tree3dba2cdbb570248107ce2eec1cb25894b36b437f
parentb656189e6a602aaf86714ccbf89d94f2ef05b644
[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.
lld/test/wasm/command-exports-no-tors.s [new file with mode: 0644]
lld/test/wasm/command-exports.s [new file with mode: 0644]
lld/test/wasm/init-fini-gc.ll [deleted file]
lld/test/wasm/init-fini-no-gc.ll [new file with mode: 0644]
lld/wasm/Driver.cpp
lld/wasm/InputChunks.h
lld/wasm/MarkLive.cpp
lld/wasm/Symbols.cpp
lld/wasm/Symbols.h
lld/wasm/Writer.cpp