Skip to content

Commit 69a9bbf

Browse files
committed
[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
1 parent c5abe89 commit 69a9bbf

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

bolt/include/bolt/Core/BinarySection.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ class BinarySection {
232232
return isText() > Other.isText();
233233

234234
// Read-only before writable.
235-
if (isReadOnly() != Other.isReadOnly())
236-
return isReadOnly() > Other.isReadOnly();
235+
if (isWritable() != Other.isWritable())
236+
return isWritable() < Other.isWritable();
237237

238238
// BSS at the end.
239239
if (isBSS() != Other.isBSS())
@@ -275,10 +275,7 @@ class BinarySection {
275275
bool isTBSS() const { return isBSS() && isTLS(); }
276276
bool isVirtual() const { return ELFType == ELF::SHT_NOBITS; }
277277
bool isRela() const { return ELFType == ELF::SHT_RELA; }
278-
bool isReadOnly() const {
279-
return ((ELFFlags & ELF::SHF_ALLOC) && !(ELFFlags & ELF::SHF_WRITE) &&
280-
ELFType == ELF::SHT_PROGBITS);
281-
}
278+
bool isWritable() const { return (ELFFlags & ELF::SHF_WRITE); }
282279
bool isAllocatable() const {
283280
if (isELF()) {
284281
return (ELFFlags & ELF::SHF_ALLOC) && !isTBSS();

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
891891
if (!Value)
892892
return IndirectBranchType::UNKNOWN;
893893

894-
if (!BC.getSectionForAddress(ArrayStart)->isReadOnly())
894+
if (BC.getSectionForAddress(ArrayStart)->isWritable())
895895
return IndirectBranchType::UNKNOWN;
896896

897897
outs() << "BOLT-INFO: fixed indirect branch detected in " << *this

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ bool SimplifyRODataLoads::simplifyRODataLoads(BinaryFunction &BF) {
11521152
// memory operand. We are only interested in read-only sections.
11531153
ErrorOr<BinarySection &> DataSection =
11541154
BC.getSectionForAddress(TargetAddress);
1155-
if (!DataSection || !DataSection->isReadOnly())
1155+
if (!DataSection || DataSection->isWritable())
11561156
continue;
11571157

11581158
if (BC.getRelocationAt(TargetAddress) ||

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
25812581
ReferencedBF->registerReferencedOffset(RefFunctionOffset);
25822582
}
25832583
if (opts::Verbosity > 1 &&
2584-
!BinarySection(*BC, RelocatedSection).isReadOnly())
2584+
BinarySection(*BC, RelocatedSection).isWritable())
25852585
errs() << "BOLT-WARNING: writable reference into the middle of the "
25862586
<< formatv("function {0} detected at address {1:x}\n",
25872587
*ReferencedBF, Rel.getOffset());
@@ -3913,7 +3913,7 @@ void RewriteInstance::mapAllocatableSections(RuntimeDyld &RTDyld) {
39133913
if (!Section.hasValidSectionID())
39143914
continue;
39153915

3916-
if (Section.isReadOnly() != (SType == ST_READONLY))
3916+
if (Section.isWritable() == (SType == ST_READONLY))
39173917
continue;
39183918

39193919
if (Section.getOutputAddress()) {
@@ -4163,7 +4163,7 @@ void RewriteInstance::rewriteNoteSections() {
41634163
// Set/modify section info.
41644164
BinarySection &NewSection = BC->registerOrUpdateNoteSection(
41654165
SectionName, SectionData, Size, Section.sh_addralign,
4166-
BSec->isReadOnly(), BSec->getELFType());
4166+
!BSec->isWritable(), BSec->getELFType());
41674167
NewSection.setOutputAddress(0);
41684168
NewSection.setOutputFileOffset(NextAvailableOffset);
41694169

0 commit comments

Comments
 (0)