[BOLT][NFC] Replace ambiguous BinarySection::isReadOnly with isWritable
authorAmir Ayupov <aaupov@fb.com>
Wed, 18 Jan 2023 22:21:28 +0000 (14:21 -0800)
committerAmir Ayupov <aaupov@fb.com>
Wed, 18 Jan 2023 22:53:07 +0000 (14:53 -0800)
Address feedback in https://reviews.llvm.org/D102284#2755060

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D141733

bolt/include/bolt/Core/BinarySection.h
bolt/lib/Core/BinaryFunction.cpp
bolt/lib/Passes/BinaryPasses.cpp
bolt/lib/Rewrite/RewriteInstance.cpp

index 1160f71..20b4b5c 100644 (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();
index 060c7e8..1de8131 100644 (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
index b0c9bde..e50379b 100644 (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) ||
index ad4c1e6..154cc05 100644 (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);