[lld] r320167 - [WebAssembly] Add --no-entry argument

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 09:58:25 PST 2017


Author: sbc
Date: Fri Dec  8 09:58:25 2017
New Revision: 320167

URL: http://llvm.org/viewvc/llvm-project?rev=320167&view=rev
Log:
[WebAssembly] Add --no-entry argument

This adds a `--no-entry` argument to wasm LLD used to
suppress the default `_start` entry point.

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D40725

Modified:
    lld/trunk/test/wasm/data-layout.ll
    lld/trunk/wasm/Driver.cpp
    lld/trunk/wasm/Options.td

Modified: lld/trunk/test/wasm/data-layout.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/data-layout.ll?rev=320167&r1=320166&r2=320167&view=diff
==============================================================================
--- lld/trunk/test/wasm/data-layout.ll (original)
+++ lld/trunk/test/wasm/data-layout.ll Fri Dec  8 09:58:25 2017
@@ -1,6 +1,6 @@
 ; RUN: llc -filetype=obj %p/Inputs/hello.ll -o %t.hello.o
 ; RUN: llc -filetype=obj %s -o %t.o
-; RUN: lld -flavor wasm --emit-relocs --allow-undefined -o %t.wasm %t.o %t.hello.o
+; RUN: lld -flavor wasm --emit-relocs --allow-undefined --no-entry -o %t.wasm %t.o %t.hello.o
 ; RUN: obj2yaml %t.wasm | FileCheck %s
 
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"

Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=320167&r1=320166&r2=320167&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Fri Dec  8 09:58:25 2017
@@ -202,6 +202,15 @@ void LinkerDriver::createFiles(opt::Inpu
     error("no input files");
 }
 
+static const char *getEntry(opt::InputArgList &Args, const char *def) {
+  auto *Arg = Args.getLastArg(OPT_entry, OPT_no_entry);
+  if (!Arg)
+    return def;
+  if (Arg->getOption().getID() == OPT_no_entry)
+    return "";
+  return Arg->getValue();
+}
+
 void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
   WasmOptTable Parser;
   opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -230,10 +239,10 @@ void LinkerDriver::link(ArrayRef<const c
   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->Relocatable = Args.hasArg(OPT_relocatable);
+  Config->Entry = getEntry(Args, Config->Relocatable ? "" : "_start");
   Config->ImportMemory = Args.hasArg(OPT_import_memory);
   Config->OutputFile = Args.getLastArgValue(OPT_o);
-  Config->Relocatable = Args.hasArg(OPT_relocatable);
   Config->SearchPaths = args::getStrings(Args, OPT_L);
   Config->StripAll = Args.hasArg(OPT_strip_all);
   Config->StripDebug = Args.hasArg(OPT_strip_debug);
@@ -265,10 +274,10 @@ void LinkerDriver::link(ArrayRef<const c
     error("undefined symbols specified for relocatable output file");
 
   if (!Config->Relocatable) {
-    if (Config->Entry.empty())
-      Config->Entry = "_start";
-    static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
-    addSyntheticUndefinedFunction(Config->Entry, &Signature);
+    if (!Config->Entry.empty()) {
+      static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
+      addSyntheticUndefinedFunction(Config->Entry, &Signature);
+    }
 
     // Handle the `--undefined <sym>` options.
     for (StringRef S : args::getStrings(Args, OPT_undefined))
@@ -301,15 +310,12 @@ void LinkerDriver::link(ArrayRef<const c
       if (!Sym->isDefined())
         error("function forced with --undefined not found: " + Sym->getName());
     }
-    if (errorCount())
-      return;
   }
 
-  if (!Config->Entry.empty()) {
-    Symbol *Sym = Symtab->find(Config->Entry);
-    if (!Sym->isFunction())
-      fatal("entry point is not a function: " + Sym->getName());
-  }
+  if (!Config->Entry.empty() && !Symtab->find(Config->Entry)->isDefined())
+    error("entry point not found: " + Config->Entry);
+  if (errorCount())
+    return;
 
   // Write the result to the file.
   writeResult();

Modified: lld/trunk/wasm/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Options.td?rev=320167&r1=320166&r2=320167&view=diff
==============================================================================
--- lld/trunk/wasm/Options.td (original)
+++ lld/trunk/wasm/Options.td Fri Dec  8 09:58:25 2017
@@ -66,6 +66,9 @@ def z: JoinedOrSeparate<["-"], "z">, Met
 def entry: S<"entry">, MetaVarName<"<entry>">,
   HelpText<"Name of entry point symbol">;
 
+def no_entry: F<"no-entry">,
+  HelpText<"Do not output any entry point">;
+
 def error_limit: J<"error-limit=">,
   HelpText<"Maximum number of errors to emit before stopping (0 = no limit)">;
 




More information about the llvm-commits mailing list