aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/ELF.cpp
diff options
context:
space:
mode:
authorRahman Lavaee <rahmanl@google.com>2025-06-04 19:55:01 -0700
committerGitHub <noreply@github.com>2025-06-04 19:55:01 -0700
commitf6260daf30fdd0eca9b6f5447433da4386bd0e54 (patch)
tree6207f4b0b25a226bde273939ac4a8ea0d1ed51ec /llvm/lib/Object/ELF.cpp
parent8ca220f1ddc710ba334576563502733b2698f995 (diff)
downloadllvm-f6260daf30fdd0eca9b6f5447433da4386bd0e54.zip
llvm-f6260daf30fdd0eca9b6f5447433da4386bd0e54.tar.gz
llvm-f6260daf30fdd0eca9b6f5447433da4386bd0e54.tar.bz2
[SHT_LLVM_BB_ADDR_MAP] Support decompressing the SHT_LLVM_BB_ADDR_MAP section. (#142825)
Compression of SHT_LLVM_BB_ADDR_MAP with zstd can give 3X compression ratio, which is especially beneficial with PGO_analysis_map. To read the data back, we must decompress it. Though we can use llvm-objcopy to do this, it's much better to do this decompression internally in the library API.
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
-rw-r--r--llvm/lib/Object/ELF.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index dfc8acb..e6864ca 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -9,6 +9,7 @@
#include "llvm/Object/ELF.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/Object/Decompressor.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataExtractor.h"
@@ -782,6 +783,27 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
if (!ContentsOrErr)
return ContentsOrErr.takeError();
ArrayRef<uint8_t> Content = *ContentsOrErr;
+
+ // Decompress the section if needed.
+ std::unique_ptr<uint8_t[]> DecompressedContent;
+ if (Sec.sh_flags & llvm::ELF::SHF_COMPRESSED) {
+ Expected<StringRef> SectionNameOrErr = EF.getSectionName(Sec);
+ if (!SectionNameOrErr)
+ return SectionNameOrErr.takeError();
+ auto DecompressorOrErr =
+ Decompressor::create(*SectionNameOrErr, toStringRef(*ContentsOrErr),
+ EF.isLE(), ELFT::Is64Bits);
+ if (!DecompressorOrErr)
+ return DecompressorOrErr.takeError();
+ size_t DecompressedSize = DecompressorOrErr->getDecompressedSize();
+ DecompressedContent = std::make_unique<uint8_t[]>(DecompressedSize);
+ MutableArrayRef<uint8_t> DecompressedContentRef(DecompressedContent.get(),
+ DecompressedSize);
+ if (Error Err = DecompressorOrErr->decompress(DecompressedContentRef))
+ return std::move(Err);
+ Content = DecompressedContentRef;
+ }
+
DataExtractor Data(Content, EF.isLE(), ELFT::Is64Bits ? 8 : 4);
std::vector<BBAddrMap> FunctionEntries;