[lld] r233882 - ELF: Move x86-64-only function from DefaultLayout to X86_64TargetLayout.

Rui Ueyama ruiu at google.com
Wed Apr 1 18:36:03 PDT 2015


Author: ruiu
Date: Wed Apr  1 20:36:02 2015
New Revision: 233882

URL: http://llvm.org/viewvc/llvm-project?rev=233882&view=rev
Log:
ELF: Move x86-64-only function from DefaultLayout to X86_64TargetLayout.

Also removed some over-generalization added in r232866, such as
making a function take two parameters and pass two equivalent
arguments to the function.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
    lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=233882&r1=233881&r2=233882&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Wed Apr  1 20:36:02 2015
@@ -313,10 +313,6 @@ public:
     return _copiedDynSymNames.count(sla->name());
   }
 
-  /// \brief Handle SORT_BY_PRIORITY.
-  void sortOutputSectionByPriority(StringRef outputSectionName,
-                                   StringRef prefix);
-
 protected:
   /// \brief TargetLayouts may use these functions to reorder the input sections
   /// in a order defined by their ABI.
@@ -335,10 +331,6 @@ protected:
         new (_allocator) RelocationTable<ELFT>(_ctx, name, order));
   }
 
-private:
-  /// Helper function that returns the priority value from an input section.
-  uint32_t getPriorityFromSectionName(StringRef sectionName) const;
-
 protected:
   llvm::BumpPtrAllocator _allocator;
   SectionMapT _sectionMap;
@@ -671,44 +663,6 @@ template <class ELFT> void DefaultLayout
   }
 }
 
-template <class ELFT>
-uint32_t
-DefaultLayout<ELFT>::getPriorityFromSectionName(StringRef sectionName) const {
-  StringRef priority = sectionName.drop_front().rsplit('.').second;
-  uint32_t prio;
-  if (priority.getAsInteger(10, prio))
-    return std::numeric_limits<uint32_t>::max();
-  return prio;
-}
-
-template <class ELFT>
-void DefaultLayout<ELFT>::sortOutputSectionByPriority(
-    StringRef outputSectionName, StringRef prefix) {
-  OutputSection<ELFT> *outputSection = findOutputSection(outputSectionName);
-  if (!outputSection)
-    return;
-
-  auto sections = outputSection->sections();
-
-  std::sort(sections.begin(), sections.end(),
-            [&](Chunk<ELFT> *lhs, Chunk<ELFT> *rhs) {
-              Section<ELFT> *lhsSection = dyn_cast<Section<ELFT>>(lhs);
-              Section<ELFT> *rhsSection = dyn_cast<Section<ELFT>>(rhs);
-              if (!lhsSection || !rhsSection)
-                return false;
-              StringRef lhsSectionName = lhsSection->inputSectionName();
-              StringRef rhsSectionName = rhsSection->inputSectionName();
-
-              if (!prefix.empty()) {
-                if (!lhsSectionName.startswith(prefix) ||
-                    !rhsSectionName.startswith(prefix))
-                  return false;
-              }
-              return getPriorityFromSectionName(lhsSectionName) <
-                     getPriorityFromSectionName(rhsSectionName);
-            });
-}
-
 template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() {
   ScopedTask task(getDefaultDomain(), "assignSectionsToSegments");
   ELFLinkingContext::OutputMagic outputMagic = _ctx.getOutputMagic();

Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h?rev=233882&r1=233881&r2=233882&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h Wed Apr  1 20:36:02 2015
@@ -19,13 +19,42 @@
 
 namespace lld {
 namespace elf {
+
 class X86_64TargetLayout : public TargetLayout<X86_64ELFType> {
 public:
   X86_64TargetLayout(X86_64LinkingContext &ctx) : TargetLayout(ctx) {}
 
   void finalizeOutputSectionLayout() override {
-    sortOutputSectionByPriority(".init_array", ".init_array");
-    sortOutputSectionByPriority(".fini_array", ".fini_array");
+    sortOutputSectionByPriority<X86_64ELFType>(".init_array");
+    sortOutputSectionByPriority<X86_64ELFType>(".fini_array");
+  }
+
+private:
+  uint32_t getPriority(StringRef sectionName) const {
+    StringRef priority = sectionName.drop_front().rsplit('.').second;
+    uint32_t prio;
+    if (priority.getAsInteger(10, prio))
+      return std::numeric_limits<uint32_t>::max();
+    return prio;
+  }
+
+  template <typename T> void sortOutputSectionByPriority(StringRef prefix) {
+    OutputSection<T> *section = findOutputSection(prefix);
+    if (!section)
+      return;
+    auto sections = section->sections();
+    std::sort(sections.begin(), sections.end(),
+              [&](Chunk<T> *lhs, Chunk<T> *rhs) {
+                Section<T> *lhsSection = dyn_cast<Section<T>>(lhs);
+                Section<T> *rhsSection = dyn_cast<Section<T>>(rhs);
+                if (!lhsSection || !rhsSection)
+                  return false;
+                StringRef lhsName = lhsSection->inputSectionName();
+                StringRef rhsName = rhsSection->inputSectionName();
+                if (!lhsName.startswith(prefix) || !rhsName.startswith(prefix))
+                  return false;
+                return getPriority(lhsName) < getPriority(rhsName);
+              });
   }
 };
 





More information about the llvm-commits mailing list