<div dir="ltr">Hi Pete,<div><br></div><div>This patch is not clean in terms of -Wpessimizing-move. Can you compile with that flag? (I can do this for you, but I expect that you are going to submit more patches like this soon.)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 30, 2016 at 5:08 PM, Pete Cooper via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: pete<br>
Date: Wed Mar 30 19:08:16 2016<br>
New Revision: 264974<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=264974&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=264974&view=rev</a><br>
Log:<br>
Convert a few macho reader/writer helpers to new error handling. NFC.<br>
<br>
These methods were responsible for some of the few remaining calls<br>
to llvm::errorCodeToError. Converting them makes us have more Error's<br>
in the api and fewer error_code's.<br>
<br>
Modified:<br>
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp<br>
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp?rev=264974&r1=264973&r2=264974&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp?rev=264974&r1=264973&r2=264974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp Wed Mar 30 19:08:16 2016<br>
@@ -53,7 +53,7 @@ namespace mach_o {<br>
namespace normalized {<br>
<br>
// Utility to call a lambda expression on each load command.<br>
-static std::error_code forEachLoadCommand(<br>
+static llvm::Error forEachLoadCommand(<br>
StringRef lcRange, unsigned lcCount, bool isBig, bool is64,<br>
std::function<bool(uint32_t cmd, uint32_t size, const char *lc)> func) {<br>
const char* p = lcRange.begin();<br>
@@ -67,15 +67,15 @@ static std::error_code forEachLoadComman<br>
slc = &lcCopy;<br>
}<br>
if ( (p + slc->cmdsize) > lcRange.end() )<br>
- return make_error_code(llvm::errc::executable_format_error);<br>
+ return llvm::make_error<GenericError>("Load command exceeds range");<br>
<br>
if (func(slc->cmd, slc->cmdsize, p))<br>
- return std::error_code();<br>
+ return llvm::Error();<br>
<br>
p += slc->cmdsize;<br>
}<br>
<br>
- return std::error_code();<br>
+ return llvm::Error();<br>
}<br>
<br>
static std::error_code appendRelocations(Relocations &relocs, StringRef buffer,<br>
@@ -257,9 +257,9 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
// Pre-scan load commands looking for indirect symbol table.<br>
uint32_t indirectSymbolTableOffset = 0;<br>
uint32_t indirectSymbolTableCount = 0;<br>
- std::error_code ec = forEachLoadCommand(lcRange, lcCount, isBig, is64,<br>
- [&](uint32_t cmd, uint32_t size,<br>
- const char *lc) -> bool {<br>
+ auto ec = forEachLoadCommand(lcRange, lcCount, isBig, is64,<br>
+ [&](uint32_t cmd, uint32_t size,<br>
+ const char *lc) -> bool {<br>
if (cmd == LC_DYSYMTAB) {<br>
const dysymtab_command *d = reinterpret_cast<const dysymtab_command*>(lc);<br>
indirectSymbolTableOffset = read32(&d->indirectsymoff, isBig);<br>
@@ -269,7 +269,7 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
return false;<br>
});<br>
if (ec)<br>
- return llvm::errorCodeToError(ec);<br>
+ return std::move(ec);<br>
<br>
// Walk load commands looking for segments/sections and the symbol table.<br>
const data_in_code_entry *dataInCode = nullptr;<br>
@@ -485,7 +485,7 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
return false;<br>
});<br>
if (ec)<br>
- return llvm::errorCodeToError(ec);<br>
+ return std::move(ec);<br>
<br>
if (dataInCode) {<br>
// Convert on-disk data_in_code_entry array to DataInCode vector.<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=264974&r1=264973&r2=264974&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=264974&r1=264973&r2=264974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Wed Mar 30 19:08:16 2016<br>
@@ -139,7 +139,7 @@ private:<br>
uint32_t loadCommandsSize(uint32_t &count);<br>
void buildFileOffsets();<br>
void writeMachHeader();<br>
- std::error_code writeLoadCommands();<br>
+ llvm::Error writeLoadCommands();<br>
void writeSectionContent();<br>
void writeRelocations();<br>
void writeSymbolTable();<br>
@@ -179,8 +179,8 @@ private:<br>
};<br>
<br>
template <typename T><br>
- std::error_code writeSingleSegmentLoadCommand(uint8_t *&lc);<br>
- template <typename T> std::error_code writeSegmentLoadCommands(uint8_t *&lc);<br>
+ llvm::Error writeSingleSegmentLoadCommand(uint8_t *&lc);<br>
+ template <typename T> llvm::Error writeSegmentLoadCommands(uint8_t *&lc);<br>
<br>
uint32_t pointerAlign(uint32_t value);<br>
static StringRef dyldPath();<br>
@@ -628,7 +628,7 @@ uint32_t MachOFileLayout::indirectSymbol<br>
}<br>
<br>
template <typename T><br>
-std::error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {<br>
+llvm::Error MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {<br>
typename T::command* seg = reinterpret_cast<typename T::command*>(lc);<br>
seg->cmd = T::LC;<br>
seg->cmdsize = sizeof(typename T::command)<br>
@@ -668,11 +668,11 @@ std::error_code MachOFileLayout::writeSi<br>
++sout;<br>
}<br>
lc = next;<br>
- return std::error_code();<br>
+ return llvm::Error();<br>
}<br>
<br>
template <typename T><br>
-std::error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {<br>
+llvm::Error MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {<br>
uint32_t indirectSymRunningIndex = 0;<br>
for (const Segment &seg : _file.segments) {<br>
// Link edit has no sections and a custom range of address, so handle it<br>
@@ -738,7 +738,7 @@ std::error_code MachOFileLayout::writeSe<br>
}<br>
lc = reinterpret_cast<uint8_t*>(next);<br>
}<br>
- return std::error_code();<br>
+ return llvm::Error();<br>
}<br>
<br>
static void writeVersionMinLoadCommand(const NormalizedFile &_file,<br>
@@ -773,15 +773,17 @@ static void writeVersionMinLoadCommand(c<br>
lc += sizeof(version_min_command);<br>
}<br>
<br>
-std::error_code MachOFileLayout::writeLoadCommands() {<br>
- std::error_code ec;<br>
+llvm::Error MachOFileLayout::writeLoadCommands() {<br>
uint8_t *lc = &_buffer[_startOfLoadCommands];<br>
if (_file.fileType == llvm::MachO::MH_OBJECT) {<br>
// Object files have one unnamed segment which holds all sections.<br>
- if (_is64)<br>
- ec = writeSingleSegmentLoadCommand<MachO64Trait>(lc);<br>
- else<br>
- ec = writeSingleSegmentLoadCommand<MachO32Trait>(lc);<br>
+ if (_is64) {<br>
+ if (auto ec = writeSingleSegmentLoadCommand<MachO64Trait>(lc))<br>
+ return std::move(ec);<br>
+ } else {<br>
+ if (auto ec = writeSingleSegmentLoadCommand<MachO32Trait>(lc))<br>
+ return std::move(ec);<br>
+ }<br>
// Add LC_SYMTAB with symbol table info<br>
symtab_command* st = reinterpret_cast<symtab_command*>(lc);<br>
st->cmd = LC_SYMTAB;<br>
@@ -824,10 +826,13 @@ std::error_code MachOFileLayout::writeLo<br>
}<br>
} else {<br>
// Final linked images have sections under segments.<br>
- if (_is64)<br>
- ec = writeSegmentLoadCommands<MachO64Trait>(lc);<br>
- else<br>
- ec = writeSegmentLoadCommands<MachO32Trait>(lc);<br>
+ if (_is64) {<br>
+ if (auto ec = writeSegmentLoadCommands<MachO64Trait>(lc))<br>
+ return std::move(ec);<br>
+ } else {<br>
+ if (auto ec = writeSegmentLoadCommands<MachO32Trait>(lc))<br>
+ return std::move(ec);<br>
+ }<br>
<br>
// Add LC_ID_DYLIB command for dynamic libraries.<br>
if (_file.fileType == llvm::MachO::MH_DYLIB) {<br>
@@ -1012,7 +1017,7 @@ std::error_code MachOFileLayout::writeLo<br>
lc += sizeof(linkedit_data_command);<br>
}<br>
}<br>
- return ec;<br>
+ return llvm::Error();<br>
}<br>
<br>
void MachOFileLayout::writeSectionContent() {<br>
@@ -1475,9 +1480,8 @@ llvm::Error MachOFileLayout::writeBinary<br>
// Write content.<br>
_buffer = fob->getBufferStart();<br>
writeMachHeader();<br>
- std::error_code ec = writeLoadCommands();<br>
- if (ec)<br>
- return llvm::errorCodeToError(ec);<br>
+ if (auto ec = writeLoadCommands())<br>
+ return std::move(ec);<br>
writeSectionContent();<br>
writeLinkEditContent();<br>
fob->commit();<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>