ELF: Define log() to print out message if --verbose is given.
authorRui Ueyama <ruiu@google.com>
Thu, 25 Feb 2016 18:56:01 +0000 (18:56 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 25 Feb 2016 18:56:01 +0000 (18:56 +0000)
llvm-svn: 261919

lld/ELF/Driver.cpp
lld/ELF/Error.cpp
lld/ELF/Error.h
lld/ELF/ICF.cpp

index 6b7ff3d..daef69f 100644 (file)
@@ -89,8 +89,7 @@ static std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB) {
 // Newly created memory buffers are owned by this driver.
 void LinkerDriver::addFile(StringRef Path) {
   using namespace llvm::sys::fs;
-  if (Config->Verbose)
-    llvm::outs() << Path << "\n";
+  log(Path);
   auto MBOrErr = MemoryBuffer::getFile(Path);
   if (error(MBOrErr, "cannot open " + Path))
     return;
index 4a5b8af..2f78108 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Error.h"
+#include "Config.h"
 
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
@@ -18,6 +19,11 @@ namespace elf2 {
 bool HasError;
 llvm::raw_ostream *ErrorOS;
 
+void log(const Twine &Msg) {
+  if (Config->Verbose)
+    llvm::outs() << Msg << "\n";
+}
+
 void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; }
 
 void error(const Twine &Msg) {
index 55782b1..941190e 100644 (file)
@@ -22,6 +22,7 @@ namespace elf2 {
 extern bool HasError;
 extern llvm::raw_ostream *ErrorOS;
 
+void log(const Twine &Msg);
 void warning(const Twine &Msg);
 
 void error(const Twine &Msg);
index 599d946..3ac37dc 100644 (file)
@@ -349,8 +349,7 @@ template <class ELFT> void ICF<ELFT>::run(SymbolTable<ELFT> *Symtab) {
     if (Id == NextId)
       break;
   }
-  if (Config->Verbose)
-    llvm::outs() << "ICF needed " << Cnt << " iterations.\n";
+  log("ICF needed " + Twine(Cnt) + " iterations.");
 
   // Merge sections in the same group.
   for (auto I = V.begin(), E = V.end(); I != E;) {
@@ -360,12 +359,10 @@ template <class ELFT> void ICF<ELFT>::run(SymbolTable<ELFT> *Symtab) {
     });
     if (I == Bound)
       continue;
-    if (Config->Verbose)
-      llvm::outs() << "Selected " << Head->getSectionName() << "\n";
+    log("Selected " + Head->getSectionName());
     while (I != Bound) {
       InputSection<ELFT> *S = *I++;
-      if (Config->Verbose)
-        llvm::outs() << "  Removed " << S->getSectionName() << "\n";
+      log("  Removed " + S->getSectionName());
       Head->replace(S);
     }
   }