@@ -461,17 +461,11 @@ getUnitForOffset(DIEBuilder &Builder, DWARFContext &DWCtx,
461461 return nullptr ;
462462}
463463
464- uint32_t
465- DIEBuilder::finalizeDIEs (DWARFUnit &CU, DIE &Die,
466- std::optional<BOLTDWARF5AccelTableData *> Parent,
467- uint32_t NumberParentsInChain, uint32_t &CurOffset) {
464+ uint32_t DIEBuilder::finalizeDIEs (DWARFUnit &CU, DIE &Die,
465+ uint32_t &CurOffset) {
468466 getState ().DWARFDieAddressesParsed .erase (Die.getOffset ());
469467 uint32_t CurSize = 0 ;
470468 Die.setOffset (CurOffset);
471- std::optional<BOLTDWARF5AccelTableData *> NameEntry =
472- DebugNamesTable.addAccelTableEntry (
473- CU, Die, SkeletonCU ? SkeletonCU->getDWOId () : std::nullopt ,
474- NumberParentsInChain, Parent);
475469 // It is possible that an indexed debugging information entry has a parent
476470 // that is not indexed (for example, if its parent does not have a name
477471 // attribute). In such a case, a parent attribute may point to a nameless
@@ -485,18 +479,13 @@ DIEBuilder::finalizeDIEs(DWARFUnit &CU, DIE &Die,
485479 // If Parent is nullopt and NumberParentsInChain is not zero, then forward
486480 // declaration was encountered in this DF traversal. Propagating nullopt for
487481 // Parent to children.
488- if (!Parent && NumberParentsInChain)
489- NameEntry = std::nullopt ;
490- if (NameEntry)
491- ++NumberParentsInChain;
492482 for (DIEValue &Val : Die.values ())
493483 CurSize += Val.sizeOf (CU.getFormParams ());
494484 CurSize += getULEB128Size (Die.getAbbrevNumber ());
495485 CurOffset += CurSize;
496486
497487 for (DIE &Child : Die.children ()) {
498- uint32_t ChildSize =
499- finalizeDIEs (CU, Child, NameEntry, NumberParentsInChain, CurOffset);
488+ uint32_t ChildSize = finalizeDIEs (CU, Child, CurOffset);
500489 CurSize += ChildSize;
501490 }
502491 // for children end mark.
@@ -514,10 +503,9 @@ void DIEBuilder::finish() {
514503 DIE *UnitDIE = getUnitDIEbyUnit (CU);
515504 uint32_t HeaderSize = CU.getHeaderSize ();
516505 uint32_t CurOffset = HeaderSize;
517- DebugNamesTable.setCurrentUnit (CU, UnitStartOffset);
518506 std::vector<std::optional<BOLTDWARF5AccelTableData *>> Parents;
519507 Parents.push_back (std::nullopt );
520- finalizeDIEs (CU, *UnitDIE, std:: nullopt , 0 , CurOffset);
508+ finalizeDIEs (CU, *UnitDIE, CurOffset);
521509
522510 DWARFUnitInfo &CurUnitInfo = getUnitInfoByDwarfUnit (CU);
523511 CurUnitInfo.UnitOffset = UnitStartOffset;
@@ -548,6 +536,48 @@ void DIEBuilder::finish() {
548536 dbgs () << Twine::utohexstr (Address) << " \n " ;
549537 }
550538 }
539+ }
540+
541+ void DIEBuilder::populateDebugNamesTable (
542+ DWARFUnit &CU, const DIE &Die,
543+ std::optional<BOLTDWARF5AccelTableData *> Parent,
544+ uint32_t NumberParentsInChain) {
545+ std::optional<BOLTDWARF5AccelTableData *> NameEntry =
546+ DebugNamesTable.addAccelTableEntry (
547+ CU, Die, SkeletonCU ? SkeletonCU->getDWOId () : std::nullopt ,
548+ NumberParentsInChain, Parent);
549+ if (!Parent && NumberParentsInChain)
550+ NameEntry = std::nullopt ;
551+ if (NameEntry)
552+ ++NumberParentsInChain;
553+
554+ for (const DIE &Child : Die.children ())
555+ populateDebugNamesTable (CU, Child, NameEntry, NumberParentsInChain);
556+ }
557+
558+ void DIEBuilder::updateDebugNamesTable () {
559+ auto finalizeDebugNamesTableForCU = [&](DWARFUnit &CU,
560+ uint64_t &UnitStartOffset) -> void {
561+ DIE *UnitDIE = getUnitDIEbyUnit (CU);
562+ DebugNamesTable.setCurrentUnit (CU, UnitStartOffset);
563+ populateDebugNamesTable (CU, *UnitDIE, std::nullopt , 0 );
564+
565+ DWARFUnitInfo &CurUnitInfo = getUnitInfoByDwarfUnit (CU);
566+ UnitStartOffset += CurUnitInfo.UnitLength ;
567+ };
568+
569+ uint64_t TypeUnitStartOffset = 0 ;
570+ for (DWARFUnit *CU : getState ().DUList ) {
571+ if (!(CU->getVersion () < 5 && CU->isTypeUnit ()))
572+ break ;
573+ finalizeDebugNamesTableForCU (*CU, TypeUnitStartOffset);
574+ }
575+
576+ for (DWARFUnit *CU : getState ().DUList ) {
577+ if (CU->getVersion () < 5 && CU->isTypeUnit ())
578+ continue ;
579+ finalizeDebugNamesTableForCU (*CU, DebugNamesUnitSize);
580+ }
551581 updateReferences ();
552582}
553583
0 commit comments