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

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 09:50:34 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL276137: [ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D22574?vs=64701&id=64703#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22574

Files:
  lld/trunk/ELF/LinkerScript.cpp

Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -450,23 +450,23 @@
 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22574.64703.patch
Type: text/x-patch
Size: 1514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160720/3f5f169b/attachment.bin>


More information about the llvm-commits mailing list