[llvm] [llvm-gsymutil] Ensure gSYM creation determinism with merged functions (PR #122921)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 07:36:40 PST 2025
https://github.com/alx32 created https://github.com/llvm/llvm-project/pull/122921
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.
>From 3d361b798fad33a34ba4015194c155f40ca5c799 Mon Sep 17 00:00:00 2001
From: Alex B <alexborcan at meta.com>
Date: Tue, 14 Jan 2025 07:32:20 -0800
Subject: [PATCH] [llvm-gsymutil] Ensure gSYM creation determinism with merged
functions
---
llvm/lib/DebugInfo/GSYM/GsymCreator.cpp | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
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
More information about the llvm-commits
mailing list