Skip to content

Commit 4d1a2eb

Browse files
[llvm-debuginfo-analyzer] Fix crash with WebAssembly dead code
#136772 Incorrect handling of 'tombstone' value for WebAssembly. llvm-debuginfo-analyzer already uses the tombstone approach to identify dead code. Currently, the tombstone value is evaluated as std::numeric_limits<uint64_t>::max(). Which is wrong as it does not take into account the 'Address Byte Size' from the Compile Unit header.
1 parent 6e0c2bc commit 4d1a2eb

File tree

5 files changed

+434
-7
lines changed

5 files changed

+434
-7
lines changed

llvm/include/llvm/DebugInfo/LogicalView/Core/LVRange.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ class LLVM_ABI LVRange final : public LVObject {
5555
LVAllocator Allocator;
5656
LVRangesTree RangesTree;
5757
LVRangeEntries RangeEntries;
58-
LVAddress Lower = MaxAddress;
58+
LVAddress TombstoneAddress;
59+
LVAddress Lower;
5960
LVAddress Upper = 0;
6061

6162
public:
62-
LVRange() : LVObject(), RangesTree(Allocator) {}
63+
LVRange(LVAddress Address = MaxAddress)
64+
: LVObject(),
65+
RangesTree(Allocator), TombstoneAddress(Address), Lower(Address) {}
6366
LVRange(const LVRange &) = delete;
6467
LVRange &operator=(const LVRange &) = delete;
6568
~LVRange() = default;
@@ -76,7 +79,7 @@ class LLVM_ABI LVRange final : public LVObject {
7679

7780
void clear() {
7881
RangeEntries.clear();
79-
Lower = MaxAddress;
82+
Lower = TombstoneAddress;
8083
Upper = 0;
8184
}
8285
bool empty() const { return RangeEntries.empty(); }

llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ class LLVM_ABI LVReader {
156156
LVAddress LowerAddress, LVAddress UpperAddress);
157157
LVRange *getSectionRanges(LVSectionIndex SectionIndex);
158158

159+
// Tombstone value. Assume 64 bits. The value is updated for each
160+
// Compile Unit that is processed.
161+
LVAddress TombstoneAddress = MaxAddress;
162+
159163
// Record Compilation Unit entry.
160164
void addCompileUnitOffset(LVOffset Offset, LVScopeCompileUnit *CompileUnit) {
161165
CompileUnits.emplace(Offset, CompileUnit);
@@ -282,6 +286,9 @@ class LLVM_ABI LVReader {
282286
return CompileUnit->getCPUType();
283287
}
284288

289+
void setTombstoneAddress(LVAddress Address) { TombstoneAddress = Address; }
290+
LVAddress getTombstoneAddress() const { return TombstoneAddress; }
291+
285292
// Access to the scopes root.
286293
LVScopeRoot *getScopesRoot() const { return Root; }
287294

llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
214214
}
215215
}
216216
if (FoundLowPC) {
217-
if (CurrentLowPC == MaxAddress)
217+
if (CurrentLowPC == getTombstoneAddress())
218218
CurrentElement->setIsDiscarded();
219-
// Consider the case of WebAssembly.
220-
CurrentLowPC += WasmCodeSectionOffset;
219+
else
220+
// Consider the case of WebAssembly.
221+
CurrentLowPC += WasmCodeSectionOffset;
221222
if (CurrentElement->isCompileUnit())
222223
setCUBaseAddress(CurrentLowPC);
223224
}
@@ -271,7 +272,8 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
271272
DWARFAddressRangesVector Ranges = RangesOrError.get();
272273
for (DWARFAddressRange &Range : Ranges) {
273274
// This seems to be a tombstone for empty ranges.
274-
if (Range.LowPC == Range.HighPC)
275+
if ((Range.LowPC == Range.HighPC) ||
276+
(Range.LowPC = getTombstoneAddress()))
275277
continue;
276278
// Store the real upper limit for the address range.
277279
if (UpdateHighAddress && Range.HighPC > 0)
@@ -629,6 +631,11 @@ Error LVDWARFReader::createScopes() {
629631
: DwarfContext->dwo_compile_units();
630632
for (const std::unique_ptr<DWARFUnit> &CU : CompileUnits) {
631633

634+
// Take into account the address byte size for a correct 'tombstone'
635+
// value identification.
636+
setTombstoneAddress(
637+
dwarf::computeTombstoneAddress(CU->getAddressByteSize()));
638+
632639
// Deduction of index used for the line records.
633640
//
634641
// For the following test case: test.cpp

0 commit comments

Comments
 (0)