[BOLT] Make the methods isText/isData more robust

Summary: Make the methods isText/isData work for MachO.

(cherry picked from FBD19849460)
This commit is contained in:
Alexander Shaposhnikov 2020-02-11 17:54:48 -08:00 committed by Maksim Panchenko
parent c3c4b15a2e
commit d5b8fc8fbe
2 changed files with 12 additions and 3 deletions

View File

@ -24,6 +24,10 @@ extern cl::opt<bool> PrintRelocations;
extern cl::opt<bool> HotData;
}
bool BinarySection::isELF() const {
return BC.Ctx->getObjectFileInfo()->getTargetTriple().isOSBinFormatELF();
}
uint64_t
BinarySection::hash(const BinaryData &BD,
std::map<const BinaryData *, uint64_t> &Cache) const {

View File

@ -230,17 +230,22 @@ public:
///
/// Basic proprety access.
///
bool isELF() const;
StringRef getName() const { return Name; }
uint64_t getAddress() const { return Address; }
uint64_t getEndAddress() const { return Address + Size; }
uint64_t getSize() const { return Size; }
uint64_t getAlignment() const { return Alignment; }
bool isText() const {
return (ELFFlags & ELF::SHF_EXECINSTR);
if (isELF())
return (ELFFlags & ELF::SHF_EXECINSTR);
return getSectionRef().isText();
}
bool isData() const {
return (ELFType == ELF::SHT_PROGBITS &&
(ELFFlags & (ELF::SHF_ALLOC | ELF::SHF_WRITE)));
if (isELF())
return (ELFType == ELF::SHT_PROGBITS &&
(ELFFlags & (ELF::SHF_ALLOC | ELF::SHF_WRITE)));
return getSectionRef().isData();
}
bool isBSS() const {
return (ELFType == ELF::SHT_NOBITS &&