bool &Result) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
+ bool section_rel_empty(DataRefImpl Sec) const override;
void moveRelocationNext(DataRefImpl &Rel) const override;
error_code getRelocationAddress(DataRefImpl Rel,
bool &Result) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
+ bool section_rel_empty(DataRefImpl Sec) const override;
section_iterator getRelocatedSection(DataRefImpl Sec) const override;
void moveRelocationNext(DataRefImpl &Rel) const override;
}
template <class ELFT>
+bool ELFObjectFile<ELFT>::section_rel_empty(DataRefImpl Sec) const {
+ const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
+ return S->sh_size == 0;
+}
+
+template <class ELFT>
section_iterator
ELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const {
if (EF.getHeader()->e_type != ELF::ET_REL)
bool &Result) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
+ bool section_rel_empty(DataRefImpl Sec) const override;
void moveRelocationNext(DataRefImpl &Rel) const override;
error_code getRelocationAddress(DataRefImpl Rel,
SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
bool operator==(const SectionRef &Other) const;
+ bool operator!=(const SectionRef &Other) const;
bool operator<(const SectionRef &Other) const;
void moveNext();
relocation_iterator_range relocations() const {
return relocation_iterator_range(relocation_begin(), relocation_end());
}
+ bool relocation_empty() const;
section_iterator getRelocatedSection() const;
DataRefImpl getRawDataRefImpl() const;
bool &Result) const = 0;
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
+ virtual bool section_rel_empty(DataRefImpl Sec) const = 0;
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
// Same as above for RelocationRef.
return SectionPimpl == Other.SectionPimpl;
}
+inline bool SectionRef::operator!=(const SectionRef &Other) const {
+ return SectionPimpl != Other.SectionPimpl;
+}
+
inline bool SectionRef::operator<(const SectionRef &Other) const {
return SectionPimpl < Other.SectionPimpl;
}
return OwningObject->section_rel_end(SectionPimpl);
}
+inline bool SectionRef::relocation_empty() const {
+ return OwningObject->section_rel_empty(SectionPimpl);
+}
+
inline section_iterator SectionRef::getRelocatedSection() const {
return OwningObject->getRelocatedSection(SectionPimpl);
}
return std::memcmp(&a, &b, sizeof(DataRefImpl)) == 0;
}
+inline bool operator!=(const DataRefImpl &a, const DataRefImpl &b) {
+ return !operator==(a, b);
+}
+
inline bool operator<(const DataRefImpl &a, const DataRefImpl &b) {
// Check bitwise identical. This is the only legal way to compare a union w/o
// knowing which member is in use.
StubMap Stubs;
section_iterator RelocatedSection = SI->getRelocatedSection();
- if ((SI->relocation_begin() != SI->relocation_end()) ||
- ProcessAllSections) {
- bool IsCode = false;
- Check(RelocatedSection->isText(IsCode));
- SectionID =
- findOrEmitSection(*Obj, *RelocatedSection, IsCode, LocalSections);
- DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n");
- }
+ if (SI->relocation_empty() && !ProcessAllSections)
+ continue;
+
+ bool IsCode = false;
+ Check(RelocatedSection->isText(IsCode));
+ SectionID =
+ findOrEmitSection(*Obj, *RelocatedSection, IsCode, LocalSections);
+ DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n");
- for (const RelocationRef &Reloc : SI->relocations())
- processRelocationRef(SectionID, Reloc, *Obj, LocalSections, LocalSymbols,
- Stubs);
+ for (relocation_iterator I = SI->relocation_begin(),
+ E = SI->relocation_end(); I != E;)
+ I = processRelocationRef(SectionID, I, *Obj, LocalSections, LocalSymbols,
+ Stubs);
}
// Give the subclasses a chance to tie-up any loose ends.
}
}
-void RuntimeDyldELF::processRelocationRef(unsigned SectionID,
- RelocationRef RelI,
- ObjectImage &Obj,
- ObjSectionToIDMap &ObjSectionToID,
- const SymbolTableMap &Symbols,
- StubMap &Stubs) {
+relocation_iterator
+RuntimeDyldELF::processRelocationRef(unsigned SectionID,
+ relocation_iterator RelI,
+ ObjectImage &Obj,
+ ObjSectionToIDMap &ObjSectionToID,
+ const SymbolTableMap &Symbols,
+ StubMap &Stubs) {
uint64_t RelType;
- Check(RelI.getType(RelType));
+ Check(RelI->getType(RelType));
int64_t Addend;
- Check(getELFRelocationAddend(RelI, Addend));
- symbol_iterator Symbol = RelI.getSymbol();
+ Check(getELFRelocationAddend(*RelI, Addend));
+ symbol_iterator Symbol = RelI->getSymbol();
// Obtain the symbol name which is referenced in the relocation
StringRef TargetName;
}
}
uint64_t Offset;
- Check(RelI.getOffset(Offset));
+ Check(RelI->getOffset(Offset));
DEBUG(dbgs() << "\t\tSectionID: " << SectionID
<< " Offset: " << Offset
else
addRelocationForSection(RE, Value.SectionID);
}
+ return ++RelI;
}
void RuntimeDyldELF::updateGOTEntries(StringRef Name, uint64_t Addr) {
{}
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
- void processRelocationRef(unsigned SectionID, RelocationRef RelI,
- ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
- const SymbolTableMap &Symbols,
- StubMap &Stubs) override;
+ relocation_iterator
+ processRelocationRef(unsigned SectionID, relocation_iterator RelI,
+ ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
+ const SymbolTableMap &Symbols, StubMap &Stubs) override;
bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
bool isCompatibleFile(const object::ObjectFile *Buffer) const override;
void registerEHFrames() override;
/// \brief Parses the object file relocation and stores it to Relocations
/// or SymbolRelocations (this depends on the object file type).
- virtual void processRelocationRef(unsigned SectionID,
- RelocationRef RelI,
- ObjectImage &Obj,
- ObjSectionToIDMap &ObjSectionToID,
- const SymbolTableMap &Symbols,
- StubMap &Stubs) = 0;
+ virtual relocation_iterator
+ processRelocationRef(unsigned SectionID, relocation_iterator RelI,
+ ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
+ const SymbolTableMap &Symbols, StubMap &Stubs) = 0;
/// \brief Resolve relocations to external symbols.
void resolveExternalSymbols();
uint64_t& DataSizeRW);
// \brief Compute the stub buffer size required for a section
- unsigned computeSectionStubBufSize(ObjectImage &Obj, const SectionRef &Section);
+ unsigned computeSectionStubBufSize(ObjectImage &Obj,
+ const SectionRef &Section);
public:
RuntimeDyldImpl(RTDyldMemoryManager *mm)
return false;
}
-void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
- RelocationRef RelI,
- ObjectImage &Obj,
- ObjSectionToIDMap &ObjSectionToID,
- const SymbolTableMap &Symbols,
- StubMap &Stubs) {
+relocation_iterator
+RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
+ relocation_iterator RelI,
+ ObjectImage &Obj,
+ ObjSectionToIDMap &ObjSectionToID,
+ const SymbolTableMap &Symbols,
+ StubMap &Stubs) {
const ObjectFile *OF = Obj.getObjectFile();
const MachOObjectFile *MachO = static_cast<const MachOObjectFile*>(OF);
- MachO::any_relocation_info RE= MachO->getRelocation(RelI.getRawDataRefImpl());
+ MachO::any_relocation_info RE =
+ MachO->getRelocation(RelI->getRawDataRefImpl());
uint32_t RelType = MachO->getAnyRelocationType(RE);
// Note: This will fail horribly where the relocations *do* need to be
// applied, but that was already the case.
if (MachO->isRelocationScattered(RE))
- return;
+ return ++RelI;
RelocationValueRef Value;
SectionEntry &Section = Sections[SectionID];
bool IsPCRel = MachO->getAnyRelocationPCRel(RE);
unsigned Size = MachO->getAnyRelocationLength(RE);
uint64_t Offset;
- RelI.getOffset(Offset);
+ RelI->getOffset(Offset);
uint8_t *LocalAddress = Section.Address + Offset;
unsigned NumBytes = 1 << Size;
uint64_t Addend = 0;
if (isExtern) {
// Obtain the symbol name which is referenced in the relocation
- symbol_iterator Symbol = RelI.getSymbol();
+ symbol_iterator Symbol = RelI->getSymbol();
StringRef TargetName;
Symbol->getName(TargetName);
// First search for the symbol in the local symbol table
else
addRelocationForSection(RE, Value.SectionID);
}
+ return ++RelI;
}
RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override;
- void processRelocationRef(unsigned SectionID, RelocationRef RelI,
- ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
- const SymbolTableMap &Symbols,
- StubMap &Stubs) override;
+ relocation_iterator
+ processRelocationRef(unsigned SectionID, relocation_iterator RelI,
+ ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID,
+ const SymbolTableMap &Symbols, StubMap &Stubs) override;
bool isCompatibleFormat(const ObjectBuffer *Buffer) const override;
bool isCompatibleFile(const object::ObjectFile *Obj) const override;
void registerEHFrames() override;
return relocation_iterator(RelocationRef(Ret, this));
}
+bool COFFObjectFile::section_rel_empty(DataRefImpl Ref) const {
+ const coff_section *Sec = toSec(Ref);
+ return Sec->NumberOfRelocations == 0;
+}
+
// Initialize the pointer to the symbol table.
error_code COFFObjectFile::initSymbolTablePtr() {
if (error_code EC = getObject(
return relocation_iterator(RelocationRef(Ret, this));
}
+bool MachOObjectFile::section_rel_empty(DataRefImpl Sec) const {
+ if (is64Bit()) {
+ MachO::section_64 Sect = getSection64(Sec);
+ return Sect.nreloc == 0;
+ } else {
+ MachO::section Sect = getSection(Sec);
+ return Sect.nreloc == 0;
+ }
+}
+
void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
const MachO::any_relocation_info *P =
reinterpret_cast<const MachO::any_relocation_info *>(Rel.p);