[lld-macho][nfc] Misc code cleanup
authorJez Ng <jezng@fb.com>
Tue, 25 May 2021 18:57:58 +0000 (14:57 -0400)
committerJez Ng <jezng@fb.com>
Tue, 25 May 2021 18:58:29 +0000 (14:58 -0400)
* Move `static_asserts` into cpp instead of header file. I noticed they
  had been separated from the main class definition in the header, so I
  set about to clean that up, then figured it made more sense as part of
  the cpp file so as not to incur unnecessary compile-time overhead.

* Remove unnecessary `virtual`s

* Remove unnecessary comment / reword another comment

lld/MachO/InputFiles.cpp
lld/MachO/InputSection.h
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h

index f6a0b52..4d3b889 100644 (file)
@@ -188,7 +188,6 @@ static bool checkCompatibility(const InputFile *input) {
 
 // Open a given file path and return it as a memory-mapped file.
 Optional<MemoryBufferRef> macho::readFile(StringRef path) {
-  // Open a file.
   ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
   if (std::error_code ec = mbOrErr.getError()) {
     error("cannot open " + path + ": " + ec.message());
@@ -209,10 +208,9 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
     return mbref;
   }
 
-  // Object files and archive files may be fat files, which contains
-  // multiple real files for different CPU ISAs. Here, we search for a
-  // file that matches with the current link target and returns it as
-  // a MemoryBufferRef.
+  // Object files and archive files may be fat files, which contain multiple
+  // real files for different CPU ISAs. Here, we search for a file that matches
+  // with the current link target and returns it as a MemoryBufferRef.
   const auto *arch = reinterpret_cast<const fat_arch *>(buf + sizeof(*hdr));
 
   for (uint32_t i = 0, n = read32be(&hdr->nfat_arch); i < n; ++i) {
index 94c24a7..4655e33 100644 (file)
@@ -19,18 +19,17 @@ namespace lld {
 namespace macho {
 
 class InputFile;
-class InputSection;
 class OutputSection;
 
 class InputSection {
 public:
   virtual ~InputSection() = default;
   virtual uint64_t getSize() const { return data.size(); }
-  virtual uint64_t getFileSize() const;
+  uint64_t getFileSize() const;
   uint64_t getFileOffset() const;
   uint64_t getVA() const;
 
-  virtual void writeTo(uint8_t *buf);
+  void writeTo(uint8_t *buf);
 
   InputFile *file = nullptr;
   StringRef name;
index 2b63b83..2ff9355 100644 (file)
@@ -925,6 +925,9 @@ void StringTableSection::writeTo(uint8_t *buf) const {
   }
 }
 
+static_assert((CodeSignatureSection::blobHeadersSize % 8) == 0, "");
+static_assert((CodeSignatureSection::fixedHeadersSize % 8) == 0, "");
+
 CodeSignatureSection::CodeSignatureSection()
     : LinkEditSection(segment_names::linkEdit, section_names::codeSignature) {
   align = 16; // required by libstuff
index d5bc8ad..24be151 100644 (file)
@@ -16,7 +16,6 @@
 #include "OutputSegment.h"
 #include "Target.h"
 
-#include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
@@ -515,9 +514,6 @@ private:
   uint64_t xarSize;
 };
 
-static_assert((CodeSignatureSection::blobHeadersSize % 8) == 0, "");
-static_assert((CodeSignatureSection::fixedHeadersSize % 8) == 0, "");
-
 struct InStruct {
   MachHeaderSection *header = nullptr;
   RebaseSection *rebase = nullptr;