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.
llvm-svn: 265156
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index db15861..5d4ee88 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -62,7 +62,7 @@
void copyLocalSymbols();
void addReservedSymbols();
- bool createSections();
+ void createSections();
void addPredefinedSections();
bool needsGot();
@@ -78,7 +78,7 @@
void setPhdrs();
void fixSectionAlignments();
void fixAbsoluteSymbols();
- bool openFile();
+ void openFile();
void writeHeader();
void writeSections();
void writeBuildId();
@@ -214,7 +214,8 @@
if (!Config->DiscardAll)
copyLocalSymbols();
addReservedSymbols();
- if (!createSections())
+ createSections();
+ if (HasError)
return;
if (Config->Relocatable) {
@@ -228,7 +229,8 @@
fixAbsoluteSymbols();
}
- if (!openFile())
+ openFile();
+ if (HasError)
return;
writeHeader();
writeSections();
@@ -959,7 +961,7 @@
}
// 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 @@
// Do not proceed if there was an undefined symbol.
if (HasError)
- return false;
+ return;
addCommonSymbols(CommonSymbols);
addCopyRelSymbols(CopyRelSymbols);
@@ -1116,7 +1118,6 @@
if (isOutputDynamic())
Out<ELFT>::Dynamic->finalize();
- return true;
}
template <class ELFT> bool Writer<ELFT>::needsGot() {
@@ -1533,16 +1534,14 @@
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.