mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 11:02:04 +08:00
[BOLT] Remove cantFail in getAddressRanges calls
Summary: We may have a CU with empty ranges, so accept errors coming from DWARFDie::getAddressRanges(). This happens when using tools that selectively strip debuginfo from the binary. (cherry picked from FBD27602731)
This commit is contained in:
committed by
Maksim Panchenko
parent
f1bfb18ceb
commit
35732d954b
@@ -1472,7 +1472,12 @@ void BinaryContext::preprocessDebugInfo() {
|
||||
std::vector<CURange> AllRanges;
|
||||
AllRanges.reserve(DwCtx->getNumCompileUnits());
|
||||
for (const auto &CU : DwCtx->compile_units()) {
|
||||
for (auto &Range : cantFail(CU->getUnitDIE().getAddressRanges())) {
|
||||
auto RangesOrError = CU->getUnitDIE().getAddressRanges();
|
||||
if (!RangesOrError) {
|
||||
consumeError(RangesOrError.takeError());
|
||||
continue;
|
||||
}
|
||||
for (auto &Range : *RangesOrError) {
|
||||
// Parts of the debug info could be invalidated due to corresponding code
|
||||
// being removed from the binary by the linker. Hence we check if the
|
||||
// address is a valid one.
|
||||
|
||||
@@ -149,12 +149,16 @@ void DWARFRewriter::updateUnitDebugInfo(size_t CUIndex, DWARFUnit *Unit) {
|
||||
DWARFDie DIE(Unit, &Die);
|
||||
switch (DIE.getTag()) {
|
||||
case dwarf::DW_TAG_compile_unit: {
|
||||
const DWARFAddressRangesVector ModuleRanges =
|
||||
cantFail(DIE.getAddressRanges());
|
||||
auto ModuleRangesOrError = DIE.getAddressRanges();
|
||||
if (!ModuleRangesOrError) {
|
||||
consumeError(ModuleRangesOrError.takeError());
|
||||
break;
|
||||
}
|
||||
DWARFAddressRangesVector ModuleRanges = *ModuleRangesOrError;
|
||||
DebugAddressRangesVector OutputRanges =
|
||||
BC.translateModuleAddressRanges(ModuleRanges);
|
||||
const uint64_t RangesSectionOffset =
|
||||
RangesSectionWriter->addRanges(OutputRanges);
|
||||
RangesSectionWriter->addRanges(OutputRanges);
|
||||
ARangesSectionWriter->addCURanges(Unit->getOffset(),
|
||||
std::move(OutputRanges));
|
||||
updateDWARFObjectAddressRanges(DIE, RangesSectionOffset);
|
||||
@@ -166,7 +170,12 @@ void DWARFRewriter::updateUnitDebugInfo(size_t CUIndex, DWARFUnit *Unit) {
|
||||
uint64_t Address;
|
||||
uint64_t SectionIndex, HighPC;
|
||||
if (!DIE.getLowAndHighPC(Address, HighPC, SectionIndex)) {
|
||||
auto Ranges = cantFail(DIE.getAddressRanges());
|
||||
auto RangesOrError = DIE.getAddressRanges();
|
||||
if (!RangesOrError) {
|
||||
consumeError(RangesOrError.takeError());
|
||||
break;
|
||||
}
|
||||
DWARFAddressRangesVector Ranges = *RangesOrError;
|
||||
// Not a function definition.
|
||||
if (Ranges.empty())
|
||||
break;
|
||||
@@ -238,6 +247,8 @@ void DWARFRewriter::updateUnitDebugInfo(size_t CUIndex, DWARFUnit *Unit) {
|
||||
);
|
||||
RangesSectionOffset = RangesSectionWriter->addRanges(
|
||||
std::move(OutputRanges), CachedRanges);
|
||||
} else if (!RangesOrError) {
|
||||
consumeError(RangesOrError.takeError());
|
||||
}
|
||||
updateDWARFObjectAddressRanges(DIE, RangesSectionOffset);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user