Fix constraint checking in ONLY_IF_RO.

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

llvm-svn: 281772
This commit is contained in:
Rafael Espindola 2016-09-16 20:34:02 +00:00
parent be394db376
commit e71a3f8ae1
3 changed files with 25 additions and 11 deletions

View File

@ -152,7 +152,7 @@ static bool checkConstraint(uint64_t Flags, ConstraintKind Kind) {
}
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 @@ static bool matchConstraints(ArrayRef<InputSectionData *> Sections,
// 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 @@ void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I,
}
}
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 @@ LinkerScript<ELFT>::createInputSectionList(OutputSectionCommand &OutCmd) {
}
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;
}

View File

@ -186,8 +186,7 @@ public:
std::vector<OutputSectionBase<ELFT> *> *OutputSections;
private:
void computeInputSections(InputSectionDescription *,
ConstraintKind Constraint);
void computeInputSections(InputSectionDescription *);
void addSection(OutputSectionFactory<ELFT> &Factory,
InputSectionBase<ELFT> *Sec, StringRef Name);

View File

@ -0,0 +1,14 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: echo "SECTIONS { zed : ONLY_IF_RO { *(foo) *(bar) } }" > %t.script
# RUN: ld.lld -T %t.script %t.o -o %t.so -shared
# RUN: llvm-readobj -s %t.so | FileCheck %s
# CHECK: Sections [
# CHECK-NOT: zed
.section foo,"aw"
.quad 1
.section bar, "a"
.quad 2