[JITLink] Deterministic JITDylib symbol table dumps
authorStefan Gränitz <stefan.graenitz@gmail.com>
Wed, 22 Mar 2023 21:11:26 +0000 (22:11 +0100)
committerStefan Gränitz <stefan.graenitz@gmail.com>
Wed, 22 Mar 2023 21:12:15 +0000 (22:12 +0100)
Sort symbols before dumping so we get a deterministic order and can check them in tests.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D146658

llvm/lib/ExecutionEngine/Orc/Core.cpp

index 82fa4be..9b67128 100644 (file)
@@ -1438,16 +1438,23 @@ void JITDylib::dump(raw_ostream &OS) {
     OS << "Link order: " << LinkOrder << "\n"
        << "Symbol table:\n";
 
-    for (auto &KV : Symbols) {
+    // Sort symbols so we get a deterministic order and can check them in tests.
+    std::vector<std::pair<SymbolStringPtr, SymbolTableEntry *>> SymbolsSorted;
+    for (auto &KV : Symbols)
+      SymbolsSorted.emplace_back(KV.first, &KV.second);
+    std::sort(SymbolsSorted.begin(), SymbolsSorted.end(),
+              [](const auto &L, const auto &R) { return *L.first < *R.first; });
+
+    for (auto &KV : SymbolsSorted) {
       OS << "    \"" << *KV.first << "\": ";
-      if (auto Addr = KV.second.getAddress())
+      if (auto Addr = KV.second->getAddress())
         OS << Addr;
       else
         OS << "<not resolved> ";
 
-      OS << " " << KV.second.getFlags() << " " << KV.second.getState();
+      OS << " " << KV.second->getFlags() << " " << KV.second->getState();
 
-      if (KV.second.hasMaterializerAttached()) {
+      if (KV.second->hasMaterializerAttached()) {
         OS << " (Materializer ";
         auto I = UnmaterializedInfos.find(KV.first);
         assert(I != UnmaterializedInfos.end() &&