bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
- bool isSectionZeroInit(DataRefImpl Sec) const override;
- bool isSectionReadOnlyData(DataRefImpl Sec) const override;
- bool isSectionRequiredForExecution(DataRefImpl Sec) const override;
bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
virtual std::error_code getSymbolVersion(SymbolRef Symb, StringRef &Version,
bool &IsDefault) const = 0;
+ virtual uint64_t getSectionFlags(SectionRef Sec) const = 0;
+ virtual uint32_t getSectionType(SectionRef Sec) const = 0;
+
static inline bool classof(const Binary *v) { return v->isELF(); }
};
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
- bool isSectionRequiredForExecution(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
- bool isSectionZeroInit(DataRefImpl Sec) const override;
- bool isSectionReadOnlyData(DataRefImpl Sec) const override;
bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
std::error_code getSymbolVersion(SymbolRef Symb, StringRef &Version,
bool &IsDefault) const override;
+ uint64_t getSectionFlags(SectionRef Sec) const override;
+ uint32_t getSectionType(SectionRef Sec) const override;
+
uint8_t getBytesInAddress() const override;
StringRef getFileFormatName() const override;
unsigned getArch() const override;
return object_error::success;
}
+template <class ELFT>
+uint64_t ELFObjectFile<ELFT>::getSectionFlags(SectionRef Sec) const {
+ DataRefImpl DRI = Sec.getRawDataRefImpl();
+ return toELFShdrIter(DRI)->sh_flags;
+}
+
+template <class ELFT>
+uint32_t ELFObjectFile<ELFT>::getSectionType(SectionRef Sec) const {
+ DataRefImpl DRI = Sec.getRawDataRefImpl();
+ return toELFShdrIter(DRI)->sh_type;
+}
+
template <class ELFT>
std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
uint64_t &Result) const {
EShdr->sh_type == ELF::SHT_NOBITS;
}
-template <class ELFT>
-bool ELFObjectFile<ELFT>::isSectionRequiredForExecution(DataRefImpl Sec) const {
- return toELFShdrIter(Sec)->sh_flags & ELF::SHF_ALLOC;
-}
-
template <class ELFT>
bool ELFObjectFile<ELFT>::isSectionVirtual(DataRefImpl Sec) const {
return toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
}
-template <class ELFT>
-bool ELFObjectFile<ELFT>::isSectionZeroInit(DataRefImpl Sec) const {
- return toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS;
-}
-
-template <class ELFT>
-bool ELFObjectFile<ELFT>::isSectionReadOnlyData(DataRefImpl Sec) const {
- Elf_Shdr_Iter EShdr = toELFShdrIter(Sec);
- return !(EShdr->sh_flags & (ELF::SHF_WRITE | ELF::SHF_EXECINSTR));
-}
-
template <class ELFT>
bool ELFObjectFile<ELFT>::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const {
// MachO specific.
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
+ unsigned getSectionType(SectionRef Sec) const;
std::error_code getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const override;
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
- bool isSectionRequiredForExecution(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
- bool isSectionZeroInit(DataRefImpl Sec) const override;
- bool isSectionReadOnlyData(DataRefImpl Sec) const override;
bool sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
bool isText() const;
bool isData() const;
bool isBSS() const;
- bool isRequiredForExecution() const;
bool isVirtual() const;
- bool isZeroInit() const;
- bool isReadOnlyData() const;
bool containsSymbol(SymbolRef S) const;
section_iterator getRelocatedSection() const;
DataRefImpl getRawDataRefImpl() const;
+ const ObjectFile *getObject() const;
};
/// SymbolRef - This is a value type class that represents a single symbol in
virtual bool isSectionText(DataRefImpl Sec) const = 0;
virtual bool isSectionData(DataRefImpl Sec) const = 0;
virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
- virtual bool isSectionRequiredForExecution(DataRefImpl Sec) const = 0;
// A section is 'virtual' if its contents aren't present in the object image.
virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
- virtual bool isSectionZeroInit(DataRefImpl Sec) const = 0;
- virtual bool isSectionReadOnlyData(DataRefImpl Sec) const = 0;
virtual bool sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const = 0;
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
return OwningObject->isSectionBSS(SectionPimpl);
}
-inline bool SectionRef::isRequiredForExecution() const {
- return OwningObject->isSectionRequiredForExecution(SectionPimpl);
-}
-
inline bool SectionRef::isVirtual() const {
return OwningObject->isSectionVirtual(SectionPimpl);
}
-inline bool SectionRef::isZeroInit() const {
- return OwningObject->isSectionZeroInit(SectionPimpl);
-}
-
-inline bool SectionRef::isReadOnlyData() const {
- return OwningObject->isSectionReadOnlyData(SectionPimpl);
-}
-
inline bool SectionRef::containsSymbol(SymbolRef S) const {
return OwningObject->sectionContainsSymbol(SectionPimpl,
S.getRawDataRefImpl());
return SectionPimpl;
}
+inline const ObjectFile *SectionRef::getObject() const {
+ return OwningObject;
+}
+
/// RelocationRef
inline RelocationRef::RelocationRef(DataRefImpl RelocationP,
const ObjectFile *Owner)
#include "RuntimeDyldELF.h"
#include "RuntimeDyldImpl.h"
#include "RuntimeDyldMachO.h"
-#include "llvm/Object/ELF.h"
+#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MutexGuard.h"
return TotalSize;
}
+static bool isRequiredForExecution(const SectionRef &Section) {
+ const ObjectFile *Obj = Section.getObject();
+ if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
+ return ELFObj->getSectionFlags(Section) & ELF::SHF_ALLOC;
+ assert(isa<MachOObjectFile>(Obj));
+ return true;
+ }
+
+static bool isReadOnlyData(const SectionRef &Section) {
+ const ObjectFile *Obj = Section.getObject();
+ if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
+ return !(ELFObj->getSectionFlags(Section) &
+ (ELF::SHF_WRITE | ELF::SHF_EXECINSTR));
+ assert(isa<MachOObjectFile>(Obj));
+ return false;
+}
+
+static bool isZeroInit(const SectionRef &Section) {
+ const ObjectFile *Obj = Section.getObject();
+ if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
+ return ELFObj->getSectionType(Section) == ELF::SHT_NOBITS;
+
+ auto *MachO = cast<MachOObjectFile>(Obj);
+ unsigned SectionType = MachO->getSectionType(Section);
+ return SectionType == MachO::S_ZEROFILL ||
+ SectionType == MachO::S_GB_ZEROFILL;
+}
+
// Compute an upper bound of the memory size that is required to load all
// sections
void RuntimeDyldImpl::computeTotalAllocSize(const ObjectFile &Obj,
SI != SE; ++SI) {
const SectionRef &Section = *SI;
- bool IsRequired = Section.isRequiredForExecution();
+ bool IsRequired = isRequiredForExecution(Section);
// Consider only the sections that are required to be loaded for execution
if (IsRequired) {
uint64_t DataSize = Section.getSize();
uint64_t Alignment64 = Section.getAlignment();
bool IsCode = Section.isText();
- bool IsReadOnly = Section.isReadOnlyData();
+ bool IsReadOnly = isReadOnlyData(Section);
Check(Section.getName(Name));
unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
unsigned PaddingSize = 0;
unsigned StubBufSize = 0;
StringRef Name;
- bool IsRequired = Section.isRequiredForExecution();
+ bool IsRequired = isRequiredForExecution(Section);
bool IsVirtual = Section.isVirtual();
- bool IsZeroInit = Section.isZeroInit();
- bool IsReadOnly = Section.isReadOnlyData();
+ bool IsZeroInit = isZeroInit(Section);
+ bool IsReadOnly = isReadOnlyData(Section);
uint64_t DataSize = Section.getSize();
Check(Section.getName(Name));
return Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
}
-bool COFFObjectFile::isSectionRequiredForExecution(DataRefImpl Ref) const {
- // Sections marked 'Info', 'Remove', or 'Discardable' aren't required for
- // execution.
- const coff_section *Sec = toSec(Ref);
- return !(Sec->Characteristics &
- (COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE |
- COFF::IMAGE_SCN_MEM_DISCARDABLE));
-}
-
bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const {
const coff_section *Sec = toSec(Ref);
return Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
}
-bool COFFObjectFile::isSectionZeroInit(DataRefImpl Ref) const {
- const coff_section *Sec = toSec(Ref);
- return Sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
-}
-
-bool COFFObjectFile::isSectionReadOnlyData(DataRefImpl Ref) const {
- const coff_section *Sec = toSec(Ref);
- // Check if it's any sort of data section.
- if (!(Sec->Characteristics & (COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
- COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)))
- return false;
- // If it's writable or executable or contains code, it isn't read-only data.
- if (Sec->Characteristics &
- (COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
- COFF::IMAGE_SCN_MEM_WRITE))
- return false;
- return true;
-}
-
bool COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef,
DataRefImpl SymbRef) const {
const coff_section *Sec = toSec(SecRef);
return object_error::success;
}
+unsigned MachOObjectFile::getSectionType(SectionRef Sec) const {
+ DataRefImpl DRI = Sec.getRawDataRefImpl();
+ uint32_t Flags = getSectionFlags(this, DRI);
+ return Flags & MachO::SECTION_TYPE;
+}
+
// getIndirectName() returns the name of the alias'ed symbol who's string table
// index is in the n_value field.
std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb,
SectionType == MachO::S_GB_ZEROFILL);
}
-bool MachOObjectFile::isSectionRequiredForExecution(DataRefImpl Sect) const {
- // FIXME: Unimplemented.
- return true;
-}
-
bool MachOObjectFile::isSectionVirtual(DataRefImpl Sec) const {
// FIXME: Unimplemented.
return false;
}
-bool MachOObjectFile::isSectionZeroInit(DataRefImpl Sec) const {
- uint32_t Flags = getSectionFlags(this, Sec);
- unsigned SectionType = Flags & MachO::SECTION_TYPE;
- return SectionType == MachO::S_ZEROFILL ||
- SectionType == MachO::S_GB_ZEROFILL;
-}
-
-bool MachOObjectFile::isSectionReadOnlyData(DataRefImpl Sec) const {
- // Consider using the code from isSectionText to look for __const sections.
- // Alternately, emit S_ATTR_PURE_INSTRUCTIONS and/or S_ATTR_SOME_INSTRUCTIONS
- // to use section attributes to distinguish code from data.
-
- // FIXME: Unimplemented.
- return false;
-}
-
bool MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb) const {
SymbolRef::Type ST;