[BOLT][NFC] Replace ambiguous BinarySection::isReadOnly with isWritable

Address feedback in https://reviews.llvm.org/D102284#2755060

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D141733
This commit is contained in:
Amir Ayupov
2023-01-18 14:21:28 -08:00
parent c5abe89312
commit 69a9bbf106
4 changed files with 8 additions and 11 deletions

View File

@@ -232,8 +232,8 @@ public:
return isText() > Other.isText();
// Read-only before writable.
if (isReadOnly() != Other.isReadOnly())
return isReadOnly() > Other.isReadOnly();
if (isWritable() != Other.isWritable())
return isWritable() < Other.isWritable();
// BSS at the end.
if (isBSS() != Other.isBSS())
@@ -275,10 +275,7 @@ public:
bool isTBSS() const { return isBSS() && isTLS(); }
bool isVirtual() const { return ELFType == ELF::SHT_NOBITS; }
bool isRela() const { return ELFType == ELF::SHT_RELA; }
bool isReadOnly() const {
return ((ELFFlags & ELF::SHF_ALLOC) && !(ELFFlags & ELF::SHF_WRITE) &&
ELFType == ELF::SHT_PROGBITS);
}
bool isWritable() const { return (ELFFlags & ELF::SHF_WRITE); }
bool isAllocatable() const {
if (isELF()) {
return (ELFFlags & ELF::SHF_ALLOC) && !isTBSS();

View File

@@ -891,7 +891,7 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
if (!Value)
return IndirectBranchType::UNKNOWN;
if (!BC.getSectionForAddress(ArrayStart)->isReadOnly())
if (BC.getSectionForAddress(ArrayStart)->isWritable())
return IndirectBranchType::UNKNOWN;
outs() << "BOLT-INFO: fixed indirect branch detected in " << *this

View File

@@ -1152,7 +1152,7 @@ bool SimplifyRODataLoads::simplifyRODataLoads(BinaryFunction &BF) {
// memory operand. We are only interested in read-only sections.
ErrorOr<BinarySection &> DataSection =
BC.getSectionForAddress(TargetAddress);
if (!DataSection || !DataSection->isReadOnly())
if (!DataSection || DataSection->isWritable())
continue;
if (BC.getRelocationAt(TargetAddress) ||

View File

@@ -2581,7 +2581,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
ReferencedBF->registerReferencedOffset(RefFunctionOffset);
}
if (opts::Verbosity > 1 &&
!BinarySection(*BC, RelocatedSection).isReadOnly())
BinarySection(*BC, RelocatedSection).isWritable())
errs() << "BOLT-WARNING: writable reference into the middle of the "
<< formatv("function {0} detected at address {1:x}\n",
*ReferencedBF, Rel.getOffset());
@@ -3913,7 +3913,7 @@ void RewriteInstance::mapAllocatableSections(RuntimeDyld &RTDyld) {
if (!Section.hasValidSectionID())
continue;
if (Section.isReadOnly() != (SType == ST_READONLY))
if (Section.isWritable() == (SType == ST_READONLY))
continue;
if (Section.getOutputAddress()) {
@@ -4163,7 +4163,7 @@ void RewriteInstance::rewriteNoteSections() {
// Set/modify section info.
BinarySection &NewSection = BC->registerOrUpdateNoteSection(
SectionName, SectionData, Size, Section.sh_addralign,
BSec->isReadOnly(), BSec->getELFType());
!BSec->isWritable(), BSec->getELFType());
NewSection.setOutputAddress(0);
NewSection.setOutputFileOffset(NextAvailableOffset);