[lld] r287514 - Simplify. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 20 18:10:13 PST 2016


Author: ruiu
Date: Sun Nov 20 20:10:12 2016
New Revision: 287514

URL: http://llvm.org/viewvc/llvm-project?rev=287514&view=rev
Log:
Simplify. NFC.

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=287514&r1=287513&r2=287514&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sun Nov 20 20:10:12 2016
@@ -128,17 +128,19 @@ bool BytesDataCommand::classof(const Bas
 template <class ELFT> LinkerScript<ELFT>::LinkerScript() = default;
 template <class ELFT> LinkerScript<ELFT>::~LinkerScript() = default;
 
+template <class ELFT> static StringRef basename(InputSectionBase<ELFT> *S) {
+  if (S->getFile())
+    return sys::path::filename(S->getFile()->getName());
+  return "";
+}
+
 template <class ELFT>
 bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) {
-  for (InputSectionDescription *ID : Opt.KeptSections) {
-    StringRef Filename = S->getFile()->getName();
-    if (!ID->FilePat.match(sys::path::filename(Filename)))
-      continue;
-
-    for (SectionPattern &P : ID->SectionPatterns)
-      if (P.SectionPat.match(S->Name))
-        return true;
-  }
+  for (InputSectionDescription *ID : Opt.KeptSections)
+    if (ID->FilePat.match(basename(S)))
+      for (SectionPattern &P : ID->SectionPatterns)
+        if (P.SectionPat.match(S->Name))
+          return true;
   return false;
 }
 
@@ -202,15 +204,13 @@ void LinkerScript<ELFT>::computeInputSec
       if (!S->Live || S->Assigned)
         continue;
 
-      StringRef Filename;
-      if (elf::ObjectFile<ELFT> *F = S->getFile())
-        Filename = sys::path::filename(F->getName());
-
-      if (I->FilePat.match(Filename) && !Pat.ExcludedFilePat.match(Filename) &&
-          Pat.SectionPat.match(S->Name)) {
-        I->Sections.push_back(S);
-        S->Assigned = true;
-      }
+      StringRef Filename = basename(S);
+      if (!I->FilePat.match(Filename) || Pat.ExcludedFilePat.match(Filename))
+        continue;
+      if (!Pat.SectionPat.match(S->Name))
+        continue;
+      I->Sections.push_back(S);
+      S->Assigned = true;
     }
 
     // Sort sections as instructed by SORT-family commands and --sort-section
@@ -343,9 +343,6 @@ void LinkerScript<ELFT>::processCommands
           if (shouldDefine<ELFT>(OutCmd))
             addSymbol<ELFT>(OutCmd);
 
-      if (V.empty())
-        continue;
-
       for (InputSectionBase<ELFT> *Sec : V) {
         addSection(Factory, Sec, Cmd->Name);
         if (uint32_t Subalign = Cmd->SubalignExpr ? Cmd->SubalignExpr(0) : 0)




More information about the llvm-commits mailing list