Revert "Don't pass llvm::errs() all over the place. Diagnostics always go to stderr."

This reverts commit 185657. It will be used by unit tests.

llvm-svn: 186366
diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp
index c9a9918..a0233fe 100644
--- a/lld/lib/Driver/Driver.cpp
+++ b/lld/lib/Driver/Driver.cpp
@@ -29,7 +29,7 @@
 namespace lld {
 
 /// This is where the link is actually performed.
-bool Driver::link(const TargetInfo &targetInfo) {
+bool Driver::link(const TargetInfo &targetInfo, raw_ostream &diagnostics) {
   // Honor -mllvm
   if (!targetInfo.llvmOptions().empty()) {
     unsigned numArgs = targetInfo.llvmOptions().size();
@@ -52,10 +52,10 @@
     if (targetInfo.logInputFiles())
       llvm::outs() << input.getPath() << "\n";
 
-    tg.spawn([ &, index]{
+    tg.spawn([&, index] {
       if (error_code ec = targetInfo.readFile(input.getPath(), files[index])) {
-        llvm::errs() << "Failed to read file: " << input.getPath() << ": "
-                     << ec.message() << "\n";
+        diagnostics << "Failed to read file: " << input.getPath()
+                    << ": " << ec.message() << "\n";
         fail = true;
         return;
       }
@@ -98,8 +98,8 @@
   // Give linked atoms to Writer to generate output file.
   ScopedTask writeTask(getDefaultDomain(), "Write");
   if (error_code ec = targetInfo.writeFile(merged)) {
-    llvm::errs() << "Failed to write file '" << targetInfo.outputPath()
-                 << "': " << ec.message() << "\n";
+    diagnostics << "Failed to write file '" << targetInfo.outputPath() 
+                << "': " << ec.message() << "\n";
     return true;
   }