Fix constraint checking in ONLY_IF_RO.

We have to look at all the relevant input sections at once.

llvm-svn: 281772
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 8881154..ea38f0e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -152,7 +152,7 @@
 }
 
 template <class ELFT>
-static bool matchConstraints(ArrayRef<InputSectionData *> Sections,
+static bool matchConstraints(ArrayRef<InputSectionBase<ELFT> *> Sections,
                              ConstraintKind Kind) {
   if (Kind == ConstraintKind::NoConstraint)
     return true;
@@ -164,8 +164,7 @@
 
 // Compute and remember which sections the InputSectionDescription matches.
 template <class ELFT>
-void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I,
-                                              ConstraintKind Constraint) {
+void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I) {
   for (const std::pair<llvm::Regex, llvm::Regex> &V : I->SectionsVec) {
     for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
       if (fileMatches(I->FileRe, V.first, sys::path::filename(F->getName()))) {
@@ -180,11 +179,6 @@
     }
   }
 
-  if (!matchConstraints<ELFT>(I->Sections, Constraint)) {
-    I->Sections.clear();
-    return;
-  }
-
   if (I->SortInner != SortSectionPolicy::None)
     std::stable_sort(I->Sections.begin(), I->Sections.end(),
                      getComparator(I->SortInner));
@@ -221,10 +215,17 @@
     }
 
     auto *Cmd = cast<InputSectionDescription>(Base.get());
-    computeInputSections(Cmd, OutCmd.Constraint);
+    computeInputSections(Cmd);
     for (InputSectionData *S : Cmd->Sections)
       Ret.push_back(static_cast<InputSectionBase<ELFT> *>(S));
   }
+
+  if (!matchConstraints<ELFT>(Ret, OutCmd.Constraint)) {
+    for (InputSectionBase<ELFT> *S : Ret)
+      S->OutSec = nullptr;
+    Ret.clear();
+  }
+
   return Ret;
 }