Index: llvm/tools/dsymutil/DwarfLinker.cpp =================================================================== --- llvm/tools/dsymutil/DwarfLinker.cpp +++ llvm/tools/dsymutil/DwarfLinker.cpp @@ -271,6 +271,19 @@ Info.Prune &= (DIE.getTag() == dwarf::DW_TAG_module) || dwarf::toUnsigned(DIE.find(dwarf::DW_AT_declaration), 0); + return Info.Prune; +} + +/// The canonical DIE offset is calculated when cloning a DIE. Therefore we +/// cannot do it during analysis, but rather have to fix it up at the beginning +/// of the clone step. +static bool updatePruning(const DWARFDie &DIE, CompileUnit &CU) { + unsigned MyIdx = CU.getOrigUnit().getDIEIndex(DIE); + CompileUnit::DIEInfo &Info = CU.getInfo(MyIdx); + + for (auto Child : DIE.children()) + Info.Prune &= updatePruning(Child, CU); + // Don't prune it if there is no definition for the DIE. Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset(); @@ -2512,14 +2525,13 @@ *CU, UnitID++, !Options.NoODR && !Options.Update, "")); } } - + // Now build the DIE parent links that we will use during the next phase. for (auto &CurrentUnit : LinkContext.CompileUnits) { auto CUDie = CurrentUnit->getOrigUnit().getUnitDIE(); if (!CUDie) continue; - analyzeContextInfo(CurrentUnit->getOrigUnit().getUnitDIE(), 0, - *CurrentUnit, &ODRContexts.getRoot(), + analyzeContextInfo(CUDie, 0, *CurrentUnit, &ODRContexts.getRoot(), UniquingStringPool, ODRContexts); } @@ -2547,6 +2559,15 @@ if (!LinkContext.ObjectFile) continue; + // We need to update all compile units before doing lookForDIEsToKeep as + // the latter can follow cross-CU links through its attributes. + for (auto &CurrentUnit : LinkContext.CompileUnits) { + auto CUDie = CurrentUnit->getOrigUnit().getUnitDIE(); + if (!CUDie) + continue; + updatePruning(CUDie, *CurrentUnit); + } + // Then mark all the DIEs that need to be present in the linked output // and collect some information about them. // Note that this loop can not be merged with the previous one because