Skip to content

Do not use zlib compression when it isn't available. #7929

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 1 commit into from
Jan 4, 2024
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
25 changes: 13 additions & 12 deletions llvm/lib/MCCAS/MCCASObjectV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1901,13 +1901,17 @@ struct DIEDataWriter : public DataWriter {
/// is described by some DIEAbbrevRef block.
struct DistinctDataWriter : public DataWriter {
Expected<DIEDistinctDataRef> getCASNode(MCCASBuilder &CASBuilder) {
#if LLVM_ENABLE_ZLIB
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));
#else
return DIEDistinctDataRef::create(CASBuilder, toStringRef(Data));
#endif
}
};

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

StringRef DistinctData = LoadedTopRef->DistinctData.getData();
#if LLVM_ENABLE_ZLIB
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,
endianness::little);
DistinctData = toStringRef(OutBuff);
BinaryStreamReader DistinctReader(DistinctData, endianness::little);
#else
BinaryStreamReader DistinctReader(DistinctData, endianness::little);
#endif
ArrayRef<char> HeaderData;

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

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