diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -63,7 +63,6 @@ MemoryBufferRef mb; std::vector symbols; - ArrayRef sectionHeaders; std::vector subsections; // Provides an easy way to sort InputFiles deterministically. const int id; @@ -75,15 +74,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; @@ -100,8 +90,14 @@ llvm::DWARFUnit *compileUnit = nullptr; StringRef archiveName = ""; 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(); }; diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -144,7 +144,7 @@ return nullptr; } -void InputFile::parseSections(ArrayRef sections) { +void ObjFile::parseSections(ArrayRef sections) { subsections.reserve(sections.size()); auto *buf = reinterpret_cast(mb.getBufferStart()); @@ -181,8 +181,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), @@ -255,8 +255,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: @@ -278,8 +278,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) {