diff options
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Object/XCOFFObjectFile.cpp | 5 |
4 files changed, 18 insertions, 23 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index ccb861cb187..854664e679d 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -292,13 +292,13 @@ uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const { return getSectionSize(toSec(Ref)); } -std::error_code COFFObjectFile::getSectionContents(DataRefImpl Ref, - StringRef &Result) const { +Expected<ArrayRef<uint8_t>> +COFFObjectFile::getSectionContents(DataRefImpl Ref) const { const coff_section *Sec = toSec(Ref); ArrayRef<uint8_t> Res; - std::error_code EC = getSectionContents(Sec, Res); - Result = StringRef(reinterpret_cast<const char*>(Res.data()), Res.size()); - return EC; + if (Error E = getSectionContents(Sec, Res)) + return std::move(E); + return Res; } uint64_t COFFObjectFile::getSectionAlignment(DataRefImpl Ref) const { @@ -1118,22 +1118,21 @@ uint64_t COFFObjectFile::getSectionSize(const coff_section *Sec) const { return Sec->SizeOfRawData; } -std::error_code -COFFObjectFile::getSectionContents(const coff_section *Sec, - ArrayRef<uint8_t> &Res) const { +Error COFFObjectFile::getSectionContents(const coff_section *Sec, + ArrayRef<uint8_t> &Res) const { // In COFF, a virtual section won't have any in-file // content, so the file pointer to the content will be zero. if (Sec->PointerToRawData == 0) - return std::error_code(); + return Error::success(); // The only thing that we need to verify is that the contents is contained // within the file bounds. We don't need to make sure it doesn't cover other // data, as there's nothing that says that is not allowed. uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData; uint32_t SectionSize = getSectionSize(Sec); if (checkOffset(Data, ConStart, SectionSize)) - return object_error::parse_failed; + return make_error<BinaryError>(); Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize); - return std::error_code(); + return Error::success(); } const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const { diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 1aa57bbbc76..d8bcf10f075 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1907,8 +1907,8 @@ uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const { return SectSize; } -std::error_code MachOObjectFile::getSectionContents(DataRefImpl Sec, - StringRef &Res) const { +Expected<ArrayRef<uint8_t>> +MachOObjectFile::getSectionContents(DataRefImpl Sec) const { uint32_t Offset; uint64_t Size; @@ -1922,8 +1922,7 @@ std::error_code MachOObjectFile::getSectionContents(DataRefImpl Sec, Size = Sect.size; } - Res = this->getData().substr(Offset, Size); - return std::error_code(); + return arrayRefFromStringRef(getData().substr(Offset, Size)); } uint64_t MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const { diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 1c56ee6652a..82aa1830dce 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -1427,14 +1427,12 @@ uint64_t WasmObjectFile::getSectionSize(DataRefImpl Sec) const { return S.Content.size(); } -std::error_code WasmObjectFile::getSectionContents(DataRefImpl Sec, - StringRef &Res) const { +Expected<ArrayRef<uint8_t>> +WasmObjectFile::getSectionContents(DataRefImpl Sec) const { const WasmSection &S = Sections[Sec.d.a]; // This will never fail since wasm sections can never be empty (user-sections // must have a name and non-user sections each have a defined structure). - Res = StringRef(reinterpret_cast<const char *>(S.Content.data()), - S.Content.size()); - return std::error_code(); + return S.Content; } uint64_t WasmObjectFile::getSectionAlignment(DataRefImpl Sec) const { diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp index 2a456538966..db57fbad002 100644 --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -137,10 +137,9 @@ uint64_t XCOFFObjectFile::getSectionSize(DataRefImpl Sec) const { return toSection(Sec)->SectionSize; } -std::error_code XCOFFObjectFile::getSectionContents(DataRefImpl Sec, - StringRef &Res) const { +Expected<ArrayRef<uint8_t>> +XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const { llvm_unreachable("Not yet implemented!"); - return std::error_code(); } uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const { |