Skip to content

Commit eb002d1

Browse files
committed
wasm: narrow DWARF range constant cleanup
1 parent 1c489eb commit eb002d1

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

‎src/wasm/wasm-debug.cpp‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ bool hasDWARFSections(const Module& wasm) {
6161
#ifdef BUILD_LLVM_DWARF
6262

6363
// In wasm32 the address size is 32 bits.
64-
static constexpr size_t AddressSize = 4;
64+
static const size_t AddressSize = 4;
6565
static constexpr size_t RangeEntrySize = 2 * AddressSize;
6666

6767
// DWARF v6 reserves the all-ones address for a non-existent entity. LLVM also
6868
// recognizes max-minus-one in legacy range and location data, where all-ones
6969
// is already the base-address-selection marker. Zero is a historical linker
7070
// tombstone, but is context-dependent because it can also be a valid address.
71-
static constexpr BinaryLocation DwarfTombstone = BinaryLocation(-1);
72-
static constexpr BinaryLocation LegacyRangeTombstone = BinaryLocation(-2);
71+
static constexpr BinaryLocation AllOnesAddress = BinaryLocation(-1);
72+
static constexpr BinaryLocation LegacyTombstoneAddress = BinaryLocation(-2);
7373
static constexpr BinaryLocation EmptyRangeAddress = 1;
7474
static constexpr size_t NoParent = size_t(-1);
7575

@@ -682,7 +682,7 @@ struct LocationUpdater {
682682
};
683683

684684
static bool isNonzeroTombstone(BinaryLocation location) {
685-
return location == DwarfTombstone || location == LegacyRangeTombstone;
685+
return location == AllOnesAddress || location == LegacyTombstoneAddress;
686686
}
687687

688688
// Keep accepting the historical zero tombstone. Callers whose encoding permits
@@ -916,8 +916,8 @@ static void updateDIE(const llvm::DWARFDebugInfoEntry& DIE,
916916
if (!isNonzeroTombstone(newLowPC) &&
917917
tag != llvm::dwarf::DW_TAG_compile_unit &&
918918
(newValue == 0 || newValue < newLowPC)) {
919-
newLowPC = DwarfTombstone;
920-
newValue = isRelative ? newLowPC : DwarfTombstone;
919+
newLowPC = AllOnesAddress;
920+
newValue = isRelative ? newLowPC : AllOnesAddress;
921921
assert(lowPCValue);
922922
lowPCValue->Value = newLowPC;
923923
} else if (newValue > newLowPC) {
@@ -932,7 +932,7 @@ static void updateDIE(const llvm::DWARFDebugInfoEntry& DIE,
932932
});
933933
if (unresolvedZeroLowPC) {
934934
assert(lowPCValue);
935-
lowPCValue->Value = DwarfTombstone;
935+
lowPCValue->Value = AllOnesAddress;
936936
}
937937
}
938938

@@ -982,10 +982,10 @@ static void updateRanges(llvm::DWARFYAML::Data& yaml,
982982
for (auto& range : yaml.Ranges) {
983983
BinaryLocation oldStart = range.Start, oldEnd = range.End, newStart = 0,
984984
newEnd = 0;
985-
if ((oldStart == 0 && oldEnd == 0) || oldStart == DwarfTombstone) {
985+
if ((oldStart == 0 && oldEnd == 0) || oldStart == AllOnesAddress) {
986986
newStart = oldStart;
987987
newEnd = oldEnd;
988-
} else if (oldStart == LegacyRangeTombstone || isTombstone(oldEnd)) {
988+
} else if (oldStart == LegacyTombstoneAddress || isTombstone(oldEnd)) {
989989
newStart = EmptyRangeAddress;
990990
newEnd = EmptyRangeAddress;
991991
} else {
@@ -1067,13 +1067,13 @@ static void readDIEAddressRanges(DIEAddressInfo& info,
10671067
terminated = true;
10681068
break;
10691069
}
1070-
if (start == DwarfTombstone) {
1070+
if (start == AllOnesAddress) {
10711071
base = end;
10721072
continue;
10731073
}
10741074
// A zero start is a valid offset from the current base. Only (0, 0),
10751075
// handled above, terminates the list.
1076-
if (start == LegacyRangeTombstone || isTombstone(end)) {
1076+
if (start == LegacyTombstoneAddress || isTombstone(end)) {
10771077
continue;
10781078
}
10791079
auto absoluteStart = base + start;
@@ -1111,7 +1111,7 @@ static void writeRangeList(DIEAddressInfo& info, llvm::DWARFYAML::Data& yaml) {
11111111
info.rangesValue->Value = yaml.Ranges.size() * RangeEntrySize;
11121112
// Use an explicit zero base so the new entries remain absolute and can be
11131113
// updated again without recovering an implicit compile-unit base.
1114-
yaml.Ranges.push_back(llvm::DWARFYAML::Range{DwarfTombstone, 0, 0});
1114+
yaml.Ranges.push_back(llvm::DWARFYAML::Range{AllOnesAddress, 0, 0});
11151115
for (auto [start, end] : info.ranges.get()) {
11161116
yaml.Ranges.push_back(llvm::DWARFYAML::Range{start, end, 0});
11171117
}
@@ -1144,10 +1144,10 @@ writeUnavailableDIE(DIEAddressInfo& info,
11441144
[&](const llvm::DWARFAbbreviationDeclaration::AttributeSpec& attrSpec,
11451145
llvm::DWARFYAML::FormValue& yamlValue) {
11461146
if (attrSpec.Attr == llvm::dwarf::DW_AT_low_pc) {
1147-
yamlValue.Value = DwarfTombstone;
1147+
yamlValue.Value = AllOnesAddress;
11481148
} else if (attrSpec.Attr == llvm::dwarf::DW_AT_high_pc) {
11491149
yamlValue.Value =
1150-
attrSpec.Form == llvm::dwarf::DW_FORM_data4 ? 0 : DwarfTombstone;
1150+
attrSpec.Form == llvm::dwarf::DW_FORM_data4 ? 0 : AllOnesAddress;
11511151
} else if (attrSpec.Attr == llvm::dwarf::DW_AT_ranges) {
11521152
if (!emptyRangeListOffset) {
11531153
emptyRangeListOffset = yaml.Ranges.size() * RangeEntrySize;
@@ -1291,8 +1291,12 @@ static void repairDIEAddressRanges(const BinaryenDWARFInfo& dwarfInfo,
12911291
});
12921292
}
12931293

1294+
// A location that is ignoreable, i.e., not a special value like 0 or -1 (which
1295+
// would indicate an end or a base in .debug_loc).
1296+
static const BinaryLocation IGNOREABLE_LOCATION = 1;
1297+
12941298
static bool isNewBaseLoc(const llvm::DWARFYAML::Loc& loc) {
1295-
return loc.Start == DwarfTombstone;
1299+
return loc.Start == BinaryLocation(-1);
12961300
}
12971301

12981302
static bool isEndMarkerLoc(const llvm::DWARFYAML::Loc& loc) {
@@ -1342,15 +1346,15 @@ static void updateLoc(llvm::DWARFYAML::Data& yaml,
13421346
locationUpdater.getNewStart(futureLoc.Start + oldBase);
13431347
// If we found a valid mapping, this is a relevant value for us. If the
13441348
// optimizer removed it, it's a 0, and we can ignore it here - we will
1345-
// emit EmptyRangeAddress for it later anyhow.
1349+
// emit IGNOREABLE_LOCATION for it later anyhow.
13461350
if (updatedStart != 0) {
13471351
smallest = std::min(smallest, updatedStart);
13481352
}
13491353
}
13501354
// If we found no valid values that will be relativized here, just use 0
13511355
// as the new (never-to-be-used) base, which is less confusing (otherwise
13521356
// the value looks like it means something).
1353-
if (smallest == DwarfTombstone) {
1357+
if (smallest == BinaryLocation(-1)) {
13541358
smallest = 0;
13551359
}
13561360
newBase = newEnd = smallest;
@@ -1366,7 +1370,7 @@ static void updateLoc(llvm::DWARFYAML::Data& yaml,
13661370
if (newStart == 0 || newEnd == 0 || newStart > newEnd) {
13671371
// This part of the loc no longer has a mapping, or after the mapping
13681372
// it is no longer a proper span, so we must ignore it.
1369-
newStart = newEnd = EmptyRangeAddress;
1373+
newStart = newEnd = IGNOREABLE_LOCATION;
13701374
} else {
13711375
// We picked a new base that ensures it is smaller than the values we
13721376
// will relativize to it.
@@ -1381,7 +1385,7 @@ static void updateLoc(llvm::DWARFYAML::Data& yaml,
13811385
// This can happen if the very first span in a compile unit is an
13821386
// empty span, in which case relative to the base of the compile unit
13831387
// we would have (0, 0).
1384-
newStart = newEnd = EmptyRangeAddress;
1388+
newStart = newEnd = IGNOREABLE_LOCATION;
13851389
}
13861390
}
13871391
// The loc start and end markers have been preserved. However, TODO

0 commit comments

Comments
 (0)