[llvm] Solve llvm-dwp overflow problem, skipped over 4g dwo (PR #71902)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 00:15:23 PST 2023


https://github.com/Labman-001 created https://github.com/llvm/llvm-project/pull/71902

When llvm-dwp enables option 'ContinueOnCuIndexOverflow', stop packing and generate .dwp at one
<img width="625" alt="image" src="https://github.com/llvm/llvm-project/assets/150100070/77d6be24-262b-4f4c-afc0-9a6c49e133c7">


>From 9192ee2ccc1591e6a58a8ddf7cea2b1cdee470d8 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Fri, 10 Nov 2023 15:53:40 +0800
Subject: [PATCH] add main logic

---
 llvm/lib/DWP/DWP.cpp | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/DWP/DWP.cpp b/llvm/lib/DWP/DWP.cpp
index 89101ca7e5736ba..4a6b8e1869f97e4 100644
--- a/llvm/lib/DWP/DWP.cpp
+++ b/llvm/lib/DWP/DWP.cpp
@@ -201,7 +201,8 @@ static Error addAllTypesFromDWP(
     MCStreamer &Out, MapVector<uint64_t, UnitIndexEntry> &TypeIndexEntries,
     const DWARFUnitIndex &TUIndex, MCSection *OutputTypes, StringRef Types,
     const UnitIndexEntry &TUEntry, uint32_t &TypesOffset,
-    unsigned TypesContributionIndex, bool ContinueOnCuIndexOverflow) {
+    unsigned TypesContributionIndex, bool ContinueOnCuIndexOverflow
+    bool &SeeOverflowFlag) {
   Out.switchSection(OutputTypes);
   for (const DWARFUnitIndex::Entry &E : TUIndex.getRows()) {
     auto *I = E.getContributions();
@@ -235,6 +236,8 @@ static Error addAllTypesFromDWP(
       if (Error Err = sectionOverflowErrorOrWarning(
               OldOffset, TypesOffset, "Types", ContinueOnCuIndexOverflow))
         return Err;
+      SeeOverflowFlag = true;
+      Error::success();
     }
   }
   return Error::success();
@@ -244,7 +247,7 @@ static Error addAllTypesFromTypesSection(
     MCStreamer &Out, MapVector<uint64_t, UnitIndexEntry> &TypeIndexEntries,
     MCSection *OutputTypes, const std::vector<StringRef> &TypesSections,
     const UnitIndexEntry &CUEntry, uint32_t &TypesOffset,
-    bool ContinueOnCuIndexOverflow) {
+    bool ContinueOnCuIndexOverflow, bool &SeeOverflowFlag ) {
   for (StringRef Types : TypesSections) {
     Out.switchSection(OutputTypes);
     uint64_t Offset = 0;
@@ -276,6 +279,8 @@ static Error addAllTypesFromTypesSection(
         if (Error Err = sectionOverflowErrorOrWarning(
                 OldOffset, TypesOffset, "types", ContinueOnCuIndexOverflow))
           return Err;
+        SeeOverflowFlag = true;
+        return Error::success();
       }
     }
   }
@@ -613,6 +618,7 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
   uint32_t ContributionOffsets[8] = {};
   uint16_t Version = 0;
   uint32_t IndexVersion = 0;
+  bool SeeOverflowFlag = false;
 
   DWPStringPool Strings(Out, StrSection);
 
@@ -687,12 +693,15 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
         uint32_t SectionIndex = 0;
         for (auto &Section : Obj.sections()) {
           if (SectionIndex == Index) {
-            return sectionOverflowErrorOrWarning(
+            if (Error Err sectionOverflowErrorOrWarning(
                 OldOffset, ContributionOffsets[Index], *Section.getName(),
-                ContinueOnCuIndexOverflow);
+                ContinueOnCuIndexOverflow))
+              return Err;
           }
           ++SectionIndex;
         }
+        SeeOverflowFlag = true;
+        break;
       }
     }
 
@@ -722,6 +731,8 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
                     InfoSectionOffset, InfoSectionOffset + C.getLength32(),
                     "debug_info", ContinueOnCuIndexOverflow))
               return Err;
+            SeeOverflowFlag = true;
+            break;
           }
 
           UnitOffset += C.getLength32();
@@ -752,6 +763,8 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
               Info.substr(UnitOffset - C.getLength32(), C.getLength32()));
           InfoSectionOffset += C.getLength32();
         }
+        if (SeeOverflowFlag)
+          break;
       }
 
       if (!FoundCUUnit)
@@ -762,7 +775,7 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
         if (Error Err = addAllTypesFromTypesSection(
                 Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry,
                 ContributionOffsets[getContributionIndex(DW_SECT_EXT_TYPES, 2)],
-                ContinueOnCuIndexOverflow))
+                ContinueOnCuIndexOverflow, SeeOverflowFlag))
           return Err;
       }
       continue;
@@ -860,9 +873,11 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
       if (Error Err = addAllTypesFromDWP(
               Out, TypeIndexEntries, TUIndex, OutSection, TypeInputSection,
               CurEntry, ContributionOffsets[TypesContributionIndex],
-              TypesContributionIndex, ContinueOnCuIndexOverflow))
+              TypesContributionIndex, ContinueOnCuIndexOverflow, SeeOverflowFlag))
         return Err;
     }
+    if (SeeOverflowFlag)
+      break;
   }
 
   if (Version < 5) {



More information about the llvm-commits mailing list