@@ -183,14 +183,19 @@ static StringRef getSubsection(StringRef Section,
183
183
static Error sectionOverflowErrorOrWarning (uint32_t PrevOffset,
184
184
uint32_t OverflowedOffset,
185
185
StringRef SectionName,
186
- bool ContinueOnCuIndexOverflow) {
186
+ OnCuIndexOverflow OverflowOptValue,
187
+ bool &AnySectionOverflow) {
187
188
std::string Msg =
188
189
(SectionName +
189
190
Twine (" Section Contribution Offset overflow 4G. Previous Offset " ) +
190
191
Twine (PrevOffset) + Twine (" , After overflow offset " ) +
191
192
Twine (OverflowedOffset) + Twine (" ." ))
192
193
.str ();
193
- if (ContinueOnCuIndexOverflow) {
194
+ if (OverflowOptValue == OnCuIndexOverflow::Continue) {
195
+ WithColor::defaultWarningHandler (make_error<DWPError>(Msg));
196
+ return Error::success ();
197
+ } else if (OverflowOptValue == OnCuIndexOverflow::SoftStop) {
198
+ AnySectionOverflow = true ;
194
199
WithColor::defaultWarningHandler (make_error<DWPError>(Msg));
195
200
return Error::success ();
196
201
}
@@ -201,7 +206,8 @@ static Error addAllTypesFromDWP(
201
206
MCStreamer &Out, MapVector<uint64_t , UnitIndexEntry> &TypeIndexEntries,
202
207
const DWARFUnitIndex &TUIndex, MCSection *OutputTypes, StringRef Types,
203
208
const UnitIndexEntry &TUEntry, uint32_t &TypesOffset,
204
- unsigned TypesContributionIndex, bool ContinueOnCuIndexOverflow) {
209
+ unsigned TypesContributionIndex, OnCuIndexOverflow OverflowOptValue,
210
+ bool &AnySectionOverflow) {
205
211
Out.switchSection (OutputTypes);
206
212
for (const DWARFUnitIndex::Entry &E : TUIndex.getRows ()) {
207
213
auto *I = E.getContributions ();
@@ -232,9 +238,14 @@ static Error addAllTypesFromDWP(
232
238
static_assert (sizeof (OldOffset) == sizeof (TypesOffset));
233
239
TypesOffset += C.getLength ();
234
240
if (OldOffset > TypesOffset) {
235
- if (Error Err = sectionOverflowErrorOrWarning (
236
- OldOffset, TypesOffset, " Types" , ContinueOnCuIndexOverflow))
241
+ if (Error Err = sectionOverflowErrorOrWarning (OldOffset, TypesOffset,
242
+ " Types" , OverflowOptValue,
243
+ AnySectionOverflow))
237
244
return Err;
245
+ if (AnySectionOverflow) {
246
+ TypesOffset = OldOffset;
247
+ return Error::success ();
248
+ }
238
249
}
239
250
}
240
251
return Error::success ();
@@ -244,7 +255,7 @@ static Error addAllTypesFromTypesSection(
244
255
MCStreamer &Out, MapVector<uint64_t , UnitIndexEntry> &TypeIndexEntries,
245
256
MCSection *OutputTypes, const std::vector<StringRef> &TypesSections,
246
257
const UnitIndexEntry &CUEntry, uint32_t &TypesOffset,
247
- bool ContinueOnCuIndexOverflow ) {
258
+ OnCuIndexOverflow OverflowOptValue, bool &AnySectionOverflow ) {
248
259
for (StringRef Types : TypesSections) {
249
260
Out.switchSection (OutputTypes);
250
261
uint64_t Offset = 0 ;
@@ -273,9 +284,14 @@ static Error addAllTypesFromTypesSection(
273
284
uint32_t OldOffset = TypesOffset;
274
285
TypesOffset += C.getLength32 ();
275
286
if (OldOffset > TypesOffset) {
276
- if (Error Err = sectionOverflowErrorOrWarning (
277
- OldOffset, TypesOffset, " types" , ContinueOnCuIndexOverflow))
287
+ if (Error Err = sectionOverflowErrorOrWarning (OldOffset, TypesOffset,
288
+ " Types" , OverflowOptValue,
289
+ AnySectionOverflow))
278
290
return Err;
291
+ if (AnySectionOverflow) {
292
+ TypesOffset = OldOffset;
293
+ return Error::success ();
294
+ }
279
295
}
280
296
}
281
297
}
@@ -583,7 +599,7 @@ Error handleSection(
583
599
}
584
600
585
601
Error write (MCStreamer &Out, ArrayRef<std::string> Inputs,
586
- bool ContinueOnCuIndexOverflow ) {
602
+ OnCuIndexOverflow OverflowOptValue ) {
587
603
const auto &MCOFI = *Out.getContext ().getObjectFileInfo ();
588
604
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection ();
589
605
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection ();
@@ -613,6 +629,7 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
613
629
uint32_t ContributionOffsets[8 ] = {};
614
630
uint16_t Version = 0 ;
615
631
uint32_t IndexVersion = 0 ;
632
+ bool AnySectionOverflow = false ;
616
633
617
634
DWPStringPool Strings (Out, StrSection);
618
635
@@ -687,12 +704,15 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
687
704
uint32_t SectionIndex = 0 ;
688
705
for (auto &Section : Obj.sections ()) {
689
706
if (SectionIndex == Index) {
690
- return sectionOverflowErrorOrWarning (
691
- OldOffset, ContributionOffsets[Index], *Section.getName (),
692
- ContinueOnCuIndexOverflow);
707
+ if (Error Err = sectionOverflowErrorOrWarning (
708
+ OldOffset, ContributionOffsets[Index], *Section.getName (),
709
+ OverflowOptValue, AnySectionOverflow))
710
+ return Err;
693
711
}
694
712
++SectionIndex;
695
713
}
714
+ if (AnySectionOverflow)
715
+ break ;
696
716
}
697
717
}
698
718
@@ -720,8 +740,14 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
720
740
C.getLength32 ()) {
721
741
if (Error Err = sectionOverflowErrorOrWarning (
722
742
InfoSectionOffset, InfoSectionOffset + C.getLength32 (),
723
- " debug_info" , ContinueOnCuIndexOverflow ))
743
+ " debug_info" , OverflowOptValue, AnySectionOverflow ))
724
744
return Err;
745
+ if (AnySectionOverflow) {
746
+ if (Header.Version < 5 ||
747
+ Header.UnitType == dwarf::DW_UT_split_compile)
748
+ FoundCUUnit = true ;
749
+ break ;
750
+ }
725
751
}
726
752
727
753
UnitOffset += C.getLength32 ();
@@ -752,6 +778,8 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
752
778
Info.substr (UnitOffset - C.getLength32 (), C.getLength32 ()));
753
779
InfoSectionOffset += C.getLength32 ();
754
780
}
781
+ if (AnySectionOverflow)
782
+ break ;
755
783
}
756
784
757
785
if (!FoundCUUnit)
@@ -762,9 +790,11 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
762
790
if (Error Err = addAllTypesFromTypesSection (
763
791
Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry,
764
792
ContributionOffsets[getContributionIndex (DW_SECT_EXT_TYPES, 2 )],
765
- ContinueOnCuIndexOverflow ))
793
+ OverflowOptValue, AnySectionOverflow ))
766
794
return Err;
767
795
}
796
+ if (AnySectionOverflow)
797
+ break ;
768
798
continue ;
769
799
}
770
800
@@ -860,9 +890,11 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
860
890
if (Error Err = addAllTypesFromDWP (
861
891
Out, TypeIndexEntries, TUIndex, OutSection, TypeInputSection,
862
892
CurEntry, ContributionOffsets[TypesContributionIndex],
863
- TypesContributionIndex, ContinueOnCuIndexOverflow ))
893
+ TypesContributionIndex, OverflowOptValue, AnySectionOverflow ))
864
894
return Err;
865
895
}
896
+ if (AnySectionOverflow)
897
+ break ;
866
898
}
867
899
868
900
if (Version < 5 ) {
0 commit comments