[lld] [lld-macho] Reduce memory usage of printing thunks in map file (PR #122785)

Peter Rong via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 09:25:41 PST 2025


================
@@ -217,15 +203,42 @@ void macho::writeMapFile() {
                    seg->name.str().c_str(), osec->name.str().c_str());
     }
 
-  // Shared function to print an array of symbols.
-  auto printIsecArrSyms = [&](const std::vector<ConcatInputSection *> &arr) {
-    for (const ConcatInputSection *isec : arr) {
+  // Shared function to print one or two arrays of ConcatInputSection in
+  // ascending outSecOff order. The second array is optional; if provided, we
+  // interleave the printing in sorted order without allocating a merged temp
+  // array.
+  auto printIsecArrSyms = [&](const std::vector<ConcatInputSection *> &arr1,
+                              const std::vector<ConcatInputSection *> *arr2 =
+                                  nullptr) {
+    // Helper lambda that prints all symbols from one ConcatInputSection.
+    auto printOne = [&](const ConcatInputSection *isec) {
       for (Defined *sym : isec->symbols) {
-        if (!(isPrivateLabel(sym->getName()) && getSymSizeForMap(sym) == 0))
+        if (!(isPrivateLabel(sym->getName()) && getSymSizeForMap(sym) == 0)) {
----------------
DataCorrupted wrote:

Oh! I mis-interpreted the parenthesis, I thought it was `!(...) && ...`. In that case let's leave it as-is.

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


More information about the llvm-commits mailing list