[llvm] [DWARFVerifier] Allow overlapping ranges for ICF-merged functions (PR #117952)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 6 10:44:04 PST 2024
alx32 wrote:
Indeed the [guidelines recommend](https://dwarfstd.org/comment.html) keeping proposals focused on a single matter:
> Each proposal should be about a single topic. Please do not combine unrelated changes in a single proposal. (Changes are unrelated if they have no interactions or dependencies.)
So looks like the parent-child aspect should be separate.
Here is what I am thinking of proposing, feedback is appreciated:
```
BEGIN_PROPOSAL
```
# Clarification of Address Range Overlap Rules for Functions and Basic Blocks
## Background
Modern compiler optimizations and linker features can result in functions or basic blocks sharing the same address ranges in the final binary. Two common cases are:
1. Identical Code Folding (ICF) at link time, where identical functions are merged to reduce code size
2. Basic block section optimizations (e.g., `-fbasic-block-sections=all`), where basic blocks from different functions may be reordered and identical blocks merged
The current DWARF 5 specification's statement in Section 2.17.3 (p. 53, line 15) that "Bounded range entries in a range list may not overlap" is overly restrictive and doesn't reflect valid cases where identical code sequences are merged. The specification needs to differentiate between valid identical overlaps and invalid partial overlaps, both within range lists and between different `DW_TAG_subprogram` entries.
## Overview
This proposal seeks to:
1. Correct and clarify the rules regarding overlapping ranges within a single range list
2. Clarify rules for overlapping function ranges specified via DW_AT_low_pc/DW_AT_high_pc
3. Address the validity of identical overlapping ranges resulting from code merging optimizations
## Proposed Changes
In Section 2.17 (Location Descriptions), replace the text on p. 53, line 15:
From:
```
Bounded range entries in a range list may not overlap. There is no requirement that the entries be ordered in any particular way.
```
To:
```
Bounded range entries in a range list must not partially overlap. However, range entries may
be exactly identical (having the same low and high PC values), which commonly occurs when
compiler or linker optimizations merge identical code sequences. A partial overlap occurs
when two ranges share some but not all addresses. There is no requirement that the entries
be ordered in any particular way.
Similarly, when ranges are specified using DW_AT_low_pc and DW_AT_high_pc attributes,
multiple debugging information entries (such as DW_TAG_subprogram entries) may specify
identical ranges when they represent code that has been merged by optimizations. However,
partial overlaps between ranges are not permitted, as this would create ambiguity in
determining which code sequence is being executed at a given address.
```
## Dependencies
None
## References
1. LLVM Pull Request demonstrating the need for this clarification (+ additional discussion):
https://github.com/llvm/llvm-project/pull/117952
```
END_PROPOSAL
```
https://github.com/llvm/llvm-project/pull/117952
More information about the llvm-commits
mailing list