aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2024-03-10 12:37:50 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-06 20:14:25 +0000
commit4c2d3b022a1d543dbbff75a0c53e8d3d7242216d (patch)
tree2cbf757a507afe2113432d167f1464c3d457674f /contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp
parent56727255ad47072ec2cc81b4ae728a099697b0e4 (diff)
parent8b885620ff1b22914b6fac738d7b2874d94e7543 (diff)
downloadsrc-4c2d3b022a1d543dbbff75a0c53e8d3d7242216d.tar.gz
src-4c2d3b022a1d543dbbff75a0c53e8d3d7242216d.zip
Diffstat (limited to 'contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp')
-rw-r--r--contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp b/contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp
index 59060ac217e3..0d3fea71aafd 100644
--- a/contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/contrib/llvm-project/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -14,6 +14,7 @@
#include "ObjDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/Archive.h"
+#include "llvm/Object/Decompressor.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
@@ -142,8 +143,23 @@ getSectionRefsByNameOrIndex(const object::ObjectFile &Obj,
return Ret;
}
+static void maybeDecompress(const object::ObjectFile &Obj,
+ StringRef SectionName, StringRef &SectionContent,
+ SmallString<0> &Out) {
+ Expected<object::Decompressor> Decompressor = object::Decompressor::create(
+ SectionName, SectionContent, Obj.isLittleEndian(), Obj.is64Bit());
+ if (!Decompressor)
+ reportWarning(Decompressor.takeError(), Obj.getFileName());
+ else if (auto Err = Decompressor->resizeAndDecompress(Out))
+ reportWarning(std::move(Err), Obj.getFileName());
+ else
+ SectionContent = Out;
+}
+
void ObjDumper::printSectionsAsString(const object::ObjectFile &Obj,
- ArrayRef<std::string> Sections) {
+ ArrayRef<std::string> Sections,
+ bool Decompress) {
+ SmallString<0> Out;
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
@@ -156,12 +172,16 @@ void ObjDumper::printSectionsAsString(const object::ObjectFile &Obj,
StringRef SectionContent =
unwrapOrError(Obj.getFileName(), Section.getContents());
+ if (Decompress && Section.isCompressed())
+ maybeDecompress(Obj, SectionName, SectionContent, Out);
printAsStringList(SectionContent);
}
}
void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
- ArrayRef<std::string> Sections) {
+ ArrayRef<std::string> Sections,
+ bool Decompress) {
+ SmallString<0> Out;
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
@@ -174,6 +194,8 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
StringRef SectionContent =
unwrapOrError(Obj.getFileName(), Section.getContents());
+ if (Decompress && Section.isCompressed())
+ maybeDecompress(Obj, SectionName, SectionContent, Out);
const uint8_t *SecContent = SectionContent.bytes_begin();
const uint8_t *SecEnd = SecContent + SectionContent.size();