[llvm-branch-commits] [lld] 7b007ac - [lld-macho][nfc] Move some methods from InputFile to ObjFile
Jez Ng via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 8 10:42:04 PST 2020
Author: Jez Ng
Date: 2020-12-08T10:34:32-08:00
New Revision: 7b007ac0800babe750c58b1aead15e1c3e7f3b0f
URL: https://github.com/llvm/llvm-project/commit/7b007ac0800babe750c58b1aead15e1c3e7f3b0f
DIFF: https://github.com/llvm/llvm-project/commit/7b007ac0800babe750c58b1aead15e1c3e7f3b0f.diff
LOG: [lld-macho][nfc] Move some methods from InputFile to ObjFile
Additionally:
1. Move the helper functions in InputSection.h below the definition of
`InputSection`, so the important stuff is on top
2. Remove unnecessary `explicit`
Reviewed By: #lld-macho, compnerd
Differential Revision: https://reviews.llvm.org/D92453
Added:
Modified:
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
Removed:
################################################################################
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 1339152901ce..24600090c491 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -155,7 +155,7 @@ const load_command *macho::findCommand(const mach_header_64 *hdr,
return nullptr;
}
-void InputFile::parseSections(ArrayRef<section_64> sections) {
+void ObjFile::parseSections(ArrayRef<section_64> sections) {
subsections.reserve(sections.size());
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
@@ -192,8 +192,8 @@ static InputSection *findContainingSubsection(SubsectionMap &map,
return it->second;
}
-void InputFile::parseRelocations(const section_64 &sec,
- SubsectionMap &subsecMap) {
+void ObjFile::parseRelocations(const section_64 &sec,
+ SubsectionMap &subsecMap) {
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
ArrayRef<any_relocation_info> anyRelInfos(
reinterpret_cast<const any_relocation_info *>(buf + sec.reloff),
@@ -266,8 +266,8 @@ static macho::Symbol *createAbsolute(const structs::nlist_64 &sym,
/*isExternal=*/false);
}
-macho::Symbol *InputFile::parseNonSectionSymbol(const structs::nlist_64 &sym,
- StringRef name) {
+macho::Symbol *ObjFile::parseNonSectionSymbol(const structs::nlist_64 &sym,
+ StringRef name) {
uint8_t type = sym.n_type & N_TYPE;
switch (type) {
case N_UNDF:
@@ -289,8 +289,8 @@ macho::Symbol *InputFile::parseNonSectionSymbol(const structs::nlist_64 &sym,
}
}
-void InputFile::parseSymbols(ArrayRef<structs::nlist_64> nList,
- const char *strtab, bool subsectionsViaSymbols) {
+void ObjFile::parseSymbols(ArrayRef<structs::nlist_64> nList,
+ const char *strtab, bool subsectionsViaSymbols) {
// resize(), not reserve(), because we are going to create N_ALT_ENTRY symbols
// out-of-sequence.
symbols.resize(nList.size());
diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 59638ac197cf..877ccaef2fef 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -64,7 +64,6 @@ class InputFile {
MemoryBufferRef mb;
std::vector<Symbol *> symbols;
- ArrayRef<llvm::MachO::section_64> sectionHeaders;
std::vector<SubsectionMap> subsections;
// Provides an easy way to sort InputFiles deterministically.
const int id;
@@ -80,15 +79,6 @@ class InputFile {
InputFile(Kind kind, const llvm::MachO::InterfaceFile &interface)
: id(idCount++), fileKind(kind), name(saver.save(interface.getPath())) {}
- void parseSections(ArrayRef<llvm::MachO::section_64>);
-
- void parseSymbols(ArrayRef<lld::structs::nlist_64> nList, const char *strtab,
- bool subsectionsViaSymbols);
-
- Symbol *parseNonSectionSymbol(const structs::nlist_64 &sym, StringRef name);
-
- void parseRelocations(const llvm::MachO::section_64 &, SubsectionMap &);
-
private:
const Kind fileKind;
const StringRef name;
@@ -99,21 +89,26 @@ class InputFile {
// .o file
class ObjFile : public InputFile {
public:
- explicit 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; }
llvm::DWARFUnit *compileUnit = nullptr;
const uint32_t modTime;
+ ArrayRef<llvm::MachO::section_64> sectionHeaders;
private:
+ void parseSections(ArrayRef<llvm::MachO::section_64>);
+ void parseSymbols(ArrayRef<lld::structs::nlist_64> nList, const char *strtab,
+ bool subsectionsViaSymbols);
+ Symbol *parseNonSectionSymbol(const structs::nlist_64 &sym, StringRef name);
+ void parseRelocations(const llvm::MachO::section_64 &, SubsectionMap &);
void parseDebugInfo();
};
// command-line -sectcreate file
class OpaqueFile : public InputFile {
public:
- explicit OpaqueFile(MemoryBufferRef mb, StringRef segName,
- StringRef sectName);
+ OpaqueFile(MemoryBufferRef mb, StringRef segName, StringRef sectName);
static bool classof(const InputFile *f) { return f->kind() == OpaqueKind; }
};
diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 80c263301f41..8477d78d2f3f 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -26,6 +26,10 @@ uint64_t InputSection::getFileOffset() const {
return parent->fileOff + outSecFileOff;
}
+uint64_t InputSection::getFileSize() const {
+ return isZeroFill(flags) ? 0 : getSize();
+}
+
uint64_t InputSection::getVA() const { return parent->addr + outSecOff; }
void InputSection::writeTo(uint8_t *buf) {
diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index f405fd6cf6d3..5829936ece29 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -35,27 +35,11 @@ struct Reloc {
llvm::PointerUnion<Symbol *, InputSection *> referent;
};
-inline bool isZeroFill(uint32_t flags) {
- return llvm::MachO::isVirtualSection(flags & llvm::MachO::SECTION_TYPE);
-}
-
-inline bool isThreadLocalVariables(uint32_t flags) {
- return (flags & llvm::MachO::SECTION_TYPE) ==
- llvm::MachO::S_THREAD_LOCAL_VARIABLES;
-}
-
-inline bool isDebugSection(uint32_t flags) {
- return (flags & llvm::MachO::SECTION_ATTRIBUTES_USR) ==
- llvm::MachO::S_ATTR_DEBUG;
-}
-
class InputSection {
public:
virtual ~InputSection() = default;
virtual uint64_t getSize() const { return data.size(); }
- virtual uint64_t getFileSize() const {
- return isZeroFill(flags) ? 0 : getSize();
- }
+ virtual uint64_t getFileSize() const;
uint64_t getFileOffset() const;
uint64_t getVA() const;
@@ -76,6 +60,20 @@ class InputSection {
std::vector<Reloc> relocs;
};
+inline bool isZeroFill(uint32_t flags) {
+ return llvm::MachO::isVirtualSection(flags & llvm::MachO::SECTION_TYPE);
+}
+
+inline bool isThreadLocalVariables(uint32_t flags) {
+ return (flags & llvm::MachO::SECTION_TYPE) ==
+ llvm::MachO::S_THREAD_LOCAL_VARIABLES;
+}
+
+inline bool isDebugSection(uint32_t flags) {
+ return (flags & llvm::MachO::SECTION_ATTRIBUTES_USR) ==
+ llvm::MachO::S_ATTR_DEBUG;
+}
+
bool isCodeSection(InputSection *);
extern std::vector<InputSection *> inputSections;
More information about the llvm-branch-commits
mailing list