[lld] 3c94d5d - [ELF] addOrphanSections: avoid std::function

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 27 15:57:44 PST 2021


Author: Fangrui Song
Date: 2021-12-27T15:57:38-08:00
New Revision: 3c94d5d9d233a8e20efd2b4d4f883d7482303b60

URL: https://github.com/llvm/llvm-project/commit/3c94d5d9d233a8e20efd2b4d4f883d7482303b60
DIFF: https://github.com/llvm/llvm-project/commit/3c94d5d9d233a8e20efd2b4d4f883d7482303b60.diff

LOG: [ELF] addOrphanSections: avoid std::function

Added: 
    

Modified: 
    lld/ELF/LinkerScript.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 7c67ee53adba..db20dd36241c 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -829,8 +829,7 @@ void LinkerScript::addOrphanSections() {
   StringMap<TinyPtrVector<OutputSection *>> map;
   SmallVector<OutputSection *, 0> v;
 
-  std::function<void(InputSectionBase *)> add;
-  add = [&](InputSectionBase *s) {
+  auto add = [&](InputSectionBase *s) {
     if (s->isLive() && !s->parent) {
       orphanSections.push_back(s);
 
@@ -846,11 +845,6 @@ void LinkerScript::addOrphanSections() {
                s->getOutputSection()->sectionIndex == UINT32_MAX);
       }
     }
-
-    if (config->relocatable)
-      for (InputSectionBase *depSec : s->dependentSections)
-        if (depSec->flags & SHF_LINK_ORDER)
-          add(depSec);
   };
 
   // For further --emit-reloc handling code we need target output section
@@ -869,6 +863,10 @@ void LinkerScript::addOrphanSections() {
         if (auto *relIS = dyn_cast_or_null<InputSectionBase>(rel->parent))
           add(relIS);
     add(isec);
+    if (config->relocatable)
+      for (InputSectionBase *depSec : isec->dependentSections)
+        if (depSec->flags & SHF_LINK_ORDER)
+          add(depSec);
   }
 
   // If no SECTIONS command was given, we should insert sections commands


        


More information about the llvm-commits mailing list