Do not sort CU vectors.
authorRui Ueyama <ruiu@google.com>
Mon, 25 Sep 2017 05:30:39 +0000 (05:30 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 25 Sep 2017 05:30:39 +0000 (05:30 +0000)
We used to sort and uniquify CU vectors, but looks like CU vectors in
.gdb_index sections created by gold are not guaranteed to be sorted.

llvm-svn: 314095

lld/ELF/SyntheticSections.cpp

index 9294a99..1f8df13 100644 (file)
@@ -1797,16 +1797,17 @@ std::vector<std::vector<uint32_t>> GdbIndexSection::createCuVectors() {
         Off += Ent.Name.size() + 1;
         Ret.push_back({});
       }
-      Ret[Sym->CuVectorIndex].push_back((Ent.Type << 24) | Idx);
+
+      // gcc 5.4.1 produces a buggy .debug_gnu_pubnames that contains
+      // duplicate entries, so we want to dedup them.
+      std::vector<uint32_t> &Vec = Ret[Sym->CuVectorIndex];
+      uint32_t Val = (Ent.Type << 24) | Idx;
+      if (Vec.empty() || Vec.back() != Val)
+        Vec.push_back(Val);
     }
     Idx += Chunk.CompilationUnits.size();
   }
 
-  for (std::vector<uint32_t> &V : Ret) {
-    std::sort(V.begin(), V.end());
-    V.erase(std::unique(V.begin(), V.end()), V.end());
-  }
-
   StringPoolSize = Off;
   return Ret;
 }