[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
This commit is contained in:
Jez Ng 2021-06-13 19:43:37 -04:00
parent c5c05ffa45
commit da24e6d43e
6 changed files with 43 additions and 43 deletions

View File

@ -24,7 +24,7 @@ class Defined;
// files that are labeled with the same segment and section name. This class // 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 // contains all such sections and writes the data from each section sequentially
// in the final binary. // in the final binary.
class ConcatOutputSection : public OutputSection { class ConcatOutputSection final : public OutputSection {
public: public:
explicit ConcatOutputSection(StringRef name) explicit ConcatOutputSection(StringRef name)
: OutputSection(ConcatKind, name) {} : OutputSection(ConcatKind, name) {}

View File

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

View File

@ -76,7 +76,7 @@ private:
// ConcatInputSections are combined into (Concat)OutputSections through simple // ConcatInputSections are combined into (Concat)OutputSections through simple
// concatenation, in contrast with literal sections which may have their // concatenation, in contrast with literal sections which may have their
// contents merged before output. // contents merged before output.
class ConcatInputSection : public InputSection { class ConcatInputSection final : public InputSection {
public: public:
ConcatInputSection(StringRef segname, StringRef name) ConcatInputSection(StringRef segname, StringRef name)
: InputSection(ConcatKind, segname, 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 // ld64 is more conservative and does not do that. This was mostly done for
// implementation simplicity; if we find programs that need the more // implementation simplicity; if we find programs that need the more
// conservative behavior we can certainly implement that. // conservative behavior we can certainly implement that.
class CStringInputSection : public InputSection { class CStringInputSection final : public InputSection {
public: public:
CStringInputSection(StringRef segname, StringRef name, InputFile *file, CStringInputSection(StringRef segname, StringRef name, InputFile *file,
ArrayRef<uint8_t> data, uint32_t align, uint32_t flags) ArrayRef<uint8_t> data, uint32_t align, uint32_t flags)
@ -168,7 +168,7 @@ public:
std::vector<StringPiece> pieces; std::vector<StringPiece> pieces;
}; };
class WordLiteralInputSection : public InputSection { class WordLiteralInputSection final : public InputSection {
public: public:
WordLiteralInputSection(StringRef segname, StringRef name, InputFile *file, WordLiteralInputSection(StringRef segname, StringRef name, InputFile *file,
ArrayRef<uint8_t> data, uint32_t align, ArrayRef<uint8_t> data, uint32_t align,

View File

@ -774,7 +774,7 @@ uint32_t SymtabSection::getNumSymbols() const {
} }
// This serves to hide (type-erase) the template parameter from SymtabSection. // 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: public:
SymtabSectionImpl(StringTableSection &stringTableSection) SymtabSectionImpl(StringTableSection &stringTableSection)
: SymtabSection(stringTableSection) {} : SymtabSection(stringTableSection) {}

View File

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

View File

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