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());
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),
/*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:
}
}
-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());
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;
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;
// .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; }
};
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) {
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;
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;