[llvm] [llvm-gsymutil] Ensure stable ordering of merged functions (PR #120796)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 20 13:31:11 PST 2024


https://github.com/alx32 created https://github.com/llvm/llvm-project/pull/120796

Previously, the test `llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml` [was disabled](https://github.com/llvm/llvm-project/pull/119957/files) due to failing on Linux. 

The issue is that the merged functions appear in a different order in the final produced `gSYM`.
To ensure deterministic ordering of merged functions, we change the sorting of functions to use the `stable_sort` algorithm. Before merged functions, this was not an issue as the address is used as a comparator in the sorting algorithm so there was no chance of two functions testing as identical according to the comparator.

>From 53428e2096cb1ab10ca0ae45eec72bac88ba2a0d Mon Sep 17 00:00:00 2001
From: Alex B <alexborcan at meta.com>
Date: Fri, 20 Dec 2024 13:23:55 -0800
Subject: [PATCH] [llvm-gsymutil] Ensure stable ordering of merged functions

---
 llvm/lib/DebugInfo/GSYM/GsymCreator.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
index eb26c637a2ca36..14078f5aaf9a46 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymCreator.cpp
@@ -200,8 +200,8 @@ void GsymCreator::prepareMergedFunctions(OutputAggregator &Out) {
   if (Funcs.size() < 2)
     return;
 
-  // Sort the function infos by address range first
-  llvm::sort(Funcs);
+  // Sort the function infos by address range first, preserving input order
+  llvm::stable_sort(Funcs);
   std::vector<FunctionInfo> TopLevelFuncs;
 
   // Add the first function info to the top level functions



More information about the llvm-commits mailing list