diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -992,7 +992,7 @@ bool IsReadOnly = true, unsigned ELFType = ELF::SHT_PROGBITS) { return registerOrUpdateSection(Name, ELFType, - BinarySection::getFlags(IsReadOnly), Data, + BinarySection::getFlags(!IsReadOnly), Data, Size, Alignment); } diff --git a/bolt/include/bolt/Core/BinarySection.h b/bolt/include/bolt/Core/BinarySection.h --- a/bolt/include/bolt/Core/BinarySection.h +++ b/bolt/include/bolt/Core/BinarySection.h @@ -186,12 +186,12 @@ ~BinarySection(); /// Helper function to generate the proper ELF flags from section properties. - static unsigned getFlags(bool IsReadOnly = true, bool IsText = false, + static unsigned getFlags(bool IsWritable = false, bool IsText = false, bool IsAllocatable = false) { unsigned Flags = 0; if (IsAllocatable) Flags |= ELF::SHF_ALLOC; - if (!IsReadOnly) + if (IsWritable) Flags |= ELF::SHF_WRITE; if (IsText) Flags |= ELF::SHF_EXECINSTR; diff --git a/bolt/lib/Passes/Instrumentation.cpp b/bolt/lib/Passes/Instrumentation.cpp --- a/bolt/lib/Passes/Instrumentation.cpp +++ b/bolt/lib/Passes/Instrumentation.cpp @@ -493,7 +493,7 @@ if (!BC.isX86()) return; - const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/false, + const unsigned Flags = BinarySection::getFlags(/*IsWritable=*/true, /*IsText=*/false, /*IsAllocatable=*/true); BC.registerOrUpdateSection(".bolt.instr.counters", ELF::SHT_PROGBITS, Flags, diff --git a/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp b/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp --- a/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp +++ b/bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp @@ -81,7 +81,7 @@ // sections in the input file. BinarySection &NewSection = BC.registerOrUpdateSection( UsePrefix ? NewSecPrefix + SectionName : SectionName, ELF::SHT_PROGBITS, - BinarySection::getFlags(IsReadOnly, IsCode, true), Ret, Size, + BinarySection::getFlags(!IsReadOnly, IsCode, true), Ret, Size, Alignment); if (UsePrefix) NewSection.setOutputName(SectionName); diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -3363,7 +3363,7 @@ void RewriteInstance::preregisterSections() { // Preregister sections before emission to set their order in the output. - const unsigned ROFlags = BinarySection::getFlags(/*IsReadOnly*/ true, + const unsigned ROFlags = BinarySection::getFlags(/*IsWritable*/ false, /*IsText*/ false, /*IsAllocatable*/ true); if (BinarySection *EHFrameSection = getSection(getEHFrameSectionName())) { @@ -4111,7 +4111,7 @@ int64_t NewTextSectionSize = NextAvailableAddress - NewTextSectionStartAddress; if (NewTextSectionSize) { - const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/true, + const unsigned Flags = BinarySection::getFlags(/*IsWritable=*/false, /*IsText=*/true, /*IsAllocatable=*/true); BinarySection &Section = @@ -5977,7 +5977,7 @@ assert(Out->os().tell() == EHFrameHdrFileOffset && "offset mismatch"); Out->os().write(NewEHFrameHdr.data(), NewEHFrameHdr.size()); - const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/true, + const unsigned Flags = BinarySection::getFlags(/*IsWritable=*/false, /*IsText=*/false, /*IsAllocatable=*/true); BinarySection *OldEHFrameHdrSection = getSection(".eh_frame_hdr"); diff --git a/bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp b/bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp --- a/bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp +++ b/bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp @@ -70,7 +70,7 @@ MCSection *Section = BC.isELF() ? static_cast(BC.Ctx->getELFSection( ".bolt.instr.counters", ELF::SHT_PROGBITS, - BinarySection::getFlags(/*IsReadOnly=*/false, + BinarySection::getFlags(/*IsWritable=*/true, /*IsText=*/false, /*IsAllocatable=*/true)