diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h --- a/llvm/include/llvm/MC/MCTargetOptions.h +++ b/llvm/include/llvm/MC/MCTargetOptions.h @@ -43,6 +43,7 @@ bool MCNoExecStack : 1; bool MCFatalWarnings : 1; bool MCNoWarn : 1; + bool MCWarnOverflow : 1; bool MCNoDeprecatedWarn : 1; bool MCSaveTempLabels : 1; bool MCUseDwarfDirectory : 1; diff --git a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h --- a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h +++ b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h @@ -38,6 +38,8 @@ bool getNoWarn(); +bool getWarnOverflow(); + bool getNoDeprecatedWarn(); std::string getABIName(); diff --git a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp --- a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp +++ b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp @@ -42,6 +42,7 @@ MCOPT(bool, ShowMCInst) MCOPT(bool, FatalWarnings) MCOPT(bool, NoWarn) +MCOPT(bool, WarnOverflow) MCOPT(bool, NoDeprecatedWarn) MCOPT(std::string, ABIName) @@ -86,6 +87,11 @@ cl::aliasopt(NoWarn)); MCBINDOPT(NoWarn); + static cl::opt WarnOverflow( + "warn-overflow", cl::desc("Warn about section overflow in dwp and " + "preserve the overflow behavior")); + MCBINDOPT(WarnOverflow); + static cl::opt NoDeprecatedWarn( "no-deprecated-warn", cl::desc("Suppress all deprecated warnings")); MCBINDOPT(NoDeprecatedWarn); @@ -109,6 +115,7 @@ Options.ABIName = getABIName(); Options.MCFatalWarnings = getFatalWarnings(); Options.MCNoWarn = getNoWarn(); + Options.MCWarnOverflow = getWarnOverflow(); Options.MCNoDeprecatedWarn = getNoDeprecatedWarn(); return Options; } diff --git a/llvm/test/tools/llvm-dwp/X86/overflow-warning.test b/llvm/test/tools/llvm-dwp/X86/overflow-warning.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-dwp/X86/overflow-warning.test @@ -0,0 +1,4 @@ +RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=hello.dwo -dwarf-version=5 %p/../Inputs/overflow/hello.s -o hello.o +RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=main.dwo -dwarf-version=5 %p/../Inputs/overflow/main.s -o main.o +RUN: llvm-dwp -e hello.o -e main.o -warn-overflow -o overflow.dwp 2>&1 | FileCheck %s +CHECK: warning: Section size overflow in debug_info.dwo diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -432,7 +432,7 @@ StringRef &CurStrSection, StringRef &CurStrOffsetSection, std::vector &CurTypesSection, StringRef &InfoSection, StringRef &AbbrevSection, StringRef &CurCUIndexSection, - StringRef &CurTUIndexSection) { + StringRef &CurTUIndexSection, bool WarnOverflow) { if (Section.isBSS()) return Error::success(); @@ -469,9 +469,13 @@ bool Overflow = false; APInt NewOffset = Offset.uadd_ov(NewLength, Overflow); if (Overflow) { - std::string SectionName = SectionPair->first().str(); - return make_error( - std::string("Section size overflow in ") + SectionName); + std::string ErrorMsg = std::string("Section size overflow in ") + + SectionPair->first().str(); + if (WarnOverflow) { + WithColor::defaultWarningHandler(make_error(ErrorMsg)); + } else { + return make_error(ErrorMsg); + } } ContributionOffsets[Index] = NewOffset.getLimitedValue(); } @@ -545,7 +549,8 @@ return std::move(DWOPaths); } -static Error write(MCStreamer &Out, ArrayRef Inputs) { +static Error write(MCStreamer &Out, ArrayRef Inputs, + bool WarnOverflow) { const auto &MCOFI = *Out.getContext().getObjectFileInfo(); MCSection *const StrSection = MCOFI.getDwarfStrDWOSection(); MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection(); @@ -599,7 +604,8 @@ CUIndexSection, TUIndexSection, Section, Out, UncompressedSections, ContributionOffsets, CurEntry, CurStrSection, CurStrOffsetSection, CurTypesSection, InfoSection, - AbbrevSection, CurCUIndexSection, CurTUIndexSection)) + AbbrevSection, CurCUIndexSection, CurTUIndexSection, + WarnOverflow)) return Err; if (InfoSection.empty()) @@ -794,7 +800,7 @@ std::make_move_iterator(DWOs->end())); } - if (auto Err = write(*MS, DWOFilenames)) { + if (auto Err = write(*MS, DWOFilenames, MCOptions.MCWarnOverflow)) { logAllUnhandledErrors(std::move(Err), WithColor::error()); return 1; }