diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index a2f611a1d492..661f693537d2 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -213,11 +213,11 @@ template void LinkerScript::filter() { if (Cmd->Constraint == ConstraintKind::NoConstraint) continue; + bool RO = (Cmd->Constraint == ConstraintKind::ReadOnly); + bool RW = (Cmd->Constraint == ConstraintKind::ReadWrite); + removeElementsIf(*OutputSections, [&](OutputSectionBase *S) { bool Writable = (S->getFlags() & SHF_WRITE); - bool RO = (Cmd->Constraint == ConstraintKind::ReadOnly); - bool RW = (Cmd->Constraint == ConstraintKind::ReadWrite); - return S->getName() == Cmd->Name && ((RO && Writable) || (RW && !Writable)); });