mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 16:24:23 +00:00
Add a ELFSectionRef class and use it to expose getSectionType.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240778 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -40,12 +40,14 @@ class ELFSymbolRef;
|
|||||||
|
|
||||||
class ELFObjectFileBase : public ObjectFile {
|
class ELFObjectFileBase : public ObjectFile {
|
||||||
friend class ELFSymbolRef;
|
friend class ELFSymbolRef;
|
||||||
|
friend class ELFSectionRef;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source);
|
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source);
|
||||||
|
|
||||||
virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
|
virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
|
||||||
virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
|
virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
|
||||||
|
virtual uint32_t getSectionType(DataRefImpl Sec) const = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
|
virtual ErrorOr<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
|
||||||
@ -58,13 +60,27 @@ public:
|
|||||||
virtual elf_symbol_iterator_range getDynamicSymbolIterators() const = 0;
|
virtual elf_symbol_iterator_range getDynamicSymbolIterators() const = 0;
|
||||||
|
|
||||||
virtual uint64_t getSectionFlags(SectionRef Sec) const = 0;
|
virtual uint64_t getSectionFlags(SectionRef Sec) const = 0;
|
||||||
virtual uint32_t getSectionType(SectionRef Sec) const = 0;
|
|
||||||
|
|
||||||
elf_symbol_iterator_range symbols() const;
|
elf_symbol_iterator_range symbols() const;
|
||||||
|
|
||||||
static inline bool classof(const Binary *v) { return v->isELF(); }
|
static inline bool classof(const Binary *v) { return v->isELF(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ELFSectionRef : public SectionRef {
|
||||||
|
public:
|
||||||
|
ELFSectionRef(const SectionRef &B) : SectionRef(B) {
|
||||||
|
assert(isa<ELFObjectFileBase>(SectionRef::getObject()));
|
||||||
|
}
|
||||||
|
|
||||||
|
const ELFObjectFileBase *getObject() const {
|
||||||
|
return cast<ELFObjectFileBase>(SectionRef::getObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t getType() const {
|
||||||
|
return getObject()->getSectionType(getRawDataRefImpl());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ELFSymbolRef : public SymbolRef {
|
class ELFSymbolRef : public SymbolRef {
|
||||||
public:
|
public:
|
||||||
ELFSymbolRef(const SymbolRef &B) : SymbolRef(B) {
|
ELFSymbolRef(const SymbolRef &B) : SymbolRef(B) {
|
||||||
@ -170,6 +186,7 @@ protected:
|
|||||||
getRelocationTypeName(DataRefImpl Rel,
|
getRelocationTypeName(DataRefImpl Rel,
|
||||||
SmallVectorImpl<char> &Result) const override;
|
SmallVectorImpl<char> &Result) const override;
|
||||||
|
|
||||||
|
uint32_t getSectionType(DataRefImpl Sec) const override;
|
||||||
uint64_t getROffset(DataRefImpl Rel) const;
|
uint64_t getROffset(DataRefImpl Rel) const;
|
||||||
StringRef getRelocationTypeName(uint32_t Type) const;
|
StringRef getRelocationTypeName(uint32_t Type) const;
|
||||||
|
|
||||||
@ -263,7 +280,6 @@ public:
|
|||||||
bool hasRelocationAddend(DataRefImpl Rel) const override;
|
bool hasRelocationAddend(DataRefImpl Rel) const override;
|
||||||
|
|
||||||
uint64_t getSectionFlags(SectionRef Sec) const override;
|
uint64_t getSectionFlags(SectionRef Sec) const override;
|
||||||
uint32_t getSectionType(SectionRef Sec) const override;
|
|
||||||
|
|
||||||
uint8_t getBytesInAddress() const override;
|
uint8_t getBytesInAddress() const override;
|
||||||
StringRef getFileFormatName() const override;
|
StringRef getFileFormatName() const override;
|
||||||
@ -315,9 +331,8 @@ uint64_t ELFObjectFile<ELFT>::getSectionFlags(SectionRef Sec) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
uint32_t ELFObjectFile<ELFT>::getSectionType(SectionRef Sec) const {
|
uint32_t ELFObjectFile<ELFT>::getSectionType(DataRefImpl Sec) const {
|
||||||
DataRefImpl DRI = Sec.getRawDataRefImpl();
|
return toELFShdrIter(Sec)->sh_type;
|
||||||
return toELFShdrIter(DRI)->sh_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -306,10 +306,10 @@ static bool isReadOnlyData(const SectionRef &Section) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isZeroInit(const SectionRef &Section) {
|
static bool isZeroInit(const SectionRef Section) {
|
||||||
const ObjectFile *Obj = Section.getObject();
|
const ObjectFile *Obj = Section.getObject();
|
||||||
if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
|
if (isa<object::ELFObjectFileBase>(Obj))
|
||||||
return ELFObj->getSectionType(Section) == ELF::SHT_NOBITS;
|
return ELFSectionRef(Section).getType() == ELF::SHT_NOBITS;
|
||||||
if (auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
|
if (auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
|
||||||
return COFFObj->getCOFFSection(Section)->Characteristics &
|
return COFFObj->getCOFFSection(Section)->Characteristics &
|
||||||
COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
|
COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
|
||||||
|
Reference in New Issue
Block a user