diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-14 18:58:48 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:03:59 +0000 |
commit | 753f127f3ace09432b2baeffd71a308760641a62 (patch) | |
tree | 97694ab339c0ca6145ebb429c7505019565b9a60 /contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp | |
parent | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (diff) | |
parent | 1f917f69ff07f09b6dbb670971f57f8efe718b84 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp index b241bd817ff5..f0e4f91cd347 100644 --- a/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp +++ b/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObject.cpp @@ -463,13 +463,12 @@ Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) { ? (ZlibGnuMagic.size() + sizeof(Sec.Size)) : sizeof(Elf_Chdr_Impl<ELFT>); - StringRef CompressedContent( - reinterpret_cast<const char *>(Sec.OriginalData.data()) + DataOffset, - Sec.OriginalData.size() - DataOffset); - - SmallVector<char, 128> DecompressedContent; - if (Error Err = zlib::uncompress(CompressedContent, DecompressedContent, - static_cast<size_t>(Sec.Size))) + ArrayRef<uint8_t> CompressedContent(Sec.OriginalData.data() + DataOffset, + Sec.OriginalData.size() - DataOffset); + SmallVector<uint8_t, 128> DecompressedContent; + if (Error Err = + compression::zlib::uncompress(CompressedContent, DecompressedContent, + static_cast<size_t>(Sec.Size))) return createStringError(errc::invalid_argument, "'" + Sec.Name + "': " + toString(std::move(Err))); @@ -544,9 +543,7 @@ CompressedSection::CompressedSection(const SectionBase &Sec, DebugCompressionType CompressionType) : SectionBase(Sec), CompressionType(CompressionType), DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) { - zlib::compress(StringRef(reinterpret_cast<const char *>(OriginalData.data()), - OriginalData.size()), - CompressedData); + compression::zlib::compress(OriginalData, CompressedData); assert(CompressionType != DebugCompressionType::None); Flags |= ELF::SHF_COMPRESSED; @@ -2643,9 +2640,12 @@ Error BinaryWriter::finalize() { // MinAddr will be skipped. uint64_t MinAddr = UINT64_MAX; for (SectionBase &Sec : Obj.allocSections()) { + // If Sec's type is changed from SHT_NOBITS due to --set-section-flags, + // Offset may not be aligned. Align it to max(Align, 1). if (Sec.ParentSegment != nullptr) - Sec.Addr = - Sec.Offset - Sec.ParentSegment->Offset + Sec.ParentSegment->PAddr; + Sec.Addr = alignTo(Sec.Offset - Sec.ParentSegment->Offset + + Sec.ParentSegment->PAddr, + std::max(Sec.Align, uint64_t(1))); if (Sec.Type != SHT_NOBITS && Sec.Size > 0) MinAddr = std::min(MinAddr, Sec.Addr); } |