diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-07-20 16:43:03 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-07-20 16:43:03 +0000 |
commit | 293cf4a2ef26bb2841e9103245f08cbfdc32401c (patch) | |
tree | 0b814989805d92ac8d265a491c1375e865beb380 | |
parent | fbbe8c9163c96cc847202cd5ec2d2d162af099b9 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@276137 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/LinkerScript.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp index aaf2b9da8..f0eff8e18 100644 --- a/ELF/LinkerScript.cpp +++ b/ELF/LinkerScript.cpp @@ -450,23 +450,23 @@ template <class ELFT> bool LinkerScript<ELFT>::hasPhdrsCommands() { template <class ELFT> std::vector<size_t> LinkerScript<ELFT>::getPhdrIndicesForSection(StringRef Name) { - std::vector<size_t> Indices; - auto ItSect = std::find_if( - Opt.Commands.begin(), Opt.Commands.end(), - [Name](const SectionsCommand &Cmd) { return Cmd.Name == Name; }); - if (ItSect != Opt.Commands.end()) { - SectionsCommand &SecCmd = (*ItSect); - for (StringRef PhdrName : SecCmd.Phdrs) { - auto ItPhdr = std::find_if( - Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(), - [PhdrName](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; }); + for (SectionsCommand &Cmd : Opt.Commands) { + if (Cmd.Kind != SectionKind || Cmd.Name != Name) + continue; + + std::vector<size_t> Indices; + for (StringRef PhdrName : Cmd.Phdrs) { + auto ItPhdr = + std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(), + [&](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; }); if (ItPhdr == Opt.PhdrsCommands.rend()) error("section header '" + PhdrName + "' is not listed in PHDRS"); else Indices.push_back(std::distance(ItPhdr, Opt.PhdrsCommands.rend()) - 1); } + return Indices; } - return Indices; + return {}; } class elf::ScriptParser : public ScriptParserBase { |