Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class DWARFVerifier {
/// This is used for finding overlapping ranges in the DW_AT_ranges
/// attribute of a DIE. It is also used as a set of address ranges that
/// children address ranges must all be contained in.
std::optional<DWARFAddressRange> insert(const DWARFAddressRange &R);
std::optional<DWARFAddressRange> insert(const DWARFAddressRange &R,
bool AllowDuplicates = false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any caller passing false, or using the default false value here? It looks like there's only two callers and they're both now passing true, so we should just change the behavior categorically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - that simplifies the change quite a bit.


/// Inserts the address range info. If any of its ranges overlaps with a
/// range in an existing range info, the range info is *not* added and an
Expand Down
14 changes: 10 additions & 4 deletions llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ class DWARFDebugInfoEntry;
}

std::optional<DWARFAddressRange>
DWARFVerifier::DieRangeInfo::insert(const DWARFAddressRange &R) {
DWARFVerifier::DieRangeInfo::insert(const DWARFAddressRange &R,
bool AllowDuplicates) {
auto Begin = Ranges.begin();
auto End = Ranges.end();
auto Pos = std::lower_bound(Begin, End, R);

// Check for exact duplicates if duplicates are not allowed
if (AllowDuplicates && Pos != End && *Pos == R) {
return std::nullopt;
}

if (Pos != End) {
DWARFAddressRange Range(*Pos);
if (Pos->merge(R))
Expand Down Expand Up @@ -613,7 +619,7 @@ unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die,
// to have. Compile units often have DW_AT_ranges that can contain one or
// more dead stripped address ranges which tend to all be at the same
// address: 0 or -1.
if (auto PrevRange = RI.insert(Range)) {
if (auto PrevRange = RI.insert(Range, /*AllowDuplicates = */ true)) {
++NumErrors;
ErrorCategory.Report("DIE has overlapping DW_AT_ranges", [&]() {
error() << "DIE has overlapping ranges in DW_AT_ranges attribute: "
Expand All @@ -627,8 +633,8 @@ unsigned DWARFVerifier::verifyDieRanges(const DWARFDie &Die,
}

// Verify that children don't intersect.
bool AllowDuplicates = Die.getTag() == DW_TAG_subprogram;
const auto IntersectingChild = ParentRI.insert(RI, AllowDuplicates);
const auto IntersectingChild =
ParentRI.insert(RI, /*AllowDuplicates = */ true);
if (IntersectingChild != ParentRI.Children.end()) {
++NumErrors;
ErrorCategory.Report("DIEs have overlapping address ranges", [&]() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//--- comments.txt
#--- comments.txt

# This test verifies several scenarios with DW_TAG_subprogram address ranges:
# 1. Two subprograms can have identical ranges (shown with foo2 and foo3 having same low_pc/high_pc)
Expand All @@ -24,7 +24,10 @@
# RUN: sed '0,/Value: 0x77/{s/Value: 0x77/Value: 0x66/}' %t/test.yaml | yaml2obj | not llvm-dwarfdump --error-display=details --verify - | FileCheck %s --check-prefix=CHECK-HIGH-PC
# CHECK-HIGH-PC: error: DIEs have overlapping address ranges

//--- test.yaml
# RUN: sed '0,/LowOffset: 0x880111/{s//LowOffset: 0x880112/}' %t/test.yaml | yaml2obj | not llvm-dwarfdump --error-display=details --verify - | FileCheck %s --check-prefix=CHECK-LEX-BLOCK
# CHECK-LEX-BLOCK: DIE has overlapping ranges in DW_AT_ranges attribute

#--- test.yaml
--- !ELF
FileHeader:
Class: ELFCLASS64
Expand Down Expand Up @@ -68,6 +71,11 @@ DWARF:
Attributes:
- Attribute: DW_AT_name
Form: DW_FORM_string
- Tag: DW_TAG_lexical_block
Children: DW_CHILDREN_no
Attributes:
- Attribute: DW_AT_ranges
Form: DW_FORM_sec_offset
debug_ranges:
- Offset: 0x0
AddrSize: 0x8
Expand All @@ -91,6 +99,17 @@ DWARF:
HighOffset: 0x8000
- LowOffset: 0x0
HighOffset: 0x0
- Offset: 0xA0 # Added Range List #3 for lexical block
AddrSize: 0x8
Entries:
- LowOffset: 0x880111
HighOffset: 0x881222
- LowOffset: 0x882333
HighOffset: 0x883444
- LowOffset: 0x880111 # Overlaps with 1st range in the same list
HighOffset: 0x881222
- LowOffset: 0x0 # End of list
HighOffset: 0x0
debug_info:
- Version: 4
Entries:
Expand Down Expand Up @@ -127,5 +146,8 @@ DWARF:
Values:
- CStr: func2_with_ranges
- Value: 0x50
- AbbrCode: 5 # Added lexical block using ranges
Values:
- Value: 0xA0 # Range list index in debug_ranges
- AbbrCode: 0
...
Loading