diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -64,7 +64,6 @@ MemoryBufferRef mb; std::vector symbols; - ArrayRef sectionHeaders; std::vector subsections; // Provides an easy way to sort InputFiles deterministically. const int id; @@ -80,15 +79,6 @@ InputFile(Kind kind, const llvm::MachO::InterfaceFile &interface) : id(idCount++), fileKind(kind), name(saver.save(interface.getPath())) {} - void parseSections(ArrayRef); - - void parseSymbols(ArrayRef 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 @@ // .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 sectionHeaders; private: + void parseSections(ArrayRef); + void parseSymbols(ArrayRef 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/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -155,7 +155,7 @@ return nullptr; } -void InputFile::parseSections(ArrayRef sections) { +void ObjFile::parseSections(ArrayRef sections) { subsections.reserve(sections.size()); auto *buf = reinterpret_cast(mb.getBufferStart()); @@ -192,8 +192,8 @@ 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(mb.getBufferStart()); ArrayRef anyRelInfos( reinterpret_cast(buf + sec.reloff), @@ -266,8 +266,8 @@ /*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 @@ } } -void InputFile::parseSymbols(ArrayRef nList, - const char *strtab, bool subsectionsViaSymbols) { +void ObjFile::parseSymbols(ArrayRef 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/InputSection.h b/lld/MachO/InputSection.h --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -35,27 +35,11 @@ llvm::PointerUnion 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 @@ std::vector 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 inputSections; diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -26,6 +26,10 @@ 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) {