[WebAssembly] Teach lld how to demangle "__main_argc_argv".
authorDan Gohman <sunfish@mozilla.com>
Thu, 27 Feb 2020 15:51:37 +0000 (07:51 -0800)
committerDan Gohman <sunfish@mozilla.com>
Thu, 27 Feb 2020 15:55:01 +0000 (07:55 -0800)
WebAssembly requires that caller and callee signatures match, so it
can't do the usual trick of passing more arguments to main than it
expects. Instead WebAssembly will mangle "main" with argc/argv
parameters as "__main_argc_argv". This patch teaches lld how to
demangle it.

This patch is part of https://reviews.llvm.org/D70700.

lld/wasm/Symbols.cpp

index 3d8fec4..349fc65 100644 (file)
@@ -29,6 +29,10 @@ std::string toString(const wasm::Symbol &sym) {
 }
 
 std::string maybeDemangleSymbol(StringRef name) {
+  // WebAssembly requires caller and callee signatures to match, so we mangle
+  // `main` in the case where we need to pass it arguments.
+  if (name == "__main_argc_argv")
+    return "main";
   if (wasm::config->demangle)
     return demangleItanium(name);
   return std::string(name);