Skip to content

Cherry pick PR #7847 into stable/20230725 #7910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions llvm/lib/MCCAS/MCCASObjectV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/MCCAS/MCCASDebugV1.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MCCAS/MCCASDebugV1.h"
#include "llvm/Support/BinaryStreamWriter.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/EndianStream.h"
#include <memory>
Expand Down Expand Up @@ -1893,7 +1894,13 @@ struct DIEDataWriter : public DataWriter {
/// is described by some DIEAbbrevRef block.
struct DistinctDataWriter : public DataWriter {
Expected<DIEDistinctDataRef> getCASNode(MCCASBuilder &CASBuilder) {
return DIEDistinctDataRef::create(CASBuilder, toStringRef(Data));
SmallVector<uint8_t> CompressedBuff;
compression::zlib::compress(arrayRefFromStringRef(toStringRef(Data)),
CompressedBuff);
// Reserve 8 bytes for ULEB to store the size of the uncompressed data.
CompressedBuff.append(8, 0);
encodeULEB128(Data.size(), CompressedBuff.end() - 8, 8 /*Pad to*/);
return DIEDistinctDataRef::create(CASBuilder, toStringRef(CompressedBuff));
}
};

Expand Down Expand Up @@ -3401,7 +3408,16 @@ Error mccasformats::v1::visitDebugInfo(
return LoadedTopRef.takeError();

StringRef DistinctData = LoadedTopRef->DistinctData.getData();
BinaryStreamReader DistinctReader(DistinctData, support::endianness::little);
ArrayRef<uint8_t> BuffRef = arrayRefFromStringRef(DistinctData);
auto UncompressedSize = decodeULEB128(BuffRef.data() + BuffRef.size() - 8);
BuffRef = BuffRef.drop_back(8);
SmallVector<uint8_t> OutBuff;
if (auto E =
compression::zlib::decompress(BuffRef, OutBuff, UncompressedSize))
return E;
auto UncompressedDistinctData = toStringRef(OutBuff);
BinaryStreamReader DistinctReader(UncompressedDistinctData,
support::endianness::little);
ArrayRef<char> HeaderData;

auto BeginOffset = DistinctReader.getOffset();
Expand All @@ -3423,8 +3439,9 @@ Error mccasformats::v1::visitDebugInfo(
HeaderCallback(toStringRef(HeaderData));

append_range(TotAbbrevEntries, LoadedTopRef->AbbrevEntries);
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, DistinctData,
HeaderCallback, StartTagCallback, AttrCallback,
EndTagCallback, NewBlockCallback};
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader,
UncompressedDistinctData, HeaderCallback,
StartTagCallback, AttrCallback,
EndTagCallback, NewBlockCallback};
return Visitor.visitDIERef(LoadedTopRef->RootDIE);
}