summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object
diff options
context:
space:
mode:
authorPaul Semel <semelpaul@gmail.com>2018-07-11 10:00:29 +0000
committerPaul Semel <semelpaul@gmail.com>2018-07-11 10:00:29 +0000
commitb98f504850123e345d0470cb0bfec67eb6e7a679 (patch)
treefe343e53812af6f8103ff323528460228556ae26 /llvm/lib/Object
parent5260c9efc87ea62bd40c47cc65d8e9648a649d42 (diff)
downloadbcm5719-llvm-b98f504850123e345d0470cb0bfec67eb6e7a679.tar.gz
bcm5719-llvm-b98f504850123e345d0470cb0bfec67eb6e7a679.zip
[llvm-readobj] Add -hex-dump (-x) option
Differential Revision: https://reviews.llvm.org/D48281 llvm-svn: 336782
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r--llvm/lib/Object/COFFObjectFile.cpp15
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp21
2 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index e622c17ca3e..26194888ac0 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -979,6 +979,21 @@ std::error_code COFFObjectFile::getSection(int32_t Index,
return object_error::parse_failed;
}
+std::error_code COFFObjectFile::getSection(StringRef SectionName,
+ const coff_section *&Result) const {
+ Result = nullptr;
+ StringRef SecName;
+ for (const SectionRef &Section : sections()) {
+ if (std::error_code E = Section.getName(SecName))
+ return E;
+ if (SecName == SectionName) {
+ Result = getCOFFSection(Section);
+ return std::error_code();
+ }
+ }
+ return object_error::parse_failed;
+}
+
std::error_code COFFObjectFile::getString(uint32_t Offset,
StringRef &Result) const {
if (StringTableSize <= 4)
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<SectionRef> 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<SectionRef> 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;
}
OpenPOWER on IntegriCloud