Skip to content

[llvm-gsymutil] Ensure gSYM creation determinism with merged functions #122921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

alx32
Copy link
Contributor

@alx32 alx32 commented Jan 14, 2025

We were seeing occasional test failures with expensive checks enabled. The issue was tracked down to a sort which should instead be a stable_sort to ensure determinism. Checked locally and the non-determinism went away.

@alx32 alx32 marked this pull request as ready for review January 14, 2025 15:37
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-debuginfo

Author: None (alx32)

Changes

We were seeing occasional test failures with expensive checks enabled. The issue was tracked down to a sort which should instead be a stable_sort to ensure determinism. Checked locally and the non-determinism went away.


Full diff: https://github.com/llvm/llvm-project/pull/122921.diff

1 Files Affected:

  • (modified) llvm/lib/DebugInfo/GSYM/GsymCreator.cpp (+21-2)
diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index 14078f5aaf9a46..f24f8c72ef0a27 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -268,15 +268,25 @@ llvm::Error GsymCreator::finalize(OutputAggregator &Out) {
   // we wouldn't find any function for range (end of Y, end of X)
   // with binary search
 
+  //////////////////////////////////////////////////////////////////////////////
+  llvm::outs() << "MyLog: Before sort:\n";
+  for (const auto &FuncInfo : Funcs) {
+    llvm::outs() << FuncInfo.Name << " " << getString(FuncInfo.Name) << "\n";
+  }
+  llvm::outs() << "\n\n";
+  //////////////////////////////////////////////////////////////////////////////
+
   const auto NumBefore = Funcs.size();
+
   // Only sort and unique if this isn't a segment. If this is a segment we
   // already finalized the main GsymCreator with all of the function infos
   // and then the already sorted and uniqued function infos were added to this
   // object.
   if (!IsSegment) {
     if (NumBefore > 1) {
-      // Sort function infos so we can emit sorted functions.
-      llvm::sort(Funcs);
+      // Sort function infos so we can emit sorted functions. Use stable sort to
+      // ensure determinism.
+      llvm::stable_sort(Funcs);
       std::vector<FunctionInfo> FinalizedFuncs;
       FinalizedFuncs.reserve(Funcs.size());
       FinalizedFuncs.emplace_back(std::move(Funcs.front()));
@@ -335,6 +345,15 @@ llvm::Error GsymCreator::finalize(OutputAggregator &Out) {
       }
       std::swap(Funcs, FinalizedFuncs);
     }
+
+    //////////////////////////////////////////////////////////////////////////////
+    llvm::outs() << "MyLog: After sort:\n";
+    for (const auto &FuncInfo : Funcs) {
+      llvm::outs() << FuncInfo.Name << " " << getString(FuncInfo.Name) << "\n";
+    }
+    llvm::outs() << "\n\n";
+    //////////////////////////////////////////////////////////////////////////////
+
     // If our last function info entry doesn't have a size and if we have valid
     // text ranges, we should set the size of the last entry since any search for
     // a high address might match our last entry. By fixing up this size, we can

@alx32 alx32 force-pushed the 07_gsymutil_fix_nondet_v3 branch from 3d361b7 to d07231d Compare January 14, 2025 15:40
@DataCorrupted
Copy link
Member

LGTM

@alx32 alx32 merged commit 93fd72c into llvm:main Jan 14, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants