Implement ONLY_IF_RO/ONLY_IF_RW like bfd.

The actual logic is to keep the output section if the output section
would have been ro/rw.

This is both simpler and more practical, as the intention is linker
scripts is to always keep of of a pair of ONLY_IF_RO/ONLY_IF_RW.

llvm-svn: 282099
This commit is contained in:
Rafael Espindola
2016-09-21 18:33:44 +00:00
parent 0f8b5d65f6
commit e746e52c7b
2 changed files with 36 additions and 9 deletions

View File

@@ -138,22 +138,17 @@ getComparator(SortSectionPolicy K) {
}
}
static bool checkConstraint(uint64_t Flags, ConstraintKind Kind) {
bool RO = (Kind == ConstraintKind::ReadOnly);
bool RW = (Kind == ConstraintKind::ReadWrite);
bool Writable = Flags & SHF_WRITE;
return !(RO && Writable) && !(RW && !Writable);
}
template <class ELFT>
static bool matchConstraints(ArrayRef<InputSectionBase<ELFT> *> Sections,
ConstraintKind Kind) {
if (Kind == ConstraintKind::NoConstraint)
return true;
return llvm::all_of(Sections, [=](InputSectionData *Sec2) {
bool IsRW = llvm::any_of(Sections, [=](InputSectionData *Sec2) {
auto *Sec = static_cast<InputSectionBase<ELFT> *>(Sec2);
return checkConstraint(Sec->getSectionHdr()->sh_flags, Kind);
return Sec->getSectionHdr()->sh_flags & SHF_WRITE;
});
return (IsRW && Kind == ConstraintKind::ReadWrite) ||
(!IsRW && Kind == ConstraintKind::ReadOnly);
}
static void sortSections(InputSectionData **Begin, InputSectionData **End,