[lld] r243232 - ELF2: Avoid calling std::sort to make output deterministic.

Rui Ueyama ruiu at google.com
Sat Jul 25 17:50:15 PDT 2015


Author: ruiu
Date: Sat Jul 25 19:50:15 2015
New Revision: 243232

URL: http://llvm.org/viewvc/llvm-project?rev=243232&view=rev
Log:
ELF2: Avoid calling std::sort to make output deterministic.

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=243232&r1=243231&r2=243232&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Jul 25 19:50:15 2015
@@ -10,6 +10,7 @@
 #include "Writer.h"
 #include "Chunks.h"
 #include "Driver.h"
+#include <map>
 
 using namespace llvm;
 using namespace llvm::ELF;
@@ -58,24 +59,14 @@ void OutputSection::addChunk(Chunk *C) {
   Header.sh_size = Off;
 }
 
-static int compare(const Chunk *A, const Chunk *B) {
-  return A->getSectionName() < B->getSectionName();
-}
-
 // Create output section objects and add them to OutputSections.
 template <class ELFT> void Writer<ELFT>::createSections() {
-  std::vector<Chunk *> Chunks = Symtab->getChunks();
-  if (Chunks.empty())
-    return;
-  std::sort(Chunks.begin(), Chunks.end(), compare);
-
-  Chunk *Prev = nullptr;
-  OutputSection *Sec = nullptr;
-  for (Chunk *C : Chunks) {
-    if (Prev == nullptr || Prev->getSectionName() != C->getSectionName()) {
+  std::map<StringRef, OutputSection *> Map;
+  for (Chunk *C : Symtab->getChunks()) {
+    OutputSection *&Sec = Map[C->getSectionName()];
+    if (!Sec) {
       Sec = new (CAlloc.Allocate()) OutputSection(C->getSectionName());
       OutputSections.push_back(Sec);
-      Prev = C;
     }
     Sec->addChunk(C);
   }





More information about the llvm-commits mailing list