[llvm] Add support for verifying .debug_names in split DWARF for CUs and TUs. (PR #101775)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 12:15:41 PDT 2024
================
@@ -1626,8 +1626,56 @@ unsigned DWARFVerifier::verifyNameIndexEntries(
UnitOffset = NI.getCUOffset(*CUIndex);
if (!UnitOffset)
continue;
- uint64_t DIEOffset = *UnitOffset + *EntryOr->getDIEUnitOffset();
- DWARFDie DIE = DCtx.getDIEForOffset(DIEOffset);
+ // For split DWARF entries we need to make sure we find the non skeleton
+ // DWARF unit that is needed and use that's DWARF unit offset as the
+ // DIE offset to add the DW_IDX_die_offset to.
+ DWARFUnit *DU = DCtx.getUnitForOffset(*UnitOffset);
+ if (DU == nullptr || DU->getOffset() != *UnitOffset) {
+ // If we didn't find a DWARF Unit from the UnitOffset, or if the offset
+ // of the unit doesn't match exactly, report an error.
+ ErrorCategory.Report(
+ "Name Index entry contains invalid CU or TU offset", [&]() {
+ error() << formatv("Name Index @ {0:x}: Entry @ {1:x} contains an "
+ "invalid CU or TU offset {1:x}.\n",
+ NI.getUnitOffset(), EntryID, *UnitOffset);
+ });
+ ++NumErrors;
+ continue;
+ }
+ // This function will try to get the non skeleton unit DIE, but if it is
+ // unable to load the .dwo file from the .dwo or .dwp, it will return the
+ // unit DIE of the DWARFUnit in "DU". So we need to check if the DWARFUnit
+ // has a .dwo file, but we couldn't load it.
+ DWARFDie NonSkeletonUnitDie = DU->getNonSkeletonUnitDIE();
+ if (DU->getDWOId() && DU->getUnitDIE() == NonSkeletonUnitDie) {
----------------
dwblaikie wrote:
> I believe it is intentional and expected behavior because as it if want all DIEs from a skeleton unit or a normal CU or TU, you call this API to try to get the DIEs regardless of if it is a skeleton unit or not.
The behavior of returning the non-split unit DIE makes sense given the name, but the behavior of returning the skeleton unit DIE if the split unit can't be found seems surprising/unintentional.
Returning the non-split unit DIE allows the "calling this function regardless of if it is a skeleton unit or not" work out, which seems good - but returning the skeleton unit DIE when the split unit isn't found seems like it'd be bad.
https://github.com/llvm/llvm-project/pull/101775
More information about the llvm-commits
mailing list