From 69a9bbf106eb3832a4a02ec84f2522a4079f3dec Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Wed, 18 Jan 2023 14:21:28 -0800 Subject: [PATCH] [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 --- bolt/include/bolt/Core/BinarySection.h | 9 +++------ bolt/lib/Core/BinaryFunction.cpp | 2 +- bolt/lib/Passes/BinaryPasses.cpp | 2 +- bolt/lib/Rewrite/RewriteInstance.cpp | 6 +++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/bolt/include/bolt/Core/BinarySection.h b/bolt/include/bolt/Core/BinarySection.h index 1160f71..20b4b5c 100644 --- a/bolt/include/bolt/Core/BinarySection.h +++ b/bolt/include/bolt/Core/BinarySection.h @@ -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(); diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 060c7e8..1de8131 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -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 diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp index b0c9bde..e50379b 100644 --- a/bolt/lib/Passes/BinaryPasses.cpp +++ b/bolt/lib/Passes/BinaryPasses.cpp @@ -1152,7 +1152,7 @@ bool SimplifyRODataLoads::simplifyRODataLoads(BinaryFunction &BF) { // memory operand. We are only interested in read-only sections. ErrorOr DataSection = BC.getSectionForAddress(TargetAddress); - if (!DataSection || !DataSection->isReadOnly()) + if (!DataSection || DataSection->isWritable()) continue; if (BC.getRelocationAt(TargetAddress) || diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index ad4c1e6..154cc05 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -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); -- 2.7.4