ELF2: Implement OUTPUT() linker script directive.

llvm-svn: 249491
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 44c045a..474801f 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -38,6 +38,7 @@
 
   void readAsNeeded();
   void readGroup();
+  void readOutput();
   void readOutputFormat();
 
   std::vector<StringRef> Tokens;
@@ -50,6 +51,8 @@
     StringRef Tok = next();
     if (Tok == "GROUP") {
       readGroup();
+    } else if (Tok == "OUTPUT") {
+      readOutput();
     } else if (Tok == "OUTPUT_FORMAT") {
       readOutputFormat();
     } else {
@@ -142,6 +145,15 @@
   }
 }
 
+void LinkerScript::readOutput() {
+  // -o <file> takes predecence over OUTPUT(<file>).
+  expect("(");
+  StringRef Tok = next();
+  if (Config->OutputFile.empty())
+    Config->OutputFile = Tok;
+  expect(")");
+}
+
 void LinkerScript::readOutputFormat() {
   // Error checking only for now.
   expect("(");