diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index db1586161bce..5d4ee887ea46 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -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 void Writer::run() { if (!Config->DiscardAll) copyLocalSymbols(); addReservedSymbols(); - if (!createSections()) + createSections(); + if (HasError) return; if (Config->Relocatable) { @@ -228,7 +229,8 @@ template void Writer::run() { fixAbsoluteSymbols(); } - if (!openFile()) + openFile(); + if (HasError) return; writeHeader(); writeSections(); @@ -959,7 +961,7 @@ template static void sortCtorsDtors(OutputSectionBase *S) { } // Create output section objects and add them to OutputSections. -template bool Writer::createSections() { +template void Writer::createSections() { OutputSections.push_back(Out::ElfHeader); if (!Config->Relocatable) OutputSections.push_back(Out::ProgramHeaders); @@ -1082,7 +1084,7 @@ template bool Writer::createSections() { // Do not proceed if there was an undefined symbol. if (HasError) - return false; + return; addCommonSymbols(CommonSymbols); addCopyRelSymbols(CopyRelSymbols); @@ -1116,7 +1118,6 @@ template bool Writer::createSections() { if (isOutputDynamic()) Out::Dynamic->finalize(); - return true; } template bool Writer::needsGot() { @@ -1533,16 +1534,14 @@ template void Writer::writeHeader() { Sec->writeHeaderTo(++SHdrs); } -template bool Writer::openFile() { +template void Writer::openFile() { ErrorOr> 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.