[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:38:32 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
Author: None (alx32)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/122921
More information about the llvm-commits
mailing list