[lld] r265156 - Make error handling consistent.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 10:24:19 PDT 2016


Author: ruiu
Date: Fri Apr  1 12:24:19 2016
New Revision: 265156

URL: http://llvm.org/viewvc/llvm-project?rev=265156&view=rev
Log:
Make error handling consistent.

Some functions in Writer reports error using HasError, and some reports
their return values. This patch makes them to consistently use HasError.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=265156&r1=265155&r2=265156&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Apr  1 12:24:19 2016
@@ -62,7 +62,7 @@ private:
 
   void copyLocalSymbols();
   void addReservedSymbols();
-  bool createSections();
+  void createSections();
   void addPredefinedSections();
   bool needsGot();
 
@@ -78,7 +78,7 @@ private:
   void setPhdrs();
   void fixSectionAlignments();
   void fixAbsoluteSymbols();
-  bool openFile();
+  void openFile();
   void writeHeader();
   void writeSections();
   void writeBuildId();
@@ -214,7 +214,8 @@ template <class ELFT> void Writer<ELFT>:
   if (!Config->DiscardAll)
     copyLocalSymbols();
   addReservedSymbols();
-  if (!createSections())
+  createSections();
+  if (HasError)
     return;
 
   if (Config->Relocatable) {
@@ -228,7 +229,8 @@ template <class ELFT> void Writer<ELFT>:
     fixAbsoluteSymbols();
   }
 
-  if (!openFile())
+  openFile();
+  if (HasError)
     return;
   writeHeader();
   writeSections();
@@ -959,7 +961,7 @@ template <class ELFT> static void sortCt
 }
 
 // Create output section objects and add them to OutputSections.
-template <class ELFT> bool Writer<ELFT>::createSections() {
+template <class ELFT> void Writer<ELFT>::createSections() {
   OutputSections.push_back(Out<ELFT>::ElfHeader);
   if (!Config->Relocatable)
     OutputSections.push_back(Out<ELFT>::ProgramHeaders);
@@ -1082,7 +1084,7 @@ template <class ELFT> bool Writer<ELFT>:
 
   // Do not proceed if there was an undefined symbol.
   if (HasError)
-    return false;
+    return;
 
   addCommonSymbols(CommonSymbols);
   addCopyRelSymbols(CopyRelSymbols);
@@ -1116,7 +1118,6 @@ template <class ELFT> bool Writer<ELFT>:
 
   if (isOutputDynamic())
     Out<ELFT>::Dynamic->finalize();
-  return true;
 }
 
 template <class ELFT> bool Writer<ELFT>::needsGot() {
@@ -1533,16 +1534,14 @@ template <class ELFT> void Writer<ELFT>:
     Sec->writeHeaderTo(++SHdrs);
 }
 
-template <class ELFT> bool Writer<ELFT>::openFile() {
+template <class ELFT> void Writer<ELFT>::openFile() {
   ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
       FileOutputBuffer::create(Config->OutputFile, FileSize,
                                FileOutputBuffer::F_executable);
-  if (!BufferOrErr) {
+  if (BufferOrErr)
+    Buffer = std::move(*BufferOrErr);
+  else
     error(BufferOrErr, "failed to open " + Config->OutputFile);
-    return false;
-  }
-  Buffer = std::move(*BufferOrErr);
-  return true;
 }
 
 // Write section contents to a mmap'ed file.




More information about the llvm-commits mailing list