[WebAssembly] Allow function signature checking at link time
This change allows checking of function signatures but
does not yes enable it by default. In this mode, linking
two objects that were compiled with a different signatures
for the same function will produce a link error.
New options for enabling and disabling this feature have been
added: (--check-signatures/--no-check-signatures).
Differential Revision: https://reviews.llvm.org/D40371
llvm-svn: 319396
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index a1fe414..769ef85 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -153,9 +153,10 @@
// Inject a new undefined symbol into the link. This will cause the link to
// fail unless this symbol can be found.
-static void addSyntheticUndefinedFunction(StringRef Name) {
+static void addSyntheticUndefinedFunction(StringRef Name,
+ const WasmSignature *Type) {
log("injecting undefined func: " + Name);
- Symtab->addUndefinedFunction(Name);
+ Symtab->addUndefinedFunction(Name, Type);
}
static void printHelp(const char *Argv0) {
@@ -243,6 +244,8 @@
}
Config->AllowUndefined = Args.hasArg(OPT_allow_undefined);
+ Config->CheckSignatures =
+ Args.hasFlag(OPT_check_signatures, OPT_no_check_signatures, false);
Config->EmitRelocs = Args.hasArg(OPT_emit_relocs);
Config->Entry = Args.getLastArgValue(OPT_entry);
Config->ImportMemory = Args.hasArg(OPT_import_memory);
@@ -278,7 +281,8 @@
if (!Config->Relocatable) {
if (Config->Entry.empty())
Config->Entry = "_start";
- addSyntheticUndefinedFunction(Config->Entry);
+ static WasmSignature Signature = { {}, WASM_TYPE_NORESULT };
+ addSyntheticUndefinedFunction(Config->Entry, &Signature);
addSyntheticGlobal("__stack_pointer", 0);
}