[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
This commit is contained in:
Jez Ng 2021-05-25 14:57:58 -04:00
parent d1e5f046cc
commit 8535834ef7
4 changed files with 8 additions and 12 deletions

View 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) {

View 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;

View 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

View 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;