[PATCH] D114735: [lld][macho] Stop grouping symbols by sections in mapfile.

Roger Kim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 23 10:31:46 PST 2021


Roger created this revision.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
Roger updated this revision to Diff 394916.
Roger added a comment.
Roger updated this revision to Diff 394917.
Roger updated this revision to Diff 394936.
Roger updated this revision to Diff 394937.
Roger retitled this revision from "[lld][macho] Remove dumping sections in mapfile." to "[lld][macho] Stop grouping symbols by sections in mapfile.".
Roger edited the summary of this revision.
Roger updated this revision to Diff 394941.
Roger updated this revision to Diff 394954.
Roger updated this revision to Diff 395003.
Roger updated this revision to Diff 396048.
Roger added a reviewer: int3.
Roger published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Deleted unnecessary function.


Roger added a comment.

Remove unnecessary using statement.


Roger added a comment.

Update diff name


Roger added a comment.

Update diff details.


Roger added a comment.

Small fixes.


Roger added a comment.

smal fix.


Roger added a comment.

Compilation fix.


Roger added a comment.

test passes


As per Bug 50689 <https://bugs.llvm.org/show_bug.cgi?id=50689>,

  2. getSectionSyms() puts all the symbols into a map of section -> symbols, but this seems unnecessary. This was likely copied from the ELF port, which prints a section header before the list of symbols it contains. But the Mach-O map file doesn't print these headers.

This diff removes `getSectionSyms()` and keeps all symbols in a flat vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114735

Files:
  lld/MachO/MapFile.cpp
  lld/test/MachO/map-file.s


Index: lld/test/MachO/map-file.s
===================================================================
--- lld/test/MachO/map-file.s
+++ lld/test/MachO/map-file.s
@@ -46,6 +46,6 @@
 
 # CHECK-NEXT: # Symbols:
 # CHECK-NEXT: # Address        File  Name
-# CHECK-NEXT: 0x[[#NUMBER]]    [  1]  _number
 # CHECK-NEXT: 0x[[#MAIN]]      [  1]  _main
 # CHECK-NEXT: 0x[[#FOO]]       [  2]  _foo
+# CHECK-NEXT: 0x[[#NUMBER]]    [  1]  _number
Index: lld/MachO/MapFile.cpp
===================================================================
--- lld/MachO/MapFile.cpp
+++ lld/MachO/MapFile.cpp
@@ -40,26 +40,6 @@
 using namespace lld;
 using namespace lld::macho;
 
-using SymbolMapTy = DenseMap<const InputSection *, SmallVector<Defined *, 4>>;
-
-// Returns a map from sections to their symbols.
-static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {
-  SymbolMapTy ret;
-  for (Defined *dr : syms)
-    ret[dr->isec].push_back(dr);
-
-  // Sort symbols by address. We want to print out symbols in the order they
-  // appear in the output file rather than the order they appeared in the input
-  // files.
-  for (auto &it : ret)
-    parallelSort(
-        it.second.begin(), it.second.end(), [](Defined *a, Defined *b) {
-          return a->getVA() != b->getVA() ? a->getVA() < b->getVA()
-                                          : a->getName() < b->getName();
-        });
-  return ret;
-}
-
 // Returns a list of all symbols that we want to print out.
 static std::vector<Defined *> getSymbols() {
   std::vector<Defined *> v;
@@ -126,7 +106,10 @@
 
   // Collect symbol info that we want to print out.
   std::vector<Defined *> syms = getSymbols();
-  SymbolMapTy sectionSyms = getSectionSyms(syms);
+  parallelSort(syms.begin(), syms.end(), [](Defined *a, Defined *b) {
+    return a->getVA() != b->getVA() ? a->getVA() < b->getVA()
+                                    : a->getName() < b->getName();
+  });
   DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms);
 
   // Dump table of sections
@@ -144,15 +127,9 @@
   // Dump table of symbols
   os << "# Symbols:\n";
   os << "# Address\t    File  Name\n";
-  for (InputSection *isec : inputSections) {
-    auto symsIt = sectionSyms.find(isec);
-    assert(!shouldOmitFromOutput(isec) || (symsIt == sectionSyms.end()));
-    if (symsIt == sectionSyms.end())
-      continue;
-    for (Symbol *sym : symsIt->second) {
-      os << format("0x%08llX\t[%3u] %s\n", sym->getVA(),
-                   readerToFileOrdinal[sym->getFile()], symStr[sym].c_str());
-    }
+  for (Symbol *sym : syms) {
+    os << format("0x%08llX\t[%3u] %s\n", sym->getVA(),
+                 readerToFileOrdinal[sym->getFile()], symStr[sym].c_str());
   }
 
   // TODO: when we implement -dead_strip, we should dump dead stripped symbols


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114735.396048.patch
Type: text/x-patch
Size: 2785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211223/0371ab8e/attachment.bin>


More information about the llvm-commits mailing list