[lld-macho] Don't sort map file entries by name
authorJez Ng <jezng@fb.com>
Tue, 25 Oct 2022 20:26:57 +0000 (16:26 -0400)
committerJez Ng <jezng@fb.com>
Tue, 25 Oct 2022 20:29:13 +0000 (16:29 -0400)
ld64 emits them in address order but not in alphabetical order. This
sorting is particularly expensive for dead-stripped symbols (which don't
need to be sorted at all, unlike live symbols that need to be sorted by
address).

Timings for chromium_framework_less_dwarf (with the `-map` flag added to
the response file) on my 16-core Mac Pro:

             base           diff           difference (95% CI)
  sys_time   1.997 ± 0.038  2.004 ± 0.028  [  -0.6% ..   +1.3%]
  user_time  8.698 ± 0.085  8.167 ± 0.070  [  -6.6% ..   -5.6%]
  wall_time  7.965 ± 0.114  7.715 ± 0.347  [  -5.1% ..   -1.2%]
  samples    25             23

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D136536

lld/MachO/MapFile.cpp
lld/test/MachO/dead-strip.s

index 0a8053c..8f1b6a1 100644 (file)
@@ -72,13 +72,7 @@ static MapInfo gatherMapInfo() {
         info.files.push_back(file);
     }
   parallelSort(info.liveSymbols.begin(), info.liveSymbols.end(),
-               [](Defined *a, Defined *b) {
-                 return a->getVA() != b->getVA() ? a->getVA() < b->getVA()
-                                                 : a->getName() < b->getName();
-               });
-  parallelSort(
-      info.deadSymbols.begin(), info.deadSymbols.end(),
-      [](Defined *a, Defined *b) { return a->getName() < b->getName(); });
+               [](Defined *a, Defined *b) { return a->getVA() < b->getVA(); });
   return info;
 }
 
index a9892fd..88b1538 100644 (file)
 ## Check that dead stripped symbols get listed properly.
 # RUN: FileCheck --check-prefix=MAP %s < %t/map
 
-# MAP: _main
+# MAP:        _main
 # MAP-LABEL: Dead Stripped Symbols
-# MAP: <<dead>> 0x00000001 [ 1] _unref_com
-# MAP: <<dead>> 0x00000008 [ 1] _unref_data
-# MAP: <<dead>> 0x00000006 [ 1] _unref_extern
-# MAP: <<dead>> 0x00000001 [ 1] _unref_local
-# MAP: <<dead>> 0x00000007 [ 1] _unref_private_extern
-# MAP: <<dead>> 0x00000008 [ 1] l_unref_data
+# MAP-DAG:   <<dead>> 0x00000001 [ 1] _unref_com
+# MAP-DAG:   <<dead>> 0x00000008 [ 1] _unref_data
+# MAP-DAG:   <<dead>> 0x00000006 [ 1] _unref_extern
+# MAP-DAG:   <<dead>> 0x00000001 [ 1] _unref_local
+# MAP-DAG:   <<dead>> 0x00000007 [ 1] _unref_private_extern
+# MAP-DAG:   <<dead>> 0x00000008 [ 1] l_unref_data
 
 ## Run dead stripping on code without any dead symbols.
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \