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
This commit is contained in:
Rui Ueyama 2016-04-01 17:24:19 +00:00
parent 8ecc2ec0e3
commit f7f52ef65d
1 changed files with 12 additions and 13 deletions

View File

@ -62,7 +62,7 @@ private:
void copyLocalSymbols(); void copyLocalSymbols();
void addReservedSymbols(); void addReservedSymbols();
bool createSections(); void createSections();
void addPredefinedSections(); void addPredefinedSections();
bool needsGot(); bool needsGot();
@ -78,7 +78,7 @@ private:
void setPhdrs(); void setPhdrs();
void fixSectionAlignments(); void fixSectionAlignments();
void fixAbsoluteSymbols(); void fixAbsoluteSymbols();
bool openFile(); void openFile();
void writeHeader(); void writeHeader();
void writeSections(); void writeSections();
void writeBuildId(); void writeBuildId();
@ -214,7 +214,8 @@ template <class ELFT> void Writer<ELFT>::run() {
if (!Config->DiscardAll) if (!Config->DiscardAll)
copyLocalSymbols(); copyLocalSymbols();
addReservedSymbols(); addReservedSymbols();
if (!createSections()) createSections();
if (HasError)
return; return;
if (Config->Relocatable) { if (Config->Relocatable) {
@ -228,7 +229,8 @@ template <class ELFT> void Writer<ELFT>::run() {
fixAbsoluteSymbols(); fixAbsoluteSymbols();
} }
if (!openFile()) openFile();
if (HasError)
return; return;
writeHeader(); writeHeader();
writeSections(); writeSections();
@ -959,7 +961,7 @@ template <class ELFT> static void sortCtorsDtors(OutputSectionBase<ELFT> *S) {
} }
// Create output section objects and add them to OutputSections. // 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); OutputSections.push_back(Out<ELFT>::ElfHeader);
if (!Config->Relocatable) if (!Config->Relocatable)
OutputSections.push_back(Out<ELFT>::ProgramHeaders); OutputSections.push_back(Out<ELFT>::ProgramHeaders);
@ -1082,7 +1084,7 @@ template <class ELFT> bool Writer<ELFT>::createSections() {
// Do not proceed if there was an undefined symbol. // Do not proceed if there was an undefined symbol.
if (HasError) if (HasError)
return false; return;
addCommonSymbols(CommonSymbols); addCommonSymbols(CommonSymbols);
addCopyRelSymbols(CopyRelSymbols); addCopyRelSymbols(CopyRelSymbols);
@ -1116,7 +1118,6 @@ template <class ELFT> bool Writer<ELFT>::createSections() {
if (isOutputDynamic()) if (isOutputDynamic())
Out<ELFT>::Dynamic->finalize(); Out<ELFT>::Dynamic->finalize();
return true;
} }
template <class ELFT> bool Writer<ELFT>::needsGot() { template <class ELFT> bool Writer<ELFT>::needsGot() {
@ -1533,16 +1534,14 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
Sec->writeHeaderTo(++SHdrs); Sec->writeHeaderTo(++SHdrs);
} }
template <class ELFT> bool Writer<ELFT>::openFile() { template <class ELFT> void Writer<ELFT>::openFile() {
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Config->OutputFile, FileSize, FileOutputBuffer::create(Config->OutputFile, FileSize,
FileOutputBuffer::F_executable); FileOutputBuffer::F_executable);
if (!BufferOrErr) { if (BufferOrErr)
Buffer = std::move(*BufferOrErr);
else
error(BufferOrErr, "failed to open " + Config->OutputFile); error(BufferOrErr, "failed to open " + Config->OutputFile);
return false;
}
Buffer = std::move(*BufferOrErr);
return true;
} }
// Write section contents to a mmap'ed file. // Write section contents to a mmap'ed file.