[lld] da24e6d - [lld-macho][nfc] Add `final` to classes where possible

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 13 16:52:23 PDT 2021


Author: Jez Ng
Date: 2021-06-13T19:52:03-04:00
New Revision: da24e6d43e3fdc07aa84f55b35ec50f6b96545ad

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

LOG: [lld-macho][nfc] Add `final` to classes where possible

I wanted to see if we would get any perf wins out of this, but
it doesn't seem to be the case. But it still seems worth committing.

Reviewed By: MaskRay

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

Added: 
    

Modified: 
    lld/MachO/ConcatOutputSection.h
    lld/MachO/InputFiles.h
    lld/MachO/InputSection.h
    lld/MachO/SyntheticSections.cpp
    lld/MachO/SyntheticSections.h
    lld/MachO/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ConcatOutputSection.h b/lld/MachO/ConcatOutputSection.h
index 377431bb6a24..e26869408dfd 100644
--- a/lld/MachO/ConcatOutputSection.h
+++ b/lld/MachO/ConcatOutputSection.h
@@ -24,7 +24,7 @@ class Defined;
 // files that are labeled with the same segment and section name. This class
 // contains all such sections and writes the data from each section sequentially
 // in the final binary.
-class ConcatOutputSection : public OutputSection {
+class ConcatOutputSection final : public OutputSection {
 public:
   explicit ConcatOutputSection(StringRef name)
       : OutputSection(ConcatKind, name) {}

diff  --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 1b6d057b77fa..d3601ffd5a2c 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -96,7 +96,7 @@ class InputFile {
 };
 
 // .o file
-class ObjFile : public InputFile {
+class ObjFile final : public InputFile {
 public:
   ObjFile(MemoryBufferRef mb, uint32_t modTime, StringRef archiveName);
   static bool classof(const InputFile *f) { return f->kind() == ObjKind; }
@@ -121,14 +121,14 @@ class ObjFile : public InputFile {
 };
 
 // command-line -sectcreate file
-class OpaqueFile : public InputFile {
+class OpaqueFile final : public InputFile {
 public:
   OpaqueFile(MemoryBufferRef mb, StringRef segName, StringRef sectName);
   static bool classof(const InputFile *f) { return f->kind() == OpaqueKind; }
 };
 
 // .dylib or .tbd file
-class DylibFile : public InputFile {
+class DylibFile final : public InputFile {
 public:
   // Mach-O dylibs can re-export other dylibs as sub-libraries, meaning that the
   // symbols in those sub-libraries will be available under the umbrella
@@ -181,7 +181,7 @@ class DylibFile : public InputFile {
 };
 
 // .a file
-class ArchiveFile : public InputFile {
+class ArchiveFile final : public InputFile {
 public:
   explicit ArchiveFile(std::unique_ptr<llvm::object::Archive> &&file);
   static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }
@@ -194,7 +194,7 @@ class ArchiveFile : public InputFile {
   llvm::DenseSet<uint64_t> seen;
 };
 
-class BitcodeFile : public InputFile {
+class BitcodeFile final : public InputFile {
 public:
   explicit BitcodeFile(MemoryBufferRef mb);
   static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }

diff  --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index 24a1800a75e8..acf8c9d4a68d 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -76,7 +76,7 @@ class InputSection {
 // ConcatInputSections are combined into (Concat)OutputSections through simple
 // concatenation, in contrast with literal sections which may have their
 // contents merged before output.
-class ConcatInputSection : public InputSection {
+class ConcatInputSection final : public InputSection {
 public:
   ConcatInputSection(StringRef segname, StringRef name)
       : InputSection(ConcatKind, segname, name) {}
@@ -136,7 +136,7 @@ static_assert(sizeof(StringPiece) == 16, "StringPiece is too big!");
 // ld64 is more conservative and does not do that. This was mostly done for
 // implementation simplicity; if we find programs that need the more
 // conservative behavior we can certainly implement that.
-class CStringInputSection : public InputSection {
+class CStringInputSection final : public InputSection {
 public:
   CStringInputSection(StringRef segname, StringRef name, InputFile *file,
                       ArrayRef<uint8_t> data, uint32_t align, uint32_t flags)
@@ -168,7 +168,7 @@ class CStringInputSection : public InputSection {
   std::vector<StringPiece> pieces;
 };
 
-class WordLiteralInputSection : public InputSection {
+class WordLiteralInputSection final : public InputSection {
 public:
   WordLiteralInputSection(StringRef segname, StringRef name, InputFile *file,
                           ArrayRef<uint8_t> data, uint32_t align,

diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 5f2d446bbe89..9317d2e99072 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -774,7 +774,7 @@ uint32_t SymtabSection::getNumSymbols() const {
 }
 
 // This serves to hide (type-erase) the template parameter from SymtabSection.
-template <class LP> class SymtabSectionImpl : public SymtabSection {
+template <class LP> class SymtabSectionImpl final : public SymtabSection {
 public:
   SymtabSectionImpl(StringTableSection &stringTableSection)
       : SymtabSection(stringTableSection) {}

diff  --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h
index 4e3ea693ccc2..1e9bba72932f 100644
--- a/lld/MachO/SyntheticSections.h
+++ b/lld/MachO/SyntheticSections.h
@@ -81,7 +81,7 @@ class LinkEditSection : public SyntheticSection {
 };
 
 // The header of the Mach-O file, which must have a file offset of zero.
-class MachHeaderSection : public SyntheticSection {
+class MachHeaderSection final : public SyntheticSection {
 public:
   MachHeaderSection();
   bool isHidden() const override { return true; }
@@ -97,7 +97,7 @@ class MachHeaderSection : public SyntheticSection {
 
 // A hidden section that exists solely for the purpose of creating the
 // __PAGEZERO segment, which is used to catch null pointer dereferences.
-class PageZeroSection : public SyntheticSection {
+class PageZeroSection final : public SyntheticSection {
 public:
   PageZeroSection();
   bool isHidden() const override { return true; }
@@ -134,7 +134,7 @@ class NonLazyPointerSectionBase : public SyntheticSection {
   llvm::SetVector<const Symbol *> entries;
 };
 
-class GotSection : public NonLazyPointerSectionBase {
+class GotSection final : public NonLazyPointerSectionBase {
 public:
   GotSection()
       : NonLazyPointerSectionBase(segment_names::dataConst,
@@ -144,7 +144,7 @@ class GotSection : public NonLazyPointerSectionBase {
   }
 };
 
-class TlvPointerSection : public NonLazyPointerSectionBase {
+class TlvPointerSection final : public NonLazyPointerSectionBase {
 public:
   TlvPointerSection()
       : NonLazyPointerSectionBase(segment_names::data,
@@ -163,7 +163,7 @@ struct Location {
 // Stores rebase opcodes, which tell dyld where absolute addresses have been
 // encoded in the binary. If the binary is not loaded at its preferred address,
 // dyld has to rebase these addresses by adding an offset to them.
-class RebaseSection : public LinkEditSection {
+class RebaseSection final : public LinkEditSection {
 public:
   RebaseSection();
   void finalizeContents() override;
@@ -190,7 +190,7 @@ struct BindingEntry {
 };
 
 // Stores bind opcodes for telling dyld which symbols to load non-lazily.
-class BindingSection : public LinkEditSection {
+class BindingSection final : public LinkEditSection {
 public:
   BindingSection();
   void finalizeContents() override;
@@ -226,7 +226,7 @@ struct WeakBindingEntry {
 //   coalesce to a non-weak definition if one is found. Note that unlike the
 //   entries in the BindingSection, the bindings here only refer to these
 //   symbols by name, but do not specify which dylib to load them from.
-class WeakBindingSection : public LinkEditSection {
+class WeakBindingSection final : public LinkEditSection {
 public:
   WeakBindingSection();
   void finalizeContents() override;
@@ -287,7 +287,7 @@ class WeakBindingSection : public LinkEditSection {
 // appropriate symbol is found at runtime. However, the bound addresses will
 // still be written (non-lazily) into the LazyPointerSection.
 
-class StubsSection : public SyntheticSection {
+class StubsSection final : public SyntheticSection {
 public:
   StubsSection();
   uint64_t getSize() const override;
@@ -313,7 +313,7 @@ class StubsSection : public SyntheticSection {
   llvm::SetVector<Symbol *> entries;
 };
 
-class StubHelperSection : public SyntheticSection {
+class StubHelperSection final : public SyntheticSection {
 public:
   StubHelperSection();
   uint64_t getSize() const override;
@@ -328,7 +328,7 @@ class StubHelperSection : public SyntheticSection {
 
 // Note that this section may also be targeted by non-lazy bindings. In
 // particular, this happens when branch relocations target weak symbols.
-class LazyPointerSection : public SyntheticSection {
+class LazyPointerSection final : public SyntheticSection {
 public:
   LazyPointerSection();
   uint64_t getSize() const override;
@@ -336,7 +336,7 @@ class LazyPointerSection : public SyntheticSection {
   void writeTo(uint8_t *buf) const override;
 };
 
-class LazyBindingSection : public LinkEditSection {
+class LazyBindingSection final : public LinkEditSection {
 public:
   LazyBindingSection();
   void finalizeContents() override;
@@ -357,7 +357,7 @@ class LazyBindingSection : public LinkEditSection {
 };
 
 // Stores a trie that describes the set of exported symbols.
-class ExportSection : public LinkEditSection {
+class ExportSection final : public LinkEditSection {
 public:
   ExportSection();
   void finalizeContents() override;
@@ -372,7 +372,7 @@ class ExportSection : public LinkEditSection {
 };
 
 // Stores ULEB128 delta encoded addresses of functions.
-class FunctionStartsSection : public LinkEditSection {
+class FunctionStartsSection final : public LinkEditSection {
 public:
   FunctionStartsSection();
   void finalizeContents() override;
@@ -384,7 +384,7 @@ class FunctionStartsSection : public LinkEditSection {
 };
 
 // Stores the strings referenced by the symbol table.
-class StringTableSection : public LinkEditSection {
+class StringTableSection final : public LinkEditSection {
 public:
   StringTableSection();
   // Returns the start offset of the added string.
@@ -463,7 +463,7 @@ template <class LP> SymtabSection *makeSymtabSection(StringTableSection &);
 // contiguous sequences of symbol references. These references can be pointers
 // (e.g. those in the GOT and TLVP sections) or assembly sequences (e.g.
 // function stubs).
-class IndirectSymtabSection : public LinkEditSection {
+class IndirectSymtabSection final : public LinkEditSection {
 public:
   IndirectSymtabSection();
   void finalizeContents() override;
@@ -476,7 +476,7 @@ class IndirectSymtabSection : public LinkEditSection {
 };
 
 // The code signature comes at the very end of the linked output file.
-class CodeSignatureSection : public LinkEditSection {
+class CodeSignatureSection final : public LinkEditSection {
 public:
   static constexpr uint8_t blockSizeShift = 12;
   static constexpr size_t blockSize = (1 << blockSizeShift); // 4 KiB
@@ -498,7 +498,7 @@ class CodeSignatureSection : public LinkEditSection {
   void writeHashes(uint8_t *buf) const;
 };
 
-class BitcodeBundleSection : public SyntheticSection {
+class BitcodeBundleSection final : public SyntheticSection {
 public:
   BitcodeBundleSection();
   uint64_t getSize() const override { return xarSize; }
@@ -510,7 +510,7 @@ class BitcodeBundleSection : public SyntheticSection {
   uint64_t xarSize;
 };
 
-class CStringSection : public SyntheticSection {
+class CStringSection final : public SyntheticSection {
 public:
   CStringSection();
   void addInput(CStringInputSection *);
@@ -529,7 +529,7 @@ class CStringSection : public SyntheticSection {
  * This section contains deduplicated literal values. The 16-byte values are
  * laid out first, followed by the 8- and then the 4-byte ones.
  */
-class WordLiteralSection : public SyntheticSection {
+class WordLiteralSection final : public SyntheticSection {
 public:
   using UInt128 = std::pair<uint64_t, uint64_t>;
   // I don't think the standard guarantees the size of a pair, so let's make

diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 40f27faf9f1f..ebb2a5e8fa7b 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -78,7 +78,7 @@ class Writer {
 };
 
 // LC_DYLD_INFO_ONLY stores the offsets of symbol import/export information.
-class LCDyldInfo : public LoadCommand {
+class LCDyldInfo final : public LoadCommand {
 public:
   LCDyldInfo(RebaseSection *rebaseSection, BindingSection *bindingSection,
              WeakBindingSection *weakBindingSection,
@@ -123,7 +123,7 @@ class LCDyldInfo : public LoadCommand {
   ExportSection *exportSection;
 };
 
-class LCFunctionStarts : public LoadCommand {
+class LCFunctionStarts final : public LoadCommand {
 public:
   explicit LCFunctionStarts(FunctionStartsSection *functionStartsSection)
       : functionStartsSection(functionStartsSection) {}
@@ -142,7 +142,7 @@ class LCFunctionStarts : public LoadCommand {
   FunctionStartsSection *functionStartsSection;
 };
 
-class LCDysymtab : public LoadCommand {
+class LCDysymtab final : public LoadCommand {
 public:
   LCDysymtab(SymtabSection *symtabSection,
              IndirectSymtabSection *indirectSymtabSection)
@@ -170,7 +170,7 @@ class LCDysymtab : public LoadCommand {
   IndirectSymtabSection *indirectSymtabSection;
 };
 
-template <class LP> class LCSegment : public LoadCommand {
+template <class LP> class LCSegment final : public LoadCommand {
 public:
   LCSegment(StringRef name, OutputSegment *seg) : name(name), seg(seg) {}
 
@@ -226,7 +226,7 @@ template <class LP> class LCSegment : public LoadCommand {
   OutputSegment *seg;
 };
 
-class LCMain : public LoadCommand {
+class LCMain final : public LoadCommand {
   uint32_t getSize() const override {
     return sizeof(structs::entry_point_command);
   }
@@ -246,7 +246,7 @@ class LCMain : public LoadCommand {
   }
 };
 
-class LCSymtab : public LoadCommand {
+class LCSymtab final : public LoadCommand {
 public:
   LCSymtab(SymtabSection *symtabSection, StringTableSection *stringTableSection)
       : symtabSection(symtabSection), stringTableSection(stringTableSection) {}
@@ -271,7 +271,7 @@ class LCSymtab : public LoadCommand {
 //   * LC_LOAD_DYLIB
 //   * LC_ID_DYLIB
 //   * LC_REEXPORT_DYLIB
-class LCDylib : public LoadCommand {
+class LCDylib final : public LoadCommand {
 public:
   LCDylib(LoadCommandType type, StringRef path,
           uint32_t compatibilityVersion = 0, uint32_t currentVersion = 0)
@@ -311,7 +311,7 @@ class LCDylib : public LoadCommand {
 
 uint32_t LCDylib::instanceCount = 0;
 
-class LCLoadDylinker : public LoadCommand {
+class LCLoadDylinker final : public LoadCommand {
 public:
   uint32_t getSize() const override {
     return alignTo(sizeof(dylinker_command) + path.size() + 1, 8);
@@ -335,7 +335,7 @@ class LCLoadDylinker : public LoadCommand {
   const StringRef path = "/usr/lib/dyld";
 };
 
-class LCRPath : public LoadCommand {
+class LCRPath final : public LoadCommand {
 public:
   explicit LCRPath(StringRef path) : path(path) {}
 
@@ -359,7 +359,7 @@ class LCRPath : public LoadCommand {
   StringRef path;
 };
 
-class LCMinVersion : public LoadCommand {
+class LCMinVersion final : public LoadCommand {
 public:
   explicit LCMinVersion(const PlatformInfo &platformInfo)
       : platformInfo(platformInfo) {}
@@ -397,7 +397,7 @@ class LCMinVersion : public LoadCommand {
   const PlatformInfo &platformInfo;
 };
 
-class LCBuildVersion : public LoadCommand {
+class LCBuildVersion final : public LoadCommand {
 public:
   explicit LCBuildVersion(const PlatformInfo &platformInfo)
       : platformInfo(platformInfo) {}
@@ -432,7 +432,7 @@ class LCBuildVersion : public LoadCommand {
 // offsets to be calculated correctly. We resolve this circular paradox by
 // first writing an LC_UUID with an all-zero UUID, then updating the UUID with
 // its real value later.
-class LCUuid : public LoadCommand {
+class LCUuid final : public LoadCommand {
 public:
   uint32_t getSize() const override { return sizeof(uuid_command); }
 
@@ -465,7 +465,7 @@ class LCUuid : public LoadCommand {
   mutable uint8_t *uuidBuf;
 };
 
-template <class LP> class LCEncryptionInfo : public LoadCommand {
+template <class LP> class LCEncryptionInfo final : public LoadCommand {
 public:
   uint32_t getSize() const override {
     return sizeof(typename LP::encryption_info_command);
@@ -486,7 +486,7 @@ template <class LP> class LCEncryptionInfo : public LoadCommand {
   }
 };
 
-class LCCodeSignature : public LoadCommand {
+class LCCodeSignature final : public LoadCommand {
 public:
   LCCodeSignature(CodeSignatureSection *section) : section(section) {}
 


        


More information about the llvm-commits mailing list