summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
index b8c739627c4..0ec7a40301d 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
@@ -139,7 +139,7 @@ private:
uint32_t loadCommandsSize(uint32_t &count);
void buildFileOffsets();
void writeMachHeader();
- std::error_code writeLoadCommands();
+ llvm::Error writeLoadCommands();
void writeSectionContent();
void writeRelocations();
void writeSymbolTable();
@@ -179,8 +179,8 @@ private:
};
template <typename T>
- std::error_code writeSingleSegmentLoadCommand(uint8_t *&lc);
- template <typename T> std::error_code writeSegmentLoadCommands(uint8_t *&lc);
+ llvm::Error writeSingleSegmentLoadCommand(uint8_t *&lc);
+ template <typename T> llvm::Error writeSegmentLoadCommands(uint8_t *&lc);
uint32_t pointerAlign(uint32_t value);
static StringRef dyldPath();
@@ -628,7 +628,7 @@ uint32_t MachOFileLayout::indirectSymbolElementSize(const Section &sect) {
}
template <typename T>
-std::error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {
+llvm::Error MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {
typename T::command* seg = reinterpret_cast<typename T::command*>(lc);
seg->cmd = T::LC;
seg->cmdsize = sizeof(typename T::command)
@@ -668,11 +668,11 @@ std::error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {
++sout;
}
lc = next;
- return std::error_code();
+ return llvm::Error();
}
template <typename T>
-std::error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {
+llvm::Error MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {
uint32_t indirectSymRunningIndex = 0;
for (const Segment &seg : _file.segments) {
// Link edit has no sections and a custom range of address, so handle it
@@ -738,7 +738,7 @@ std::error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {
}
lc = reinterpret_cast<uint8_t*>(next);
}
- return std::error_code();
+ return llvm::Error();
}
static void writeVersionMinLoadCommand(const NormalizedFile &_file,
@@ -773,15 +773,17 @@ static void writeVersionMinLoadCommand(const NormalizedFile &_file,
lc += sizeof(version_min_command);
}
-std::error_code MachOFileLayout::writeLoadCommands() {
- std::error_code ec;
+llvm::Error MachOFileLayout::writeLoadCommands() {
uint8_t *lc = &_buffer[_startOfLoadCommands];
if (_file.fileType == llvm::MachO::MH_OBJECT) {
// Object files have one unnamed segment which holds all sections.
- if (_is64)
- ec = writeSingleSegmentLoadCommand<MachO64Trait>(lc);
- else
- ec = writeSingleSegmentLoadCommand<MachO32Trait>(lc);
+ if (_is64) {
+ if (auto ec = writeSingleSegmentLoadCommand<MachO64Trait>(lc))
+ return std::move(ec);
+ } else {
+ if (auto ec = writeSingleSegmentLoadCommand<MachO32Trait>(lc))
+ return std::move(ec);
+ }
// Add LC_SYMTAB with symbol table info
symtab_command* st = reinterpret_cast<symtab_command*>(lc);
st->cmd = LC_SYMTAB;
@@ -824,10 +826,13 @@ std::error_code MachOFileLayout::writeLoadCommands() {
}
} else {
// Final linked images have sections under segments.
- if (_is64)
- ec = writeSegmentLoadCommands<MachO64Trait>(lc);
- else
- ec = writeSegmentLoadCommands<MachO32Trait>(lc);
+ if (_is64) {
+ if (auto ec = writeSegmentLoadCommands<MachO64Trait>(lc))
+ return std::move(ec);
+ } else {
+ if (auto ec = writeSegmentLoadCommands<MachO32Trait>(lc))
+ return std::move(ec);
+ }
// Add LC_ID_DYLIB command for dynamic libraries.
if (_file.fileType == llvm::MachO::MH_DYLIB) {
@@ -1012,7 +1017,7 @@ std::error_code MachOFileLayout::writeLoadCommands() {
lc += sizeof(linkedit_data_command);
}
}
- return ec;
+ return llvm::Error();
}
void MachOFileLayout::writeSectionContent() {
@@ -1475,9 +1480,8 @@ llvm::Error MachOFileLayout::writeBinary(StringRef path) {
// Write content.
_buffer = fob->getBufferStart();
writeMachHeader();
- std::error_code ec = writeLoadCommands();
- if (ec)
- return llvm::errorCodeToError(ec);
+ if (auto ec = writeLoadCommands())
+ return std::move(ec);
writeSectionContent();
writeLinkEditContent();
fob->commit();
OpenPOWER on IntegriCloud