[lld] 8535834 - [lld-macho][nfc] Misc code cleanup

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Tue May 25 11:58:40 PDT 2021


Author: Jez Ng
Date: 2021-05-25T14:58:29-04:00
New Revision: 8535834ef7891a5221e0bd1350a4f0636b6f3efb

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

LOG: [lld-macho][nfc] Misc code cleanup

* 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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index f6a0b5296cd7a..4d3b889586e20 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -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 
diff erent 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 
diff erent 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) {

diff  --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index 94c24a736b197..4655e33943949 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -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;

diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 2b63b839c0743..2ff93556b46b7 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -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

diff  --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h
index d5bc8ad6a56e3..24be151690b06 100644
--- a/lld/MachO/SyntheticSections.h
+++ b/lld/MachO/SyntheticSections.h
@@ -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 @@ class BitcodeBundleSection : public SyntheticSection {
   uint64_t xarSize;
 };
 
-static_assert((CodeSignatureSection::blobHeadersSize % 8) == 0, "");
-static_assert((CodeSignatureSection::fixedHeadersSize % 8) == 0, "");
-
 struct InStruct {
   MachHeaderSection *header = nullptr;
   RebaseSection *rebase = nullptr;


        


More information about the llvm-commits mailing list