[ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection

Previously it was harder to read and also has a error:
command kind was not checked.

Differential revision: https://reviews.llvm.org/D22574

llvm-svn: 276137
This commit is contained in:
George Rimar 2016-07-20 16:43:03 +00:00
parent db80c0c77f
commit 31d842f55f
1 changed files with 11 additions and 11 deletions

View File

@ -450,23 +450,23 @@ template <class ELFT> bool LinkerScript<ELFT>::hasPhdrsCommands() {
template <class ELFT> template <class ELFT>
std::vector<size_t> std::vector<size_t>
LinkerScript<ELFT>::getPhdrIndicesForSection(StringRef Name) { LinkerScript<ELFT>::getPhdrIndicesForSection(StringRef Name) {
std::vector<size_t> Indices; for (SectionsCommand &Cmd : Opt.Commands) {
auto ItSect = std::find_if( if (Cmd.Kind != SectionKind || Cmd.Name != Name)
Opt.Commands.begin(), Opt.Commands.end(), continue;
[Name](const SectionsCommand &Cmd) { return Cmd.Name == Name; });
if (ItSect != Opt.Commands.end()) { std::vector<size_t> Indices;
SectionsCommand &SecCmd = (*ItSect); for (StringRef PhdrName : Cmd.Phdrs) {
for (StringRef PhdrName : SecCmd.Phdrs) { auto ItPhdr =
auto ItPhdr = std::find_if( std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(),
Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(), [&](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; });
[PhdrName](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; });
if (ItPhdr == Opt.PhdrsCommands.rend()) if (ItPhdr == Opt.PhdrsCommands.rend())
error("section header '" + PhdrName + "' is not listed in PHDRS"); error("section header '" + PhdrName + "' is not listed in PHDRS");
else else
Indices.push_back(std::distance(ItPhdr, Opt.PhdrsCommands.rend()) - 1); Indices.push_back(std::distance(ItPhdr, Opt.PhdrsCommands.rend()) - 1);
} }
return Indices;
} }
return Indices; return {};
} }
class elf::ScriptParser : public ScriptParserBase { class elf::ScriptParser : public ScriptParserBase {