mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
[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
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -64,7 +64,6 @@ public:
|
||||
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 @@ protected:
|
||||
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 @@ private:
|
||||
// .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; }
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 @@ public:
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user