[WebAssembly] Mangle the argc/argv `main` as `__wasm_argc_argv`.
authorDan Gohman <sunfish@mozilla.com>
Mon, 25 Nov 2019 17:50:58 +0000 (09:50 -0800)
committerDan Gohman <sunfish@mozilla.com>
Thu, 27 Feb 2020 15:55:36 +0000 (07:55 -0800)
commit00072c08c75050ae2c835b7bb0e505475dbcd7b9
treef6ea954da28498b216233acac4507efe27ff1eea
parent197bda587b4bb5e7603ad05fc1106332edc6afbd
[WebAssembly] Mangle the argc/argv `main` as `__wasm_argc_argv`.

WebAssembly enforces a rule that caller and callee signatures must
match. This means that the traditional technique of passing `main`
`argc` and `argv` even when it doesn't need them doesn't work.

Currently the backend renames `main` to `__original_main`, however this
doesn't interact well with LTO'ing libc, and the name isn't intuitive.
This patch allows us to transition to `__main_argc_argv` instead.

This implements the proposal in
https://github.com/WebAssembly/tool-conventions/pull/134
with a flag to disable it when targeting Emscripten, though this is
expected to be temporary, as discussed in the proposal comments.

Differential Revision: https://reviews.llvm.org/D70700
clang/lib/AST/Mangle.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Frontend/InitHeaderSearch.cpp
clang/test/CodeGen/wasm-call-main.c [new file with mode: 0644]
clang/test/CodeGen/wasm-main.c [new file with mode: 0644]
clang/test/CodeGen/wasm-main_argc_argv.c [new file with mode: 0644]