From b98f504850123e345d0470cb0bfec67eb6e7a679 Mon Sep 17 00:00:00 2001 From: Paul Semel Date: Wed, 11 Jul 2018 10:00:29 +0000 Subject: [llvm-readobj] Add -hex-dump (-x) option Differential Revision: https://reviews.llvm.org/D48281 llvm-svn: 336782 --- llvm/lib/Object/MachOObjectFile.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 731ff4e01fd..e422903f280 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1939,6 +1939,27 @@ uint64_t MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const { return uint64_t(1) << Align; } +Expected MachOObjectFile::getSection(unsigned SectionIndex) const { + if (SectionIndex < 1 || SectionIndex > Sections.size()) + return malformedError("bad section index: " + Twine((int)SectionIndex)); + + DataRefImpl DRI; + DRI.d.a = SectionIndex - 1; + return SectionRef(DRI, this); +} + +Expected MachOObjectFile::getSection(StringRef SectionName) const { + StringRef SecName; + for (const SectionRef &Section : sections()) { + if (std::error_code E = Section.getName(SecName)) + return errorCodeToError(E); + if (SecName == SectionName) { + return Section; + } + } + return errorCodeToError(object_error::parse_failed); +} + bool MachOObjectFile::isSectionCompressed(DataRefImpl Sec) const { return false; } -- cgit v1.2.3