[ELF2] Add ENTRY command to the linker script

Set ENTRY as an entry point if -e is not specified.

Differential Revision: http://reviews.llvm.org/D13509

llvm-svn: 249661
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 474801f..a2b4fa5 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -37,6 +37,7 @@
   void expect(StringRef Expect);
 
   void readAsNeeded();
+  void readEntry();
   void readGroup();
   void readOutput();
   void readOutputFormat();
@@ -49,7 +50,9 @@
 void LinkerScript::run() {
   while (!atEOF()) {
     StringRef Tok = next();
-    if (Tok == "GROUP") {
+    if (Tok == "ENTRY") {
+      readEntry();
+    } else if (Tok == "GROUP") {
       readGroup();
     } else if (Tok == "OUTPUT") {
       readOutput();
@@ -131,6 +134,15 @@
   }
 }
 
+void LinkerScript::readEntry() {
+  // -e <symbol> takes predecence over ENTRY(<symbol>).
+  expect("(");
+  StringRef Tok = next();
+  if (Config->Entry.empty())
+    Config->Entry = Tok;
+  expect(")");
+}
+
 void LinkerScript::readGroup() {
   expect("(");
   for (;;) {