Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -258,6 +258,18 @@ } template +bool canAddSection(InputSectionBase *C, ConstraintKind Kind) { + if (Kind == NoConstraint) + return true; + bool Writable = C->getSectionHdr()->sh_flags & SHF_WRITE; + if (Kind == ReadWrite && !Writable) + return false; + if (Kind == ReadOnly && Writable) + return false; + return true; +} + +template std::vector *> LinkerScript::createSections(OutputSectionFactory &Factory) { typedef const std::unique_ptr> ObjectFile; @@ -273,12 +285,7 @@ std::tie(Sec, IsNew) = Factory.create(C, Name); if (IsNew) Result.push_back(Sec); - if ((!(C->getSectionHdr()->sh_flags & SHF_WRITE)) && - Constraint == ReadWrite) { - Removed.insert(Sec); - return; - } - if ((C->getSectionHdr()->sh_flags & SHF_WRITE) && Constraint == ReadOnly) { + if (!canAddSection(C, Constraint)) { Removed.insert(Sec); return; }