[llvm] cce3521 - [llvm-objcopy] Simplify CompressedSection creation. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 23:15:21 PDT 2022


Author: Fangrui Song
Date: 2022-03-14T23:15:15-07:00
New Revision: cce3521020011b65b703549850d57191cbc91aee

URL: https://github.com/llvm/llvm-project/commit/cce3521020011b65b703549850d57191cbc91aee
DIFF: https://github.com/llvm/llvm-project/commit/cce3521020011b65b703549850d57191cbc91aee.diff

LOG: [llvm-objcopy] Simplify CompressedSection creation. NFC

Remove Expected<CompressedSection> factory functions in favor of constructors
now that zlib::compress returns void (D121512).

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D121644

Added: 
    

Modified: 
    llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
    llvm/lib/ObjCopy/ELF/ELFObject.cpp
    llvm/lib/ObjCopy/ELF/ELFObject.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index 756f6ccbd288e..bbbbd9f990073 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -509,12 +509,8 @@ static Error replaceAndRemoveSections(const CommonConfig &Config,
     if (Error Err = replaceDebugSections(
             Obj, isCompressable,
             [&Config, &Obj](const SectionBase *S) -> Expected<SectionBase *> {
-              Expected<CompressedSection> NewSection =
-                  CompressedSection::create(*S, Config.CompressionType);
-              if (!NewSection)
-                return NewSection.takeError();
-
-              return &Obj.addSection<CompressedSection>(std::move(*NewSection));
+              return &Obj.addSection<CompressedSection>(
+                  CompressedSection(*S, Config.CompressionType));
             }))
       return Err;
   } else if (Config.DecompressDebugSections) {

diff  --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index cb5c82c2e337c..fce46beed5a38 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -545,18 +545,6 @@ Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
   return Error::success();
 }
 
-Expected<CompressedSection>
-CompressedSection::create(const SectionBase &Sec,
-                          DebugCompressionType CompressionType) {
-  return CompressedSection(Sec, CompressionType);
-}
-Expected<CompressedSection>
-CompressedSection::create(ArrayRef<uint8_t> CompressedData,
-                          uint64_t DecompressedSize,
-                          uint64_t DecompressedAlign) {
-  return CompressedSection(CompressedData, DecompressedSize, DecompressedAlign);
-}
-
 CompressedSection::CompressedSection(const SectionBase &Sec,
                                      DebugCompressionType CompressionType)
     : SectionBase(Sec), CompressionType(CompressionType),
@@ -1754,12 +1742,8 @@ Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
       uint64_t DecompressedSize, DecompressedAlign;
       std::tie(DecompressedSize, DecompressedAlign) =
           getDecompressedSizeAndAlignment<ELFT>(*Data);
-      Expected<CompressedSection> NewSection =
-          CompressedSection::create(*Data, DecompressedSize, DecompressedAlign);
-      if (!NewSection)
-        return NewSection.takeError();
-
-      return Obj.addSection<CompressedSection>(std::move(*NewSection));
+      return Obj.addSection<CompressedSection>(
+          CompressedSection(*Data, DecompressedSize, DecompressedAlign));
     }
 
     return Obj.addSection<Section>(*Data);

diff  --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h
index 80f043d8d6321..b72133a0c5d7c 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.h
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.h
@@ -542,11 +542,10 @@ class CompressedSection : public SectionBase {
   SmallVector<char, 128> CompressedData;
 
 public:
-  static Expected<CompressedSection>
-  create(const SectionBase &Sec, DebugCompressionType CompressionType);
-  static Expected<CompressedSection> create(ArrayRef<uint8_t> CompressedData,
-                                            uint64_t DecompressedSize,
-                                            uint64_t DecompressedAlign);
+  CompressedSection(const SectionBase &Sec,
+                    DebugCompressionType CompressionType);
+  CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize,
+                    uint64_t DecompressedAlign);
 
   uint64_t getDecompressedSize() const { return DecompressedSize; }
   uint64_t getDecompressedAlign() const { return DecompressedAlign; }
@@ -558,12 +557,6 @@ class CompressedSection : public SectionBase {
     return (S->OriginalFlags & ELF::SHF_COMPRESSED) ||
            (StringRef(S->Name).startswith(".zdebug"));
   }
-
-private:
-  CompressedSection(const SectionBase &Sec,
-                    DebugCompressionType CompressionType);
-  CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize,
-                    uint64_t DecompressedAlign);
 };
 
 class DecompressedSection : public SectionBase {


        


More information about the llvm-commits mailing list