[PATCH] D66306: Fix lld on GCC 5.1 after the C++14 move

JF Bastien via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 10:46:00 PDT 2019


jfb updated this revision to Diff 215437.
jfb added a comment.

- Fall through as suggested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66306/new/

https://reviews.llvm.org/D66306

Files:
  lld/ELF/LinkerScript.cpp


Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -304,30 +304,6 @@
   return false;
 }
 
-// A helper function for the SORT() command.
-static std::function<bool(InputSectionBase *, InputSectionBase *)>
-getComparator(SortSectionPolicy k) {
-  switch (k) {
-  case SortSectionPolicy::Alignment:
-    return [](InputSectionBase *a, InputSectionBase *b) {
-      // ">" is not a mistake. Sections with larger alignments are placed
-      // before sections with smaller alignments in order to reduce the
-      // amount of padding necessary. This is compatible with GNU.
-      return a->alignment > b->alignment;
-    };
-  case SortSectionPolicy::Name:
-    return [](InputSectionBase *a, InputSectionBase *b) {
-      return a->name < b->name;
-    };
-  case SortSectionPolicy::Priority:
-    return [](InputSectionBase *a, InputSectionBase *b) {
-      return getPriority(a->name) < getPriority(b->name);
-    };
-  default:
-    llvm_unreachable("unknown sort policy");
-  }
-}
-
 // A helper function for the SORT() command.
 static bool matchConstraints(ArrayRef<InputSection *> sections,
                              ConstraintKind kind) {
@@ -343,8 +319,30 @@
 
 static void sortSections(MutableArrayRef<InputSection *> vec,
                          SortSectionPolicy k) {
-  if (k != SortSectionPolicy::Default && k != SortSectionPolicy::None)
-    llvm::stable_sort(vec, getComparator(k));
+  auto alignmentComparator = [](InputSectionBase *a, InputSectionBase *b) {
+    // ">" is not a mistake. Sections with larger alignments are placed
+    // before sections with smaller alignments in order to reduce the
+    // amount of padding necessary. This is compatible with GNU.
+    return a->alignment > b->alignment;
+  };
+  auto nameComparator = [](InputSectionBase *a, InputSectionBase *b) {
+    return a->name < b->name;
+  };
+  auto priorityComparator = [](InputSectionBase *a, InputSectionBase *b) {
+    return getPriority(a->name) < getPriority(b->name);
+  };
+
+  switch (k) {
+  case SortSectionPolicy::Default:
+  case SortSectionPolicy::None:
+    return;
+  case SortSectionPolicy::Alignment:
+    return llvm::stable_sort(vec, alignmentComparator);
+  case SortSectionPolicy::Name:
+    return llvm::stable_sort(vec, nameComparator);
+  case SortSectionPolicy::Priority:
+    return llvm::stable_sort(vec, priorityComparator);
+  }
 }
 
 // Sort sections as instructed by SORT-family commands and --sort-section


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66306.215437.patch
Type: text/x-patch
Size: 2555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190815/20a0f67f/attachment.bin>


More information about the llvm-commits mailing list