[lld] r313127 - [ELF] - Refactor of Writer<ELFT>::forEachRelSec.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 00:54:48 PDT 2017


Author: grimar
Date: Wed Sep 13 00:54:47 2017
New Revision: 313127

URL: http://llvm.org/viewvc/llvm-project?rev=313127&view=rev
Log:
[ELF] - Refactor of Writer<ELFT>::forEachRelSec.

There is no need to scan over all input sections for relocatable output.
As we do not process or scan relocations anyways.
Patch moves check for Config->Relocatable out to avoid that and also removes
excessive check for isa<EhInputSection> from first for loop. 
It is excessive because we handle all of them in a second for loop below.
That all allowed to simplify code.

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

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=313127&r1=313126&r2=313127&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Sep 13 00:54:47 2017
@@ -880,24 +880,16 @@ template <class ELFT> static void sortBy
 
 template <class ELFT>
 void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) {
-  for (InputSectionBase *IS : InputSections) {
-    if (!IS->Live)
-      continue;
-    // Scan all relocations. Each relocation goes through a series
-    // of tests to determine if it needs special treatment, such as
-    // creating GOT, PLT, copy relocations, etc.
-    // Note that relocations for non-alloc sections are directly
-    // processed by InputSection::relocateNonAlloc.
-    if (!(IS->Flags & SHF_ALLOC))
-      continue;
-    if (isa<InputSection>(IS) || isa<EhInputSection>(IS))
+  // Scan all relocations. Each relocation goes through a series
+  // of tests to determine if it needs special treatment, such as
+  // creating GOT, PLT, copy relocations, etc.
+  // Note that relocations for non-alloc sections are directly
+  // processed by InputSection::relocateNonAlloc.
+  for (InputSectionBase *IS : InputSections)
+    if (IS->Live && isa<InputSection>(IS) && (IS->Flags & SHF_ALLOC))
       Fn(*IS);
-  }
-
-  if (!Config->Relocatable) {
-    for (EhInputSection *ES : In<ELFT>::EhFrame->Sections)
-      Fn(*ES);
-  }
+  for (EhInputSection *ES : In<ELFT>::EhFrame->Sections)
+    Fn(*ES);
 }
 
 template <class ELFT> void Writer<ELFT>::createSections() {
@@ -1280,7 +1272,8 @@ template <class ELFT> void Writer<ELFT>:
 
   // Scan relocations. This must be done after every symbol is declared so that
   // we can correctly decide if a dynamic relocation is needed.
-  forEachRelSec(scanRelocations<ELFT>);
+  if (!Config->Relocatable)
+    forEachRelSec(scanRelocations<ELFT>);
 
   if (InX::Plt && !InX::Plt->empty())
     InX::Plt->addSymbols();




More information about the llvm-commits mailing list