[lld] [lld-macho] Fix compatibility between --icf=safe_thunks and --keep-icf-stabs (PR #116687)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 18 14:04:08 PST 2024


================
@@ -1251,26 +1255,26 @@ void SymtabSection::emitStabs() {
 
       // We use 'originalIsec' to get the file id of the symbol since 'isec()'
       // might point to the merged ICF symbol's file
-      symbolsNeedingStabs.emplace_back(defined,
-                                       defined->originalIsec->getFile()->id);
+      Defined *funcBodySym = getFuncBodySym(defined);
+      symbolsNeedingStabs.emplace_back(SymbolStabInfo{
+          defined, funcBodySym->originalIsec->getFile()->id, funcBodySym});
     }
   }
 
   llvm::stable_sort(symbolsNeedingStabs,
-                    [&](const SortingPair &a, const SortingPair &b) {
-                      return a.second < b.second;
+                    [&](const SymbolStabInfo &a, const SymbolStabInfo &b) {
+                      return a.fileId < b.fileId;
                     });
 
   // Emit STABS symbols so that dsymutil and/or the debugger can map address
   // regions in the final binary to the source and object files from which they
   // originated.
   InputFile *lastFile = nullptr;
-  for (SortingPair &pair : symbolsNeedingStabs) {
-    Defined *defined = pair.first;
+  for (const SymbolStabInfo &info : symbolsNeedingStabs) {
----------------
alx32 wrote:

We need `funcBodySym->originalIsec->getFile()->id` in `SymbolStabInfo` in order to sort. Since we already have `funcBodySym` above, I decided to store it in `SymbolStabInfo` to not re-compute it again later. 

https://github.com/llvm/llvm-project/pull/116687


More information about the llvm-commits mailing list