55 for (
auto &Unit :
Dwarf.compile_units()) {
56 Size += Unit->getLength();
66 return LHS <
RHS->getOrigUnit().getNextUnitOffset();
68 return CU != Units.end() ?
CU->get() :
nullptr;
74DWARFDie DWARFLinker::resolveDIEReference(
const DWARFFile &File,
76 const DWARFFormValue &RefValue,
78 CompileUnit *&RefCU) {
81 if (std::optional<uint64_t> Off = RefValue.getAsRelativeReference()) {
82 RefOffset = RefValue.getUnit()->getOffset() + *Off;
83 }
else if (Off = RefValue.getAsDebugInfoReference(); Off) {
86 reportWarning(
"Unsupported reference type", File, &DIE);
90 if (
const auto RefDie = RefCU->getOrigUnit().getDIEForOffset(RefOffset)) {
97 reportWarning(
"could not find referenced DIE", File, &DIE);
107 case dwarf::DW_AT_type:
108 case dwarf::DW_AT_containing_type:
109 case dwarf::DW_AT_specification:
110 case dwarf::DW_AT_abstract_origin:
111 case dwarf::DW_AT_import:
112 case dwarf::DW_AT_LLVM_alloc_type:
120 case dwarf::DW_TAG_array_type:
121 case dwarf::DW_TAG_class_type:
122 case dwarf::DW_TAG_enumeration_type:
123 case dwarf::DW_TAG_pointer_type:
124 case dwarf::DW_TAG_reference_type:
125 case dwarf::DW_TAG_string_type:
126 case dwarf::DW_TAG_structure_type:
127 case dwarf::DW_TAG_subroutine_type:
128 case dwarf::DW_TAG_template_alias:
129 case dwarf::DW_TAG_typedef:
130 case dwarf::DW_TAG_union_type:
131 case dwarf::DW_TAG_ptr_to_member_type:
132 case dwarf::DW_TAG_set_type:
133 case dwarf::DW_TAG_subrange_type:
134 case dwarf::DW_TAG_base_type:
135 case dwarf::DW_TAG_const_type:
136 case dwarf::DW_TAG_constant:
137 case dwarf::DW_TAG_file_type:
138 case dwarf::DW_TAG_namelist:
139 case dwarf::DW_TAG_packed_type:
140 case dwarf::DW_TAG_volatile_type:
141 case dwarf::DW_TAG_restrict_type:
142 case dwarf::DW_TAG_atomic_type:
143 case dwarf::DW_TAG_interface_type:
144 case dwarf::DW_TAG_unspecified_type:
145 case dwarf::DW_TAG_shared_type:
146 case dwarf::DW_TAG_immutable_type:
157DWARFLinker::DIECloner::getCanonicalDIEName(DWARFDie Die,
const DWARFFile &File,
162 std::optional<DWARFFormValue>
Ref;
164 auto GetDieName = [](
const DWARFDie &
D) -> llvm::StringRef {
165 auto NameForm =
D.find(llvm::dwarf::DW_AT_name);
169 auto NameOrErr = NameForm->getAsCString();
178 llvm::StringRef
Name = GetDieName(Die);
183 if (!(
Ref = Die.find(llvm::dwarf::DW_AT_specification)) &&
184 !(
Ref = Die.find(llvm::dwarf::DW_AT_abstract_origin)))
187 Die = Linker.resolveDIEReference(File, CompileUnits, *
Ref, Die, Unit);
193 unsigned SpecIdx =
Unit->getOrigUnit().getDIEIndex(Die);
194 CompileUnit::DIEInfo &SpecInfo =
Unit->getInfo(SpecIdx);
195 if (SpecInfo.Ctxt && SpecInfo.Ctxt->hasCanonicalDIE()) {
196 if (!SpecInfo.Ctxt->getCanonicalName().empty()) {
197 Name = SpecInfo.Ctxt->getCanonicalName();
202 Name = GetDieName(Die);
210bool DWARFLinker::DIECloner::getDIENames(
212 const DWARFFile &File, CompileUnit &Unit,
bool StripTemplate) {
216 if (Die.getTag() == dwarf::DW_TAG_lexical_block)
222 if (!
Info.MangledName)
223 if (
const char *MangledName = Die.getLinkageName())
224 Info.MangledName = StringPool.getEntry(MangledName);
230 if (llvm::StringRef Name = getCanonicalDIEName(Die, File, &Unit);
232 Info.Name = StringPool.getEntry(Name);
234 if (!
Info.MangledName)
237 if (StripTemplate &&
Info.Name &&
Info.MangledName !=
Info.Name) {
238 StringRef
Name =
Info.Name.getString();
240 Info.NameWithoutTemplate = StringPool.getEntry(*StrippedName);
243 return Info.Name ||
Info.MangledName;
257 std::function<
void(
const Twine &,
const DWARFDie &)> ReportWarning) {
258 if (
CU.getLanguage() != dwarf::DW_LANG_Swift)
261 if (!ParseableSwiftInterfaces)
265 if (!Path.ends_with(
".swiftinterface"))
270 SysRoot =
CU.getSysRoot();
271 if (!SysRoot.
empty() && Path.starts_with(SysRoot))
276 if (!DeveloperDir.
empty() && Path.starts_with(DeveloperDir))
280 std::optional<const char *> Name =
284 auto &Entry = (*ParseableSwiftInterfaces)[*Name];
286 DWARFDie CUDie =
CU.getOrigUnit().getUnitDIE();
291 if (!Entry.empty() && Entry != ResolvedPath)
292 ReportWarning(
Twine(
"Conflicting parseable interfaces for Swift Module ") +
293 *Name +
": " + Entry +
" and " + Path,
295 Entry = std::string(ResolvedPath);
338 Info.Prune &= (Die.
getTag() == dwarf::DW_TAG_module) ||
344 if (ModulesEndOffset == 0)
345 Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset();
347 Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset() > 0 &&
348 Info.Ctxt->getCanonicalDIEOffset() <= ModulesEndOffset;
356 Info.Prune &= ChildInfo.
Prune;
372 std::function<
void(
const Twine &,
const DWARFDie &)> ReportWarning) {
374 std::vector<ContextWorklistItem> Worklist;
375 Worklist.emplace_back(
DIE, CurrentDeclContext, ParentIdx,
false);
377 while (!Worklist.empty()) {
381 switch (Current.
Type) {
392 unsigned Idx =
CU.getOrigUnit().getDIEIndex(Current.
Die);
407 if (Current.
Die.
getTag() == dwarf::DW_TAG_module &&
410 CU.getClangModuleName()) {
418 if (
CU.hasODR() || Info.InModuleScope) {
422 Current.
Context = PtrInvalidPair.getPointer();
424 PtrInvalidPair.getInt() ? nullptr : PtrInvalidPair.getPointer();
428 Info.Ctxt = Current.
Context =
nullptr;
437 Worklist.emplace_back(
439 Worklist.emplace_back(Child, Current.
Context, Idx,
449 case dwarf::DW_TAG_class_type:
450 case dwarf::DW_TAG_common_block:
451 case dwarf::DW_TAG_lexical_block:
452 case dwarf::DW_TAG_structure_type:
453 case dwarf::DW_TAG_subprogram:
454 case dwarf::DW_TAG_subroutine_type:
455 case dwarf::DW_TAG_union_type:
461void DWARFLinker::cleanupAuxiliarryData(LinkContext &Context) {
464 for (DIEBlock *
I : DIEBlocks)
466 for (DIELoc *
I : DIELocs)
480 auto StmtAttrs = Unit.getStmtSeqListAttributes();
482 SortedOffsets.
reserve(StmtAttrs.size());
492std::pair<bool, std::optional<int64_t>>
493DWARFLinker::getVariableRelocAdjustment(AddressesMap &RelocMgr,
494 const DWARFDie &DIE) {
495 assert((DIE.getTag() == dwarf::DW_TAG_variable ||
496 DIE.getTag() == dwarf::DW_TAG_constant) &&
497 "Wrong type of input die");
499 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
502 DWARFUnit *U = DIE.getDwarfUnit();
503 std::optional<uint32_t> LocationIdx =
504 Abbrev->findAttributeIndex(dwarf::DW_AT_location);
506 return std::make_pair(
false, std::nullopt);
510 Abbrev->getAttributeOffsetFromIndex(*LocationIdx, DIE.getOffset(), *U);
513 std::optional<DWARFFormValue> LocationValue =
514 Abbrev->getAttributeValueFromOffset(*LocationIdx, AttrOffset, *U);
516 return std::make_pair(
false, std::nullopt);
521 std::optional<ArrayRef<uint8_t>> Expr = LocationValue->getAsBlock();
523 return std::make_pair(
false, std::nullopt);
526 DataExtractor
Data(
toStringRef(*Expr), U->getContext().isLittleEndian(),
527 U->getAddressByteSize());
528 DWARFExpression Expression(
Data, U->getAddressByteSize(),
529 U->getFormParams().Format);
531 bool HasLocationAddress =
false;
533 for (DWARFExpression::iterator It = Expression.begin();
534 It != Expression.end(); ++It) {
535 DWARFExpression::iterator NextIt = It;
538 const DWARFExpression::Operation &
Op = *It;
540 case dwarf::DW_OP_const2u:
541 case dwarf::DW_OP_const4u:
542 case dwarf::DW_OP_const8u:
543 case dwarf::DW_OP_const2s:
544 case dwarf::DW_OP_const4s:
545 case dwarf::DW_OP_const8s:
546 if (NextIt == Expression.end() ||
550 case dwarf::DW_OP_addr: {
551 HasLocationAddress =
true;
553 if (std::optional<int64_t> RelocAdjustment =
554 RelocMgr.getExprOpAddressRelocAdjustment(
555 *U,
Op, AttrOffset + CurExprOffset,
557 return std::make_pair(HasLocationAddress, *RelocAdjustment);
559 case dwarf::DW_OP_constx:
560 case dwarf::DW_OP_addrx: {
561 HasLocationAddress =
true;
562 if (std::optional<uint64_t> AddressOffset =
563 DIE.getDwarfUnit()->getIndexedAddressOffset(
566 if (std::optional<int64_t> RelocAdjustment =
567 RelocMgr.getExprOpAddressRelocAdjustment(
568 *U,
Op, *AddressOffset,
569 *AddressOffset + DIE.getDwarfUnit()->getAddressByteSize(),
571 return std::make_pair(HasLocationAddress, *RelocAdjustment);
581 return std::make_pair(HasLocationAddress, std::nullopt);
586unsigned DWARFLinker::shouldKeepVariableDIE(AddressesMap &RelocMgr,
588 CompileUnit::DIEInfo &MyInfo,
590 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
593 if (!(Flags & TF_InFunctionScope) &&
594 Abbrev->findAttributeIndex(dwarf::DW_AT_const_value)) {
595 MyInfo.InDebugMap =
true;
596 return Flags | TF_Keep;
604 std::pair<bool, std::optional<int64_t>> LocExprAddrAndRelocAdjustment =
605 getVariableRelocAdjustment(RelocMgr, DIE);
607 if (LocExprAddrAndRelocAdjustment.first)
608 MyInfo.HasLocationExpressionAddr =
true;
610 if (!LocExprAddrAndRelocAdjustment.second)
613 MyInfo.AddrAdjust = *LocExprAddrAndRelocAdjustment.second;
614 MyInfo.InDebugMap =
true;
616 if (((Flags & TF_InFunctionScope) &&
620 if (Options.Verbose) {
621 outs() <<
"Keeping variable DIE:";
622 DIDumpOptions DumpOpts;
623 DumpOpts.ChildRecurseDepth = 0;
624 DumpOpts.Verbose = Options.Verbose;
625 DIE.dump(
outs(), 8 , DumpOpts);
628 return Flags | TF_Keep;
633unsigned DWARFLinker::shouldKeepSubprogramDIE(
634 AddressesMap &RelocMgr,
const DWARFDie &DIE,
const DWARFFile &File,
635 CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo,
unsigned Flags) {
636 Flags |= TF_InFunctionScope;
642 assert(LowPc &&
"low_pc attribute is not an address.");
643 std::optional<int64_t> RelocAdjustment =
644 RelocMgr.getSubprogramRelocAdjustment(DIE, Options.Verbose);
645 if (!RelocAdjustment)
648 MyInfo.AddrAdjust = *RelocAdjustment;
649 MyInfo.InDebugMap =
true;
651 if (Options.Verbose) {
652 outs() <<
"Keeping subprogram DIE:";
653 DIDumpOptions DumpOpts;
654 DumpOpts.ChildRecurseDepth = 0;
655 DumpOpts.Verbose = Options.Verbose;
656 DIE.dump(
outs(), 8 , DumpOpts);
659 if (DIE.getTag() == dwarf::DW_TAG_label) {
660 if (
Unit.hasLabelAt(*LowPc))
663 DWARFUnit &OrigUnit =
Unit.getOrigUnit();
673 if (
Unit.getLanguage() == dwarf::DW_LANG_Mips_Assembler ||
674 Unit.getLanguage() == dwarf::DW_LANG_Assembly) {
675 if (
auto Range = RelocMgr.getAssemblyRangeForAddress(*LowPc)) {
676 Unit.addFunctionRange(
Range->LowPC,
Range->HighPC, MyInfo.AddrAdjust);
678 Unit.addLabelLowPc(*LowPc, MyInfo.AddrAdjust);
681 Unit.addLabelLowPc(*LowPc, MyInfo.AddrAdjust);
683 return Flags | TF_Keep;
688 std::optional<uint64_t> HighPc = DIE.getHighPC(*LowPc);
690 reportWarning(
"Function without high_pc. Range will be discarded.\n", File,
694 if (*LowPc > *HighPc) {
695 reportWarning(
"low_pc greater than high_pc. Range will be discarded.\n",
701 Unit.addFunctionRange(*LowPc, *HighPc, MyInfo.AddrAdjust);
707unsigned DWARFLinker::shouldKeepDIE(AddressesMap &RelocMgr,
const DWARFDie &DIE,
708 const DWARFFile &File, CompileUnit &Unit,
709 CompileUnit::DIEInfo &MyInfo,
711 switch (DIE.getTag()) {
712 case dwarf::DW_TAG_constant:
713 case dwarf::DW_TAG_variable:
714 return shouldKeepVariableDIE(RelocMgr, DIE, MyInfo, Flags);
715 case dwarf::DW_TAG_subprogram:
716 case dwarf::DW_TAG_label:
717 return shouldKeepSubprogramDIE(RelocMgr, DIE, File, Unit, MyInfo, Flags);
718 case dwarf::DW_TAG_base_type:
721 case dwarf::DW_TAG_imported_module:
722 case dwarf::DW_TAG_imported_declaration:
723 case dwarf::DW_TAG_imported_unit:
725 return Flags | TF_Keep;
739 case dwarf::DW_TAG_structure_type:
740 case dwarf::DW_TAG_class_type:
741 case dwarf::DW_TAG_union_type:
759 case dwarf::DW_TAG_typedef:
760 case dwarf::DW_TAG_member:
761 case dwarf::DW_TAG_reference_type:
762 case dwarf::DW_TAG_ptr_to_member_type:
763 case dwarf::DW_TAG_pointer_type:
780void DWARFLinker::lookForChildDIEsToKeep(
781 const DWARFDie &Die, CompileUnit &
CU,
unsigned Flags,
782 SmallVectorImpl<WorklistItem> &Worklist) {
789 Flags &= ~DWARFLinker::TF_ParentWalk;
793 if (!Die.hasChildren() || (Flags & DWARFLinker::TF_ParentWalk))
798 for (
auto Child :
reverse(Die.children())) {
801 CompileUnit::DIEInfo &ChildInfo =
CU.getInfo(Child);
802 Worklist.emplace_back(Die,
CU, WorklistItemType::UpdateChildIncompleteness,
804 Worklist.emplace_back(Child,
CU, Flags);
811 if (!Info.Ctxt || (Die.
getTag() == dwarf::DW_TAG_namespace))
814 if (!
CU.hasODR() && !Info.InModuleScope)
817 return !Info.Incomplete && Info.Ctxt !=
CU.getInfo(Info.ParentIdx).Ctxt;
820void DWARFLinker::markODRCanonicalDie(
const DWARFDie &Die, CompileUnit &
CU) {
821 CompileUnit::DIEInfo &Info =
CU.getInfo(Die);
823 Info.ODRMarkingDone =
true;
825 !Info.Ctxt->hasCanonicalDIE())
826 Info.Ctxt->setHasCanonicalDIE();
831void DWARFLinker::lookForRefDIEsToKeep(
832 const DWARFDie &Die, CompileUnit &CU,
unsigned Flags,
833 const UnitListTy &Units,
const DWARFFile &File,
834 SmallVectorImpl<WorklistItem> &Worklist) {
835 bool UseOdr = (
Flags & DWARFLinker::TF_DependencyWalk)
836 ? (Flags & DWARFLinker::TF_ODR)
838 DWARFUnit &
Unit = CU.getOrigUnit();
839 DWARFDataExtractor
Data =
Unit.getDebugInfoExtractor();
840 const auto *Abbrev = Die.getAbbreviationDeclarationPtr();
844 for (
const auto &AttrSpec : Abbrev->attributes()) {
845 DWARFFormValue Val(AttrSpec.Form);
847 AttrSpec.Attr == dwarf::DW_AT_sibling) {
849 Unit.getFormParams());
854 CompileUnit *ReferencedCU;
856 resolveDIEReference(File, Units, Val, Die, ReferencedCU)) {
857 CompileUnit::DIEInfo &
Info = ReferencedCU->getInfo(RefDie);
868 if (AttrSpec.Form != dwarf::DW_FORM_ref_addr &&
870 Info.Ctxt->hasCanonicalDIE())
875 Info.Ctxt->hasCanonicalDIE()))
877 ReferencedDIEs.emplace_back(RefDie, *ReferencedCU);
881 unsigned ODRFlag = UseOdr ? DWARFLinker::TF_ODR : 0;
885 for (
auto &
P :
reverse(ReferencedDIEs)) {
888 CompileUnit::DIEInfo &
Info =
P.second.getInfo(
P.first);
889 Worklist.emplace_back(Die, CU, WorklistItemType::UpdateRefIncompleteness,
891 Worklist.emplace_back(
P.first,
P.second,
892 DWARFLinker::TF_Keep |
893 DWARFLinker::TF_DependencyWalk | ODRFlag);
898void DWARFLinker::lookForParentDIEsToKeep(
899 unsigned AncestorIdx, CompileUnit &CU,
unsigned Flags,
900 SmallVectorImpl<WorklistItem> &Worklist) {
902 if (CU.getInfo(AncestorIdx).Keep)
905 DWARFUnit &
Unit = CU.getOrigUnit();
906 DWARFDie ParentDIE =
Unit.getDIEAtIndex(AncestorIdx);
907 Worklist.emplace_back(CU.getInfo(AncestorIdx).ParentIdx, CU, Flags);
908 Worklist.emplace_back(ParentDIE, CU, Flags);
936void DWARFLinker::lookForDIEsToKeep(AddressesMap &AddressesMap,
938 const DWARFDie &Die,
const DWARFFile &File,
939 CompileUnit &Cu,
unsigned Flags) {
942 Worklist.emplace_back(Die, Cu, Flags);
944 while (!Worklist.empty()) {
945 WorklistItem Current = Worklist.pop_back_val();
948 switch (Current.Type) {
949 case WorklistItemType::UpdateChildIncompleteness:
952 case WorklistItemType::UpdateRefIncompleteness:
955 case WorklistItemType::LookForChildDIEsToKeep:
956 lookForChildDIEsToKeep(Current.Die, Current.CU, Current.Flags, Worklist);
958 case WorklistItemType::LookForRefDIEsToKeep:
959 lookForRefDIEsToKeep(Current.Die, Current.CU, Current.Flags, Units, File,
962 case WorklistItemType::LookForParentDIEsToKeep:
963 lookForParentDIEsToKeep(Current.AncestorIdx, Current.CU, Current.Flags,
966 case WorklistItemType::MarkODRCanonicalDie:
967 markODRCanonicalDie(Current.Die, Current.CU);
969 case WorklistItemType::LookForDIEsToKeep:
973 unsigned Idx = Current.CU.getOrigUnit().getDIEIndex(Current.Die);
974 CompileUnit::DIEInfo &MyInfo = Current.CU.getInfo(Idx);
979 if (Current.Flags & TF_DependencyWalk)
980 MyInfo.Prune =
false;
987 bool AlreadyKept = MyInfo.Keep;
988 if ((Current.Flags & TF_DependencyWalk) && AlreadyKept)
991 if (!(Current.Flags & TF_DependencyWalk))
992 Current.Flags = shouldKeepDIE(AddressesMap, Current.Die, File, Current.CU,
993 MyInfo, Current.Flags);
998 if (!(Current.Flags & TF_DependencyWalk) ||
999 (MyInfo.ODRMarkingDone && !MyInfo.Keep)) {
1000 if (Current.CU.hasODR() || MyInfo.InModuleScope)
1001 Worklist.emplace_back(Current.Die, Current.CU,
1002 WorklistItemType::MarkODRCanonicalDie);
1008 Worklist.emplace_back(Current.Die, Current.CU, Current.Flags,
1009 WorklistItemType::LookForChildDIEsToKeep);
1011 if (AlreadyKept || !(Current.Flags & TF_Keep))
1020 Current.Die.getTag() != dwarf::DW_TAG_subprogram &&
1021 Current.Die.getTag() != dwarf::DW_TAG_member &&
1027 Worklist.emplace_back(Current.Die, Current.CU, Current.Flags,
1028 WorklistItemType::LookForRefDIEsToKeep);
1030 bool UseOdr = (Current.Flags & TF_DependencyWalk) ? (Current.Flags & TF_ODR)
1031 : Current.CU.hasODR();
1032 unsigned ODRFlag = UseOdr ? TF_ODR : 0;
1033 unsigned ParFlags = TF_ParentWalk | TF_Keep | TF_DependencyWalk | ODRFlag;
1036 Worklist.emplace_back(MyInfo.ParentIdx, Current.CU, ParFlags);
1052 std::vector<DWARFDie> Worklist;
1053 Worklist.push_back(
CU.getOrigUnit().getUnitDIE());
1056 std::vector<BrokenLink> BrokenLinks;
1058 while (!Worklist.empty()) {
1059 const DWARFDie Current = Worklist.back();
1060 Worklist.pop_back();
1062 const bool CurrentDieIsKept =
CU.getInfo(Current).Keep;
1065 Worklist.push_back(Child);
1067 const bool ChildDieIsKept =
CU.getInfo(Child).Keep;
1068 if (!CurrentDieIsKept && ChildDieIsKept)
1069 BrokenLinks.emplace_back(Current, Child);
1073 if (!BrokenLinks.empty()) {
1076 "Found invalid link in keep chain between {0:x} and {1:x}\n",
1077 Link.Parent.getOffset(), Link.Child.getOffset());
1079 errs() <<
"Parent:";
1080 Link.Parent.dump(
errs(), 0, {});
1081 CU.getInfo(Link.Parent).dump();
1084 Link.Child.dump(
errs(), 2, {});
1085 CU.getInfo(Link.Child).dump();
1098void DWARFLinker::assignAbbrev(DIEAbbrev &Abbrev) {
1100 FoldingSetNodeID
ID;
1103 DIEAbbrev *InSet = AbbreviationsSet.FindNodeOrInsertPos(
ID, InsertToken);
1108 Abbrev.setNumber(InSet->getNumber());
1111 Abbreviations.push_back(
1112 std::make_unique<DIEAbbrev>(Abbrev.getTag(), Abbrev.hasChildren()));
1113 for (
const auto &Attr : Abbrev.getData())
1114 Abbreviations.back()->AddAttribute(Attr);
1115 AbbreviationsSet.InsertNode(Abbreviations.back().get(), InsertToken);
1117 Abbrev.setNumber(Abbreviations.size());
1118 Abbreviations.back()->setNumber(Abbreviations.size());
1122unsigned DWARFLinker::DIECloner::cloneStringAttribute(DIE &Die,
1123 AttributeSpec AttrSpec,
1124 const DWARFFormValue &Val,
1126 AttributesInfo &Info) {
1131 if (AttrSpec.Form == dwarf::DW_FORM_line_strp) {
1136 if (AttrSpec.Attr == dwarf::DW_AT_APPLE_origin) {
1137 Info.HasAppleOrigin =
true;
1138 if (std::optional<StringRef> FileName =
1139 ObjFile.Addresses->getLibraryInstallName()) {
1145 if (AttrSpec.Attr == dwarf::DW_AT_name)
1147 else if (AttrSpec.Attr == dwarf::DW_AT_MIPS_linkage_name ||
1148 AttrSpec.Attr == dwarf::DW_AT_linkage_name)
1150 if (
U.getVersion() >= 5) {
1152 auto StringOffsetIndex =
1153 StringOffsetPool.getValueIndex(
StringEntry.getOffset());
1156 dwarf::DW_FORM_strx, DIEInteger(StringOffsetIndex))
1157 ->sizeOf(
U.getFormParams());
1160 AttrSpec.Form = dwarf::DW_FORM_strp;
1167unsigned DWARFLinker::DIECloner::cloneDieReferenceAttribute(
1168 DIE &Die,
const DWARFDie &InputDIE, AttributeSpec AttrSpec,
1169 unsigned AttrSize,
const DWARFFormValue &Val,
const DWARFFile &File,
1170 CompileUnit &Unit) {
1171 const DWARFUnit &
U =
Unit.getOrigUnit();
1173 if (std::optional<uint64_t> Off = Val.getAsRelativeReference())
1174 Ref = Val.getUnit()->getOffset() + *
Off;
1175 else if (Off = Val.getAsDebugInfoReference(); Off)
1180 DIE *NewRefDie =
nullptr;
1181 CompileUnit *RefUnit =
nullptr;
1184 Linker.resolveDIEReference(File, CompileUnits, Val, InputDIE, RefUnit);
1187 if (!RefDie || AttrSpec.Attr == dwarf::DW_AT_sibling)
1190 CompileUnit::DIEInfo &RefInfo = RefUnit->getInfo(RefDie);
1195 RefInfo.Ctxt->getCanonicalDIEOffset()) {
1196 assert(RefInfo.Ctxt->hasCanonicalDIE() &&
1197 "Offset to canonical die is set, but context is not marked");
1198 DIEInteger Attr(RefInfo.Ctxt->getCanonicalDIEOffset());
1200 dwarf::DW_FORM_ref_addr, Attr);
1201 return U.getRefAddrByteSize();
1204 if (!RefInfo.Clone) {
1207 RefInfo.UnclonedReference =
true;
1210 NewRefDie = RefInfo.Clone;
1212 if (AttrSpec.Form == dwarf::DW_FORM_ref_addr ||
1214 if (
Ref < InputDIE.getOffset() && !RefInfo.UnclonedReference) {
1219 dwarf::DW_FORM_ref_addr, DIEEntry(*NewRefDie));
1225 Unit.noteForwardReference(
1226 NewRefDie, RefUnit, RefInfo.Ctxt,
1228 dwarf::DW_FORM_ref_addr, DIEInteger(
UINT64_MAX)));
1230 return U.getRefAddrByteSize();
1234 dwarf::Form(AttrSpec.Form), DIEEntry(*NewRefDie));
1239void DWARFLinker::DIECloner::cloneExpression(
1240 DataExtractor &
Data, DWARFExpression Expression,
const DWARFFile &File,
1241 CompileUnit &Unit, SmallVectorImpl<uint8_t> &OutputBuffer,
1242 int64_t AddrRelocAdjustment,
bool IsLittleEndian) {
1245 uint8_t OrigAddressByteSize =
Unit.getOrigUnit().getAddressByteSize();
1247 uint64_t OpOffset = 0;
1248 for (
auto &
Op : Expression) {
1254 Desc.
Op[0] != Encoding::Size1))
1255 Linker.reportWarning(
"Unsupported DW_OP encoding.", File);
1259 Desc.
Op[0] == Encoding::Size1)) {
1279 if (RefOffset > 0 ||
Op.
getCode() != dwarf::DW_OP_convert) {
1280 RefOffset +=
Unit.getOrigUnit().getOffset();
1281 auto RefDie =
Unit.getOrigUnit().getDIEForOffset(RefOffset);
1282 CompileUnit::DIEInfo &
Info =
Unit.getInfo(RefDie);
1283 if (DIE *Clone =
Info.Clone)
1284 Offset = Clone->getOffset();
1286 Linker.reportWarning(
1287 "base type ref doesn't point to DW_TAG_base_type.", File);
1291 if (RealSize > ULEBsize) {
1294 Linker.reportWarning(
"base type ref doesn't fit.", File);
1296 assert(RealSize == ULEBsize &&
"padding failed");
1297 ArrayRef<uint8_t> ULEBbytes(ULEB, ULEBsize);
1298 OutputBuffer.append(ULEBbytes.begin(), ULEBbytes.end());
1299 }
else if (!Linker.Options.Update &&
Op.
getCode() == dwarf::DW_OP_addrx) {
1300 if (std::optional<object::SectionedAddress> SA =
1301 Unit.getOrigUnit().getAddrOffsetSectionItem(
1307 OutputBuffer.push_back(dwarf::DW_OP_addr);
1308 uint64_t LinkedAddress = SA->Address + AddrRelocAdjustment;
1311 ArrayRef<uint8_t> AddressBytes(
1312 reinterpret_cast<const uint8_t *
>(&LinkedAddress),
1313 OrigAddressByteSize);
1314 OutputBuffer.append(AddressBytes.begin(), AddressBytes.end());
1316 Linker.reportWarning(
"cannot read DW_OP_addrx operand.", File);
1317 }
else if (!Linker.Options.Update &&
Op.
getCode() == dwarf::DW_OP_constx) {
1318 if (std::optional<object::SectionedAddress> SA =
1319 Unit.getOrigUnit().getAddrOffsetSectionItem(
1325 std::optional<uint8_t> OutOperandKind;
1326 switch (OrigAddressByteSize) {
1328 OutOperandKind = dwarf::DW_OP_const4u;
1331 OutOperandKind = dwarf::DW_OP_const8u;
1334 Linker.reportWarning(
1335 formatv((
"unsupported address size: {0}."), OrigAddressByteSize),
1340 if (OutOperandKind) {
1341 OutputBuffer.push_back(*OutOperandKind);
1342 uint64_t LinkedAddress = SA->Address + AddrRelocAdjustment;
1345 ArrayRef<uint8_t> AddressBytes(
1346 reinterpret_cast<const uint8_t *
>(&LinkedAddress),
1347 OrigAddressByteSize);
1348 OutputBuffer.append(AddressBytes.begin(), AddressBytes.end());
1351 Linker.reportWarning(
"cannot read DW_OP_constx operand.", File);
1355 OutputBuffer.append(Bytes.begin(), Bytes.end());
1361unsigned DWARFLinker::DIECloner::cloneBlockAttribute(
1362 DIE &Die,
const DWARFDie &InputDIE,
const DWARFFile &File,
1363 CompileUnit &Unit, AttributeSpec AttrSpec,
const DWARFFormValue &Val,
1364 bool IsLittleEndian) {
1367 DIELoc *Loc =
nullptr;
1368 DIEBlock *
Block =
nullptr;
1369 if (AttrSpec.Form == dwarf::DW_FORM_exprloc) {
1370 Loc =
new (DIEAlloc) DIELoc;
1371 Linker.DIELocs.push_back(Loc);
1373 Block =
new (DIEAlloc) DIEBlock;
1374 Linker.DIEBlocks.push_back(
Block);
1376 Attr = Loc ?
static_cast<DIEValueList *
>(Loc)
1377 : static_cast<DIEValueList *>(
Block);
1379 DWARFUnit &OrigUnit =
Unit.getOrigUnit();
1382 SmallVector<uint8_t, 32> Buffer;
1383 ArrayRef<uint8_t> Bytes = *Val.getAsBlock();
1387 DataExtractor Data(StringRef((const char *)Bytes.data(), Bytes.size()),
1388 IsLittleEndian, OrigUnit.getAddressByteSize());
1389 DWARFExpression Expr(Data, OrigUnit.getAddressByteSize(),
1390 OrigUnit.getFormParams().Format);
1391 cloneExpression(Data, Expr, File, Unit, Buffer,
1392 Unit.getInfo(InputDIE).AddrAdjust, IsLittleEndian);
1395 for (
auto Byte : Bytes)
1397 dwarf::DW_FORM_data1, DIEInteger(Byte));
1403 Loc->setSize(Bytes.size());
1405 Block->setSize(Bytes.size());
1413 if ((AttrSpec.Form == dwarf::DW_FORM_block1 &&
1414 (Bytes.size() > UINT8_MAX)) ||
1415 (AttrSpec.Form == dwarf::DW_FORM_block2 &&
1416 (Bytes.size() > UINT16_MAX)) ||
1417 (AttrSpec.Form == dwarf::DW_FORM_block4 && (Bytes.size() > UINT32_MAX)))
1418 AttrSpec.Form = dwarf::DW_FORM_block;
1420 Value = DIEValue(dwarf::Attribute(AttrSpec.Attr),
1421 dwarf::Form(AttrSpec.Form), Block);
1424 return Die.addValue(DIEAlloc,
Value)->sizeOf(OrigUnit.getFormParams());
1427unsigned DWARFLinker::DIECloner::cloneAddressAttribute(
1428 DIE &Die,
const DWARFDie &InputDIE, AttributeSpec AttrSpec,
1429 unsigned AttrSize,
const DWARFFormValue &Val,
const CompileUnit &Unit,
1430 AttributesInfo &Info) {
1431 if (AttrSpec.Attr == dwarf::DW_AT_low_pc)
1432 Info.HasLowPc =
true;
1436 dwarf::Form(AttrSpec.Form), DIEInteger(Val.getRawUValue()));
1452 std::optional<DWARFFormValue> AddrAttribute = InputDIE.find(AttrSpec.Attr);
1456 std::optional<uint64_t> Addr = AddrAttribute->getAsAddress();
1458 Linker.reportWarning(
"Cann't read address attribute value.", ObjFile);
1462 if (InputDIE.getTag() == dwarf::DW_TAG_compile_unit &&
1463 AttrSpec.Attr == dwarf::DW_AT_low_pc) {
1464 if (std::optional<uint64_t> LowPC =
Unit.getLowPc())
1468 }
else if (InputDIE.getTag() == dwarf::DW_TAG_compile_unit &&
1469 AttrSpec.Attr == dwarf::DW_AT_high_pc) {
1470 if (uint64_t HighPc =
Unit.getHighPc())
1475 *Addr +=
Info.PCOffset;
1478 if (AttrSpec.Form == dwarf::DW_FORM_addr) {
1480 AttrSpec.Form, DIEInteger(*Addr));
1481 return Unit.getOrigUnit().getAddressByteSize();
1484 auto AddrIndex = AddrPool.getValueIndex(*Addr);
1488 dwarf::Form::DW_FORM_addrx, DIEInteger(AddrIndex))
1489 ->sizeOf(
Unit.getOrigUnit().getFormParams());
1492unsigned DWARFLinker::DIECloner::cloneScalarAttribute(
1493 DIE &Die,
const DWARFDie &InputDIE,
const DWARFFile &File,
1494 CompileUnit &Unit, AttributeSpec AttrSpec,
const DWARFFormValue &Val,
1495 unsigned AttrSize, AttributesInfo &Info) {
1500 if (AttrSpec.Attr == dwarf::DW_AT_GNU_dwo_id ||
1501 AttrSpec.Attr == dwarf::DW_AT_dwo_id)
1506 if (AttrSpec.Attr == dwarf::DW_AT_macro_info) {
1507 if (std::optional<uint64_t>
Offset = Val.getAsSectionOffset()) {
1508 const llvm::DWARFDebugMacro *
Macro =
File.Dwarf->getDebugMacinfo();
1514 if (AttrSpec.Attr == dwarf::DW_AT_macros) {
1515 if (std::optional<uint64_t>
Offset = Val.getAsSectionOffset()) {
1516 const llvm::DWARFDebugMacro *
Macro =
File.Dwarf->getDebugMacro();
1522 if (AttrSpec.Attr == dwarf::DW_AT_str_offsets_base) {
1526 Info.AttrStrOffsetBaseSeen =
true;
1528 .addValue(DIEAlloc, dwarf::DW_AT_str_offsets_base,
1529 dwarf::DW_FORM_sec_offset, DIEInteger(8))
1530 ->sizeOf(
Unit.getOrigUnit().getFormParams());
1533 if (AttrSpec.Attr == dwarf::DW_AT_LLVM_stmt_sequence) {
1536 dwarf::DW_FORM_sec_offset,
1537 DIEInteger(*Val.getAsSectionOffset()));
1540 Unit.noteStmtSeqListAttribute(Patch);
1542 return Unit.getOrigUnit().getFormParams().getDwarfOffsetByteSize();
1546 if (
auto OptionalValue = Val.getAsUnsignedConstant())
1547 Value = *OptionalValue;
1548 else if (
auto OptionalValue = Val.getAsSignedConstant())
1549 Value = *OptionalValue;
1550 else if (
auto OptionalValue = Val.getAsSectionOffset())
1551 Value = *OptionalValue;
1553 Linker.reportWarning(
1554 "Unsupported scalar attribute form. Dropping attribute.", File,
1558 if (AttrSpec.Attr == dwarf::DW_AT_declaration &&
Value)
1559 Info.IsDeclaration =
true;
1561 if (AttrSpec.Form == dwarf::DW_FORM_loclistx)
1570 [[maybe_unused]]
dwarf::Form OriginalForm = AttrSpec.Form;
1571 if (AttrSpec.Form == dwarf::DW_FORM_rnglistx) {
1575 std::optional<uint64_t>
Index = Val.getAsSectionOffset();
1577 Linker.reportWarning(
"Cannot read the attribute. Dropping.", File,
1581 std::optional<uint64_t>
Offset =
1582 Unit.getOrigUnit().getRnglistOffset(*Index);
1584 Linker.reportWarning(
"Cannot read the attribute. Dropping.", File,
1590 AttrSpec.Form = dwarf::DW_FORM_sec_offset;
1591 AttrSize =
Unit.getOrigUnit().getFormParams().getDwarfOffsetByteSize();
1592 }
else if (AttrSpec.Form == dwarf::DW_FORM_loclistx) {
1596 std::optional<uint64_t>
Index = Val.getAsSectionOffset();
1598 Linker.reportWarning(
"Cannot read the attribute. Dropping.", File,
1602 std::optional<uint64_t>
Offset =
1603 Unit.getOrigUnit().getLoclistOffset(*Index);
1605 Linker.reportWarning(
"Cannot read the attribute. Dropping.", File,
1611 AttrSpec.Form = dwarf::DW_FORM_sec_offset;
1612 AttrSize =
Unit.getOrigUnit().getFormParams().getDwarfOffsetByteSize();
1613 }
else if (AttrSpec.Attr == dwarf::DW_AT_high_pc &&
1614 Die.getTag() == dwarf::DW_TAG_compile_unit) {
1615 std::optional<uint64_t> LowPC =
Unit.getLowPc();
1620 }
else if (AttrSpec.Form == dwarf::DW_FORM_sec_offset)
1621 Value = *Val.getAsSectionOffset();
1622 else if (AttrSpec.Form == dwarf::DW_FORM_sdata)
1623 Value = *Val.getAsSignedConstant();
1624 else if (
auto OptionalValue = Val.getAsUnsignedConstant())
1625 Value = *OptionalValue;
1627 Linker.reportWarning(
1628 "Unsupported scalar attribute form. Dropping attribute.", File,
1633 DIE::value_iterator Patch =
1636 if (AttrSpec.Attr == dwarf::DW_AT_ranges ||
1637 AttrSpec.Attr == dwarf::DW_AT_start_scope) {
1638 Unit.noteRangeAttribute(Die, Patch);
1639 Info.HasRanges =
true;
1643 Unit.getOrigUnit().getVersion())) {
1645 CompileUnit::DIEInfo &LocationDieInfo =
Unit.getInfo(InputDIE);
1646 Unit.noteLocationAttribute({Patch, LocationDieInfo.InDebugMap
1647 ? LocationDieInfo.AddrAdjust
1649 }
else if (AttrSpec.Attr == dwarf::DW_AT_declaration &&
Value)
1650 Info.IsDeclaration =
true;
1653 assert((
Info.HasRanges || (OriginalForm != dwarf::DW_FORM_rnglistx)) &&
1654 "Unhandled DW_FORM_rnglistx attribute");
1662unsigned DWARFLinker::DIECloner::cloneAttribute(
1663 DIE &Die,
const DWARFDie &InputDIE,
const DWARFFile &File,
1664 CompileUnit &Unit,
const DWARFFormValue &Val,
const AttributeSpec AttrSpec,
1665 unsigned AttrSize, AttributesInfo &Info,
bool IsLittleEndian) {
1666 const DWARFUnit &
U =
Unit.getOrigUnit();
1668 switch (AttrSpec.Form) {
1669 case dwarf::DW_FORM_strp:
1670 case dwarf::DW_FORM_line_strp:
1671 case dwarf::DW_FORM_string:
1672 case dwarf::DW_FORM_strx:
1673 case dwarf::DW_FORM_strx1:
1674 case dwarf::DW_FORM_strx2:
1675 case dwarf::DW_FORM_strx3:
1676 case dwarf::DW_FORM_strx4:
1677 return cloneStringAttribute(Die, AttrSpec, Val, U, Info);
1678 case dwarf::DW_FORM_ref_addr:
1679 case dwarf::DW_FORM_ref1:
1680 case dwarf::DW_FORM_ref2:
1681 case dwarf::DW_FORM_ref4:
1682 case dwarf::DW_FORM_ref8:
1683 return cloneDieReferenceAttribute(Die, InputDIE, AttrSpec, AttrSize, Val,
1685 case dwarf::DW_FORM_block:
1686 case dwarf::DW_FORM_block1:
1687 case dwarf::DW_FORM_block2:
1688 case dwarf::DW_FORM_block4:
1689 case dwarf::DW_FORM_exprloc:
1690 return cloneBlockAttribute(Die, InputDIE, File, Unit, AttrSpec, Val,
1692 case dwarf::DW_FORM_addr:
1693 case dwarf::DW_FORM_addrx:
1694 case dwarf::DW_FORM_addrx1:
1695 case dwarf::DW_FORM_addrx2:
1696 case dwarf::DW_FORM_addrx3:
1697 case dwarf::DW_FORM_addrx4:
1698 return cloneAddressAttribute(Die, InputDIE, AttrSpec, AttrSize, Val, Unit,
1700 case dwarf::DW_FORM_data1:
1701 case dwarf::DW_FORM_data2:
1702 case dwarf::DW_FORM_data4:
1703 case dwarf::DW_FORM_data8:
1704 case dwarf::DW_FORM_udata:
1705 case dwarf::DW_FORM_sdata:
1706 case dwarf::DW_FORM_sec_offset:
1707 case dwarf::DW_FORM_flag:
1708 case dwarf::DW_FORM_flag_present:
1709 case dwarf::DW_FORM_rnglistx:
1710 case dwarf::DW_FORM_loclistx:
1711 case dwarf::DW_FORM_implicit_const:
1712 return cloneScalarAttribute(Die, InputDIE, File, Unit, AttrSpec, Val,
1715 Linker.reportWarning(
"Unsupported attribute form " +
1717 " in cloneAttribute. Dropping.",
1724void DWARFLinker::DIECloner::addObjCAccelerator(CompileUnit &Unit,
1726 DwarfStringPoolEntryRef Name,
1728 bool SkipPubSection) {
1729 std::optional<ObjCSelectorNames> Names =
1733 Unit.addNameAccelerator(Die, StringPool.getEntry(Names->Selector),
1735 Unit.addObjCAccelerator(Die, StringPool.getEntry(Names->ClassName),
1737 if (Names->ClassNameNoCategory)
1738 Unit.addObjCAccelerator(
1739 Die, StringPool.getEntry(*Names->ClassNameNoCategory), SkipPubSection);
1740 if (Names->MethodNameNoCategory)
1741 Unit.addNameAccelerator(
1742 Die, StringPool.getEntry(*Names->MethodNameNoCategory), SkipPubSection);
1749 switch (AttrSpec.
Attr) {
1752 case dwarf::DW_AT_low_pc:
1753 case dwarf::DW_AT_high_pc:
1754 case dwarf::DW_AT_ranges:
1755 return !Update && SkipPC;
1756 case dwarf::DW_AT_rnglists_base:
1762 case dwarf::DW_AT_loclists_base:
1768 case dwarf::DW_AT_location:
1769 case dwarf::DW_AT_frame_base:
1770 return !Update && SkipPC;
1780DIE *DWARFLinker::DIECloner::cloneDIE(
const DWARFDie &InputDIE,
1782 int64_t PCOffset,
uint32_t OutOffset,
1783 unsigned Flags,
bool IsLittleEndian,
1786 unsigned Idx = U.getDIEIndex(InputDIE);
1790 if (!Unit.getInfo(Idx).Keep)
1794 assert(!(Die && Info.Clone) &&
"Can't supply a DIE and a cloned DIE");
1806 (Info.Ctxt->getCanonicalDIEOffset() == 0)) {
1807 if (!Info.Ctxt->hasCanonicalDIE())
1808 Info.Ctxt->setHasCanonicalDIE();
1812 Info.Ctxt->setCanonicalDIEOffset(OutOffset + Unit.getStartOffset());
1816 DWARFDataExtractor
Data =
U.getDebugInfoExtractor();
1820 uint64_t NextOffset = (Idx + 1 <
U.getNumDIEs())
1821 ?
U.getDIEAtIndex(Idx + 1).getOffset()
1822 :
U.getNextUnitOffset();
1823 AttributesInfo AttrInfo;
1828 SmallString<40> DIECopy(
Data.getData().substr(
Offset, NextOffset -
Offset));
1830 DWARFDataExtractor(DIECopy,
Data.isLittleEndian(),
Data.getAddressSize());
1833 ObjFile.Addresses->applyValidRelocs(DIECopy,
Offset,
Data.isLittleEndian());
1843 if (Die->
getTag() == dwarf::DW_TAG_subprogram)
1844 PCOffset =
Info.AddrAdjust;
1845 AttrInfo.PCOffset = PCOffset;
1847 if (Abbrev->getTag() == dwarf::DW_TAG_subprogram) {
1848 Flags |= TF_InFunctionScope;
1851 }
else if (Abbrev->getTag() == dwarf::DW_TAG_variable) {
1854 if ((Flags & TF_InFunctionScope) &&
Info.InDebugMap)
1855 Flags &= ~TF_SkipPC;
1858 else if (!
Info.InDebugMap &&
Info.HasLocationExpressionAddr &&
1863 std::optional<StringRef> LibraryInstallName =
1864 ObjFile.Addresses->getLibraryInstallName();
1866 for (
const auto &AttrSpec : Abbrev->attributes()) {
1873 AttributeLinkedOffsetFixup CurAttrFixup;
1875 CurAttrFixup.LinkedOffsetFixupVal =
1876 Unit.getStartOffset() + OutOffset - CurAttrFixup.InputAttrStartOffset;
1878 DWARFFormValue Val = AttrSpec.getFormValue();
1879 uint64_t AttrSize =
Offset;
1880 Val.extractValue(
Data, &
Offset,
U.getFormParams(), &U);
1882 AttrSize =
Offset - AttrSize;
1884 uint64_t FinalAttrSize =
1885 cloneAttribute(*Die, InputDIE, File, Unit, Val, AttrSpec, AttrSize,
1886 AttrInfo, IsLittleEndian);
1887 if (FinalAttrSize != 0 && ObjFile.Addresses->needToSaveValidRelocs())
1888 AttributesFixups.push_back(CurAttrFixup);
1890 OutOffset += FinalAttrSize;
1896 const bool NeedsAppleOrigin = (
Tag == dwarf::DW_TAG_compile_unit) &&
1897 LibraryInstallName.has_value() &&
1898 !AttrInfo.HasAppleOrigin;
1899 if (NeedsAppleOrigin) {
1900 auto StringEntry = DebugStrPool.getEntry(LibraryInstallName.value());
1902 dwarf::DW_FORM_strp, DIEInteger(
StringEntry.getOffset()));
1911 if ((
Info.InDebugMap || AttrInfo.HasLowPc || AttrInfo.HasRanges) &&
1912 Tag != dwarf::DW_TAG_compile_unit &&
1913 getDIENames(InputDIE, AttrInfo, DebugStrPool, File, Unit,
1914 Tag != dwarf::DW_TAG_inlined_subroutine)) {
1915 if (AttrInfo.MangledName && AttrInfo.MangledName != AttrInfo.Name)
1916 Unit.addNameAccelerator(Die, AttrInfo.MangledName,
1917 Tag == dwarf::DW_TAG_inlined_subroutine);
1918 if (AttrInfo.Name) {
1919 if (AttrInfo.NameWithoutTemplate)
1920 Unit.addNameAccelerator(Die, AttrInfo.NameWithoutTemplate,
1922 Unit.addNameAccelerator(Die, AttrInfo.Name,
1923 Tag == dwarf::DW_TAG_inlined_subroutine);
1926 addObjCAccelerator(Unit, Die, AttrInfo.Name, DebugStrPool,
1929 }
else if (
Tag == dwarf::DW_TAG_namespace) {
1931 AttrInfo.Name = DebugStrPool.getEntry(
"(anonymous namespace)");
1932 Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
1933 }
else if (
Tag == dwarf::DW_TAG_imported_declaration && AttrInfo.Name) {
1934 Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
1935 }
else if (
isTypeTag(
Tag) && !AttrInfo.IsDeclaration) {
1936 bool Success = getDIENames(InputDIE, AttrInfo, DebugStrPool, File, Unit);
1937 uint64_t RuntimeLang =
1940 bool ObjCClassIsImplementation =
1941 (RuntimeLang == dwarf::DW_LANG_ObjC ||
1942 RuntimeLang == dwarf::DW_LANG_ObjC_plus_plus) &&
1945 if (
Success && AttrInfo.Name && !AttrInfo.Name.getString().empty()) {
1947 Unit.addTypeAccelerator(Die, AttrInfo.Name, ObjCClassIsImplementation,
1952 if (
Success && AttrInfo.MangledName &&
1953 RuntimeLang == dwarf::DW_LANG_Swift &&
1954 !AttrInfo.MangledName.getString().empty() &&
1955 AttrInfo.MangledName != AttrInfo.Name) {
1956 auto Hash =
djbHash(AttrInfo.MangledName.getString().data());
1957 Unit.addTypeAccelerator(Die, AttrInfo.MangledName,
1958 ObjCClassIsImplementation, Hash);
1963 bool HasChildren =
false;
1964 for (
auto Child : InputDIE.
children()) {
1965 unsigned Idx =
U.getDIEIndex(Child);
1966 if (
Unit.getInfo(Idx).Keep) {
1972 if (
Unit.getOrigUnit().getVersion() >= 5 && !AttrInfo.AttrStrOffsetBaseSeen &&
1973 Die->
getTag() == dwarf::DW_TAG_compile_unit) {
1975 Die->
addValue(DIEAlloc, dwarf::DW_AT_str_offsets_base,
1976 dwarf::DW_FORM_sec_offset, DIEInteger(8));
1984 Linker.assignAbbrev(NewAbbrev);
1990 OutOffset += AbbrevNumberSize;
1993 for (AttributeLinkedOffsetFixup &
F : AttributesFixups)
1994 F.LinkedOffsetFixupVal += AbbrevNumberSize;
1996 for (AttributeLinkedOffsetFixup &
F : AttributesFixups)
1997 ObjFile.Addresses->updateAndSaveValidRelocs(
1998 Unit.getOrigUnit().getVersion() >= 5,
Unit.getOrigUnit().getOffset(),
1999 F.LinkedOffsetFixupVal,
F.InputAttrStartOffset,
F.InputAttrEndOffset);
2008 for (
auto Child : InputDIE.
children()) {
2009 if (DIE *Clone = cloneDIE(Child, File, Unit, PCOffset, OutOffset, Flags,
2012 OutOffset = Clone->getOffset() + Clone->getSize();
2017 OutOffset +=
sizeof(int8_t);
2026Error DWARFLinker::generateUnitRanges(CompileUnit &Unit,
const DWARFFile &File,
2031 const auto &FunctionRanges =
Unit.getFunctionRanges();
2034 AddressRanges LinkedFunctionRanges;
2035 for (
const AddressRangeValuePair &
Range : FunctionRanges)
2036 LinkedFunctionRanges.insert(
2040 if (!LinkedFunctionRanges.empty())
2041 TheDwarfEmitter->emitDwarfDebugArangesTable(Unit, LinkedFunctionRanges);
2044 std::optional<PatchLocation> UnitRngListAttribute =
2045 Unit.getUnitRangesAttribute();
2047 if (!AllRngListAttributes.empty() || UnitRngListAttribute) {
2048 std::optional<AddressRangeValuePair> CachedRange;
2049 MCSymbol *EndLabel = TheDwarfEmitter->emitDwarfDebugRangeListHeader(Unit);
2053 for (PatchLocation &AttributePatch : AllRngListAttributes) {
2056 AddressRanges LinkedRanges;
2057 if (Expected<DWARFAddressRangesVector> OriginalRanges =
2058 Unit.getOrigUnit().findRnglistFromOffset(AttributePatch.get())) {
2060 for (
const auto &
Range : *OriginalRanges) {
2061 if (!CachedRange || !CachedRange->Range.contains(
Range.LowPC))
2062 CachedRange = FunctionRanges.getRangeThatContains(
Range.LowPC);
2066 reportWarning(
"inconsistent range data.", File);
2071 LinkedRanges.insert({
Range.LowPC + CachedRange->Value,
2072 Range.HighPC + CachedRange->Value});
2076 reportWarning(
"invalid range list ignored.", File);
2080 if (
Error E = TheDwarfEmitter->emitDwarfDebugRangeListFragment(
2081 Unit, LinkedRanges, AttributePatch, AddrPool))
2086 if (UnitRngListAttribute.has_value())
2087 if (
Error E = TheDwarfEmitter->emitDwarfDebugRangeListFragment(
2088 Unit, LinkedFunctionRanges, *UnitRngListAttribute, AddrPool))
2092 TheDwarfEmitter->emitDwarfDebugRangeListFooter(Unit, EndLabel);
2098Error DWARFLinker::DIECloner::generateUnitLocations(
2099 CompileUnit &Unit,
const DWARFFile &File,
2100 ExpressionHandlerRef ExprHandler) {
2105 Unit.getLocationAttributes();
2107 if (AllLocListAttributes.empty())
2113 for (
auto &CurLocAttr : AllLocListAttributes) {
2116 Expected<DWARFLocationExpressionsVector> OriginalLocations =
2117 Unit.getOrigUnit().findLoclistFromOffset(CurLocAttr.get());
2119 if (!OriginalLocations) {
2121 Linker.reportWarning(
"Invalid location attribute ignored.", File);
2126 for (DWARFLocationExpression &CurExpression : *OriginalLocations) {
2127 DWARFLocationExpression LinkedExpression;
2129 if (CurExpression.Range) {
2131 LinkedExpression.Range = {
2132 CurExpression.Range->LowPC + CurLocAttr.RelocAdjustment,
2133 CurExpression.Range->HighPC + CurLocAttr.RelocAdjustment};
2137 LinkedExpression.Expr.reserve(CurExpression.Expr.size());
2138 ExprHandler(CurExpression.Expr, LinkedExpression.Expr,
2139 CurLocAttr.RelocAdjustment);
2141 LinkedLocationExpressions.push_back(LinkedExpression);
2146 Unit, LinkedLocationExpressions, CurLocAttr, AddrPool))
2151 Emitter->emitDwarfDebugLocListFooter(Unit, EndLabel);
2157 for (
auto &V : Die.
values())
2158 if (V.getAttribute() == dwarf::DW_AT_addr_base) {
2166Error DWARFLinker::DIECloner::emitDebugAddrSection(
2167 CompileUnit &Unit,
const uint16_t DwarfVersion)
const {
2172 if (DwarfVersion < 5)
2175 if (AddrPool.getValues().empty())
2178 MCSymbol *EndLabel =
Emitter->emitDwarfDebugAddrsHeader(Unit);
2180 dwarf::FormParams
FP = Unit.getOrigUnit().getFormParams();
2181 if (AddrOffset >
FP.getDwarfMaxOffset())
2185 patchAddrBase(*Unit.getOutputUnitDIE(), DIEInteger(AddrOffset));
2186 Emitter->emitDwarfDebugAddrs(AddrPool.getValues(),
2187 Unit.getOrigUnit().getAddressByteSize());
2188 Emitter->emitDwarfDebugAddrsFooter(Unit, EndLabel);
2206 std::vector<TrackedRow> &Rows) {
2212 Seq.front().isStartSeqInOutput =
true;
2214 if (!Rows.empty() && Rows.back().Row.Address < Seq.front().Row.Address) {
2222 Rows, [=](
const TrackedRow &O) {
return O.Row.Address < Front; });
2231 Rows.insert(
InsertPoint + 1, Seq.begin() + 1, Seq.end());
2240 for (
auto &V : Die.
values())
2241 if (V.getAttribute() == dwarf::DW_AT_stmt_list) {
2249void DWARFLinker::DIECloner::rememberUnitForMacroOffset(CompileUnit &Unit) {
2250 DWARFUnit &OrigUnit = Unit.getOrigUnit();
2251 DWARFDie OrigUnitDie = OrigUnit.getUnitDIE();
2253 if (std::optional<uint64_t> MacroAttr =
2255 UnitMacroMap.insert(std::make_pair(*MacroAttr, &Unit));
2259 if (std::optional<uint64_t> MacroAttr =
2261 UnitMacroMap.insert(std::make_pair(*MacroAttr, &Unit));
2266Error DWARFLinker::DIECloner::generateLineTableForUnit(CompileUnit &Unit) {
2271 DWARFDie CUDie =
Unit.getOrigUnit().getUnitDIE();
2277 if (
auto *OutputDIE =
Unit.getOutputUnitDIE()) {
2278 uint64_t StmtOffset =
Emitter->getLineSectionSize();
2279 dwarf::FormParams
FP =
Unit.getOrigUnit().getFormParams();
2280 if (StmtOffset >
FP.getDwarfMaxOffset())
2287 if (
const DWARFDebugLine::LineTable *LT =
2288 ObjFile.Dwarf->getLineTableForUnit(&
Unit.getOrigUnit())) {
2290 DWARFDebugLine::LineTable LineTable;
2293 LineTable.Prologue =
LT->Prologue;
2296 if (Linker.Options.Update) {
2297 LineTable.Rows =
LT->Rows;
2300 if (LineTable.Rows.size() == 1 && LineTable.Rows[0].EndSequence)
2301 LineTable.Rows.clear();
2303 LineTable.Sequences =
LT->Sequences;
2305 Emitter->emitLineTableForUnit(LineTable, Unit, DebugStrPool,
2309 std::vector<TrackedRow> InputRows;
2310 InputRows.reserve(
LT->Rows.size());
2311 for (
size_t i = 0; i <
LT->Rows.size(); i++)
2312 InputRows.emplace_back(TrackedRow{LT->Rows[i], i, false});
2315 std::vector<TrackedRow> OutputRows;
2316 OutputRows.reserve(InputRows.size());
2320 std::vector<TrackedRow> Seq;
2321 Seq.reserve(InputRows.size());
2323 const auto &FunctionRanges =
Unit.getFunctionRanges();
2324 std::optional<AddressRangeValuePair> CurrRange;
2337 for (
size_t i = 0; i < InputRows.size(); i++) {
2338 TrackedRow TR = InputRows[i];
2345 if (!CurrRange || !CurrRange->Range.contains(TR.Row.Address.Address)) {
2348 uint64_t StopAddress =
2349 CurrRange ? CurrRange->Range.end() + CurrRange->Value : -1ULL;
2351 FunctionRanges.getRangeThatContains(TR.Row.Address.Address);
2352 if (StopAddress != -1ULL && !Seq.empty()) {
2355 auto NextLine = Seq.back();
2356 NextLine.Row.Address.Address = StopAddress;
2357 NextLine.Row.EndSequence = 1;
2358 NextLine.Row.PrologueEnd = 0;
2359 NextLine.Row.BasicBlock = 0;
2360 NextLine.Row.EpilogueBegin = 0;
2361 Seq.push_back(NextLine);
2370 if (TR.Row.EndSequence && Seq.empty())
2374 TR.Row.Address.Address += CurrRange->Value;
2377 if (TR.Row.EndSequence)
2388 if (!OutputRows.empty()) {
2389 OutputRows[0].isStartSeqInOutput =
true;
2390 for (
size_t i = 1; i < OutputRows.size(); ++i)
2391 OutputRows[i].isStartSeqInOutput = OutputRows[i - 1].Row.EndSequence;
2395 LineTable.Rows.clear();
2396 LineTable.Rows.reserve(OutputRows.size());
2397 for (
auto &TR : OutputRows)
2398 LineTable.Rows.push_back(TR.Row);
2402 std::vector<uint64_t> OutputRowOffsets;
2406 bool hasStmtSeq =
Unit.getStmtSeqListAttributes().size() > 0;
2407 Emitter->emitLineTableForUnit(LineTable, Unit, DebugStrPool,
2409 hasStmtSeq ? &OutputRowOffsets :
nullptr);
2412 assert(OutputRowOffsets.size() == OutputRows.size() &&
2413 "must have an offset for each row");
2416 DenseMap<uint64_t, uint64_t> SeqOffToOrigRow;
2421 if (!
LT->Rows.empty())
2429 DenseMap<size_t, size_t> OrigRowToOutputRow;
2430 std::vector<size_t> OutputRowToSeqStart(OutputRows.size());
2432 size_t CurrentSeqStart = 0;
2433 for (
size_t i = 0; i < OutputRows.size(); ++i) {
2435 if (OutputRows[i].isStartSeqInOutput)
2436 CurrentSeqStart = i;
2437 OutputRowToSeqStart[i] = CurrentSeqStart;
2440 OrigRowToOutputRow[OutputRows[i].OriginalRowIndex] = i;
2445 for (
const auto &StmtSeq :
Unit.getStmtSeqListAttributes()) {
2446 uint64_t OrigStmtSeq = StmtSeq.get();
2448 auto OrigRowIter = SeqOffToOrigRow.find(OrigStmtSeq);
2449 const uint64_t InvalidOffset =
2450 Unit.getOrigUnit().getFormParams().getDwarfMaxOffset();
2454 if (OrigRowIter == SeqOffToOrigRow.end()) {
2455 StmtSeq.set(InvalidOffset);
2458 size_t OrigRowIndex = OrigRowIter->second;
2461 auto OutputRowIter = OrigRowToOutputRow.find(OrigRowIndex);
2462 if (OutputRowIter == OrigRowToOutputRow.end()) {
2464 StmtSeq.set(InvalidOffset);
2467 size_t OutputRowIdx = OutputRowIter->second;
2472 size_t SeqStartIdx = OutputRowToSeqStart[OutputRowIdx];
2476 assert(SeqStartIdx < OutputRowOffsets.size() &&
2477 "Sequence start index out of bounds");
2478 uint64_t NewStmtSeqOffset = OutputRowOffsets[SeqStartIdx];
2481 StmtSeq.set(NewStmtSeqOffset);
2487 Linker.reportWarning(
"Cann't load line table.", ObjFile);
2492void DWARFLinker::emitAcceleratorEntriesForUnit(CompileUnit &Unit) {
2497 for (
const auto &Namespace :
Unit.getNamespaces())
2499 Unit.getStartOffset());
2501 for (
const auto &Pubname :
Unit.getPubnames())
2502 AppleNames.addName(Pubname.Name,
2503 Pubname.Die->getOffset() +
Unit.getStartOffset());
2505 for (
const auto &Pubtype :
Unit.getPubtypes())
2507 Pubtype.Name, Pubtype.Die->getOffset() +
Unit.getStartOffset(),
2508 Pubtype.Die->getTag(),
2511 Pubtype.QualifiedNameHash);
2513 for (
const auto &ObjC :
Unit.getObjC())
2514 AppleObjc.addName(ObjC.Name,
2515 ObjC.Die->getOffset() +
Unit.getStartOffset());
2518 TheDwarfEmitter->emitPubNamesForUnit(Unit);
2519 TheDwarfEmitter->emitPubTypesForUnit(Unit);
2522 for (
const auto &Namespace :
Unit.getNamespaces())
2527 Unit.getTag() == dwarf::DW_TAG_type_unit);
2528 for (
const auto &Pubname :
Unit.getPubnames())
2530 Pubname.Name, Pubname.Die->getOffset(),
2532 Pubname.Die->getTag(),
Unit.getUniqueID(),
2533 Unit.getTag() == dwarf::DW_TAG_type_unit);
2534 for (
const auto &Pubtype :
Unit.getPubtypes())
2536 Pubtype.Name, Pubtype.Die->getOffset(),
2538 Pubtype.Die->getTag(),
Unit.getUniqueID(),
2539 Unit.getTag() == dwarf::DW_TAG_type_unit);
2551void DWARFLinker::patchFrameInfoForObject(LinkContext &
Context) {
2552 DWARFContext &OrigDwarf = *
Context.File.Dwarf;
2553 unsigned SrcAddrSize = OrigDwarf.getDWARFObj().getAddressSize();
2555 StringRef
FrameData = OrigDwarf.getDWARFObj().getFrameSection().Data;
2560 for (std::unique_ptr<CompileUnit> &Unit :
Context.CompileUnits) {
2561 for (
auto CurRange :
Unit->getFunctionRanges())
2562 AllUnitsRanges.insert(CurRange.Range, CurRange.Value);
2565 DataExtractor
Data(FrameData, OrigDwarf.isLittleEndian(), 0);
2566 uint64_t InputOffset = 0;
2570 DenseMap<uint64_t, StringRef> LocalCIES;
2572 while (
Data.isValidOffset(InputOffset)) {
2573 uint64_t EntryOffset = InputOffset;
2574 uint32_t InitialLength =
Data.getU32(&InputOffset);
2575 if (InitialLength == 0xFFFFFFFF)
2576 return reportWarning(
"Dwarf64 bits no supported",
Context.File);
2578 uint32_t CIEId =
Data.getU32(&InputOffset);
2579 if (CIEId == 0xFFFFFFFF) {
2581 StringRef CIEData =
FrameData.substr(EntryOffset, InitialLength + 4);
2582 LocalCIES[EntryOffset] = CIEData;
2584 InputOffset += InitialLength - 4;
2588 uint64_t Loc =
Data.getUnsigned(&InputOffset, SrcAddrSize);
2594 std::optional<AddressRangeValuePair>
Range =
2595 AllUnitsRanges.getRangeThatContains(Loc);
2598 InputOffset = EntryOffset + InitialLength + 4;
2604 StringRef CIEData = LocalCIES[CIEId];
2605 if (CIEData.empty())
2606 return reportWarning(
"Inconsistent debug_frame content. Dropping.",
2611 auto IteratorInserted = EmittedCIEs.insert(
2612 std::make_pair(CIEData, TheDwarfEmitter->getFrameSectionSize()));
2614 if (IteratorInserted.second) {
2615 LastCIEOffset = TheDwarfEmitter->getFrameSectionSize();
2616 IteratorInserted.first->getValue() = LastCIEOffset;
2617 TheDwarfEmitter->emitCIE(CIEData);
2623 unsigned FDERemainingBytes = InitialLength - (4 + SrcAddrSize);
2624 TheDwarfEmitter->emitFDE(IteratorInserted.first->getValue(), SrcAddrSize,
2626 FrameData.substr(InputOffset, FDERemainingBytes));
2627 InputOffset += FDERemainingBytes;
2631uint32_t DWARFLinker::DIECloner::hashFullyQualifiedName(DWARFDie DIE,
2633 const DWARFFile &File,
2634 int ChildRecurseDepth) {
2635 const char *
Name =
nullptr;
2636 DWARFUnit *OrigUnit = &
U.getOrigUnit();
2637 CompileUnit *CU = &
U;
2638 std::optional<DWARFFormValue>
Ref;
2644 if (!(
Ref = DIE.find(dwarf::DW_AT_specification)) &&
2645 !(
Ref = DIE.find(dwarf::DW_AT_abstract_origin)))
2653 Linker.resolveDIEReference(File, CompileUnits, *
Ref, DIE, RefCU)) {
2655 OrigUnit = &RefCU->getOrigUnit();
2660 unsigned Idx = OrigUnit->getDIEIndex(DIE);
2661 if (!Name && DIE.getTag() == dwarf::DW_TAG_namespace)
2662 Name =
"(anonymous namespace)";
2664 if (CU->getInfo(Idx).ParentIdx == 0 ||
2666 CU->getOrigUnit().getDIEAtIndex(CU->getInfo(Idx).ParentIdx).getTag() ==
2667 dwarf::DW_TAG_module)
2668 return djbHash(Name ? Name :
"",
djbHash(ChildRecurseDepth ?
"" :
"::"));
2670 DWARFDie Die = OrigUnit->getDIEAtIndex(CU->getInfo(Idx).ParentIdx);
2679 CUDie.
find({dwarf::DW_AT_dwo_id, dwarf::DW_AT_GNU_dwo_id}));
2688 if (ObjectPrefixMap.empty())
2692 for (
const auto &Entry : ObjectPrefixMap)
2695 return p.str().str();
2702 CUDie.
find({dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
"");
2704 if (PCMFile.empty())
2707 if (ObjectPrefixMap)
2708 PCMFile =
remapPath(PCMFile, *ObjectPrefixMap);
2713std::pair<bool, bool> DWARFLinker::isClangModuleRef(
const DWARFDie &CUDie,
2714 std::string &PCMFile,
2715 LinkContext &Context,
2718 if (PCMFile.empty())
2719 return std::make_pair(
false,
false);
2724 std::string Name =
dwarf::toString(CUDie.find(dwarf::DW_AT_name),
"");
2727 reportWarning(
"Anonymous module skeleton CU for " + PCMFile,
2729 return std::make_pair(
true,
true);
2732 if (!
Quiet && Options.Verbose) {
2734 outs() <<
"Found clang module reference " << PCMFile;
2737 auto Cached = ClangModules.find(PCMFile);
2738 if (Cached != ClangModules.end()) {
2742 if (!
Quiet && Options.Verbose && (Cached->second != DwoId))
2743 reportWarning(Twine(
"hash mismatch: this object file was built against a "
2744 "different version of the module ") +
2747 if (!
Quiet && Options.Verbose)
2748 outs() <<
" [cached].\n";
2749 return std::make_pair(
true,
true);
2752 return std::make_pair(
true,
false);
2755bool DWARFLinker::registerModuleReference(
const DWARFDie &CUDie,
2760 std::string PCMFile =
getPCMFile(CUDie, Options.ObjectPrefixMap);
2761 std::pair<bool, bool> IsClangModuleRef =
2762 isClangModuleRef(CUDie, PCMFile,
Context, Indent,
false);
2764 if (!IsClangModuleRef.first)
2767 if (IsClangModuleRef.second)
2770 if (Options.Verbose)
2775 ClangModules.insert({PCMFile,
getDwoId(CUDie)});
2777 if (
Error E = loadClangModule(Loader, CUDie, PCMFile,
Context, OnCUDieLoaded,
2785Error DWARFLinker::loadClangModule(
2786 ObjFileLoaderTy Loader,
const DWARFDie &CUDie,
const std::string &PCMFile,
2790 std::string ModuleName =
dwarf::toString(CUDie.find(dwarf::DW_AT_name),
"");
2793 SmallString<0>
Path(Options.PrependPath);
2800 if (Loader ==
nullptr) {
2801 reportError(
"Could not load clang module: loader is not specified.\n",
2806 auto ErrOrObj = Loader(
Context.File.FileName, Path);
2810 std::unique_ptr<CompileUnit>
Unit;
2811 for (
const auto &CU : ErrOrObj->Dwarf->compile_units()) {
2814 auto ChildCUDie = CU->getUnitDIE();
2817 if (!registerModuleReference(ChildCUDie,
Context, Loader, OnCUDieLoaded,
2822 ": Clang modules are expected to have exactly 1 compile unit.\n");
2823 reportError(Err,
Context.File);
2829 uint64_t PCMDwoId =
getDwoId(ChildCUDie);
2830 if (PCMDwoId != DwoId) {
2831 if (Options.Verbose)
2833 Twine(
"hash mismatch: this object file was built against a "
2834 "different version of the module ") +
2838 ClangModules[PCMFile] = PCMDwoId;
2842 Unit = std::make_unique<CompileUnit>(*CU, UniqueUnitID++, !Options.NoODR,
2848 Context.ModuleUnits.emplace_back(RefModuleUnit{*ErrOrObj, std::move(Unit)});
2853Expected<uint64_t> DWARFLinker::DIECloner::cloneAllCompileUnits(
2854 DWARFContext &DwarfContext,
const DWARFFile &File,
bool IsLittleEndian) {
2855 uint64_t OutputDebugInfoSize =
2857 const uint64_t StartOutputDebugInfoSize = OutputDebugInfoSize;
2859 for (
auto &CurrentUnit : CompileUnits) {
2860 const uint16_t DwarfVersion = CurrentUnit->getOrigUnit().getVersion();
2861 const uint32_t UnitHeaderSize = DwarfVersion >= 5 ? 12 : 11;
2862 auto InputDIE = CurrentUnit->getOrigUnit().getUnitDIE();
2863 CurrentUnit->setStartOffset(OutputDebugInfoSize);
2865 OutputDebugInfoSize = CurrentUnit->computeNextUnitOffset(DwarfVersion);
2868 if (CurrentUnit->getInfo(0).Keep) {
2871 CurrentUnit->createOutputDIE();
2872 rememberUnitForMacroOffset(*CurrentUnit);
2873 cloneDIE(InputDIE, File, *CurrentUnit, 0 , UnitHeaderSize,
2874 0, IsLittleEndian, CurrentUnit->getOutputUnitDIE());
2877 OutputDebugInfoSize = CurrentUnit->computeNextUnitOffset(DwarfVersion);
2881 if (
Error E = generateLineTableForUnit(*CurrentUnit))
2884 Linker.emitAcceleratorEntriesForUnit(*CurrentUnit);
2889 if (
Error E = Linker.generateUnitRanges(*CurrentUnit, File, AddrPool))
2892 auto ProcessExpr = [&](SmallVectorImpl<uint8_t> &SrcBytes,
2893 SmallVectorImpl<uint8_t> &OutBytes,
2894 int64_t RelocAdjustment) {
2895 DWARFUnit &OrigUnit = CurrentUnit->getOrigUnit();
2896 DataExtractor
Data(SrcBytes, IsLittleEndian,
2897 OrigUnit.getAddressByteSize());
2898 cloneExpression(
Data,
2899 DWARFExpression(
Data, OrigUnit.getAddressByteSize(),
2900 OrigUnit.getFormParams().Format),
2901 File, *CurrentUnit, OutBytes, RelocAdjustment,
2904 if (
Error E = generateUnitLocations(*CurrentUnit, File, ProcessExpr))
2906 if (
Error E = emitDebugAddrSection(*CurrentUnit, DwarfVersion))
2915 Emitter->emitMacroTables(
File.Dwarf.get(), UnitMacroMap, DebugStrPool);
2918 for (
auto &CurrentUnit : CompileUnits) {
2919 CurrentUnit->fixupForwardReferences();
2921 if (!CurrentUnit->getOutputUnitDIE())
2924 unsigned DwarfVersion = CurrentUnit->getOrigUnit().getVersion();
2927 CurrentUnit->getStartOffset());
2928 Emitter->emitCompileUnitHeader(*CurrentUnit, DwarfVersion);
2929 Emitter->emitDIE(*CurrentUnit->getOutputUnitDIE());
2931 CurrentUnit->computeNextUnitOffset(DwarfVersion));
2935 return OutputDebugInfoSize - StartOutputDebugInfoSize;
2938void DWARFLinker::copyInvariantDebugSection(DWARFContext &
Dwarf) {
2939 TheDwarfEmitter->emitSectionContents(
Dwarf.getDWARFObj().getLocSection().Data,
2941 TheDwarfEmitter->emitSectionContents(
2942 Dwarf.getDWARFObj().getRangesSection().Data,
2944 TheDwarfEmitter->emitSectionContents(
2946 TheDwarfEmitter->emitSectionContents(
Dwarf.getDWARFObj().getArangesSection(),
2948 TheDwarfEmitter->emitSectionContents(
2950 TheDwarfEmitter->emitSectionContents(
2951 Dwarf.getDWARFObj().getRnglistsSection().Data,
2953 TheDwarfEmitter->emitSectionContents(
2954 Dwarf.getDWARFObj().getLoclistsSection().Data,
2960 ObjectContexts.emplace_back(LinkContext(File));
2962 if (ObjectContexts.back().File.Dwarf) {
2963 for (
const std::unique_ptr<DWARFUnit> &
CU :
2964 ObjectContexts.back().File.Dwarf->compile_units()) {
2973 registerModuleReference(CUDie, ObjectContexts.back(), Loader,
2980 assert((Options.TargetDWARFVersion != 0) &&
2981 "TargetDWARFVersion should be set");
2985 unsigned NumObjects = ObjectContexts.size();
2997 for (LinkContext &OptContext : ObjectContexts) {
2998 if (Options.Verbose)
2999 outs() <<
"DEBUG MAP OBJECT: " << OptContext.File.FileName <<
"\n";
3001 if (!OptContext.File.Dwarf)
3004 if (Options.VerifyInputDWARF)
3005 verifyInput(OptContext.File);
3012 !OptContext.File.Addresses->hasValidRelocs()) {
3013 if (Options.Verbose)
3014 outs() <<
"No valid relocations found. Skipping.\n";
3018 OptContext.Skip =
true;
3023 if (!OptContext.File.Dwarf)
3027 if (!OptContext.File.Dwarf->types_section_units().empty()) {
3028 reportWarning(
"type units are not currently supported: file will "
3031 OptContext.Skip =
true;
3037 OptContext.CompileUnits.reserve(
3038 OptContext.File.Dwarf->getNumCompileUnits());
3039 for (
const auto &
CU : OptContext.File.Dwarf->compile_units()) {
3040 auto CUDie =
CU->getUnitDIE(
true);
3041 if (Options.Verbose) {
3042 outs() <<
"Input compilation unit:";
3045 DumpOpts.
Verbose = Options.Verbose;
3046 CUDie.dump(
outs(), 0, DumpOpts);
3050 for (
auto &
CU : OptContext.ModuleUnits) {
3051 if (
Error Err = cloneModuleUnit(OptContext,
CU, ODRContexts, DebugStrPool,
3052 DebugLineStrPool, StringOffsetPool))
3053 reportWarning(
toString(std::move(Err)),
CU.File);
3063 (TheDwarfEmitter ==
nullptr) ? 0
3064 : TheDwarfEmitter->getDebugInfoSectionSize();
3068 std::mutex ProcessedFilesMutex;
3069 std::condition_variable ProcessedFilesConditionVariable;
3070 BitVector ProcessedFiles(NumObjects,
false);
3074 auto AnalyzeLambda = [&](
size_t I) {
3075 auto &Context = ObjectContexts[
I];
3077 if (Context.Skip || !Context.File.Dwarf)
3080 for (
const auto &
CU : Context.File.Dwarf->compile_units()) {
3083 auto CUDie =
CU->getUnitDIE(
false);
3084 std::string PCMFile =
getPCMFile(CUDie, Options.ObjectPrefixMap);
3087 !isClangModuleRef(CUDie, PCMFile, Context, 0,
true).first) {
3088 Context.CompileUnits.push_back(std::make_unique<CompileUnit>(
3089 *
CU, UniqueUnitID++, !Options.NoODR && !Options.Update,
""));
3094 for (
auto &CurrentUnit : Context.CompileUnits) {
3095 auto CUDie = CurrentUnit->getOrigUnit().getUnitDIE();
3099 *CurrentUnit, &ODRContexts.
getRoot(), ODRContexts,
3100 ModulesEndOffset, Options.ParseableSwiftInterfaces,
3102 reportWarning(Warning, Context.File, &DIE);
3115 auto &OptContext = ObjectContexts[
I];
3116 if (OptContext.Skip || !OptContext.File.Dwarf)
3125 for (
auto &CurrentUnit : OptContext.CompileUnits)
3126 CurrentUnit->markEverythingAsKept();
3127 copyInvariantDebugSection(*OptContext.File.Dwarf);
3129 for (
auto &CurrentUnit : OptContext.CompileUnits) {
3130 lookForDIEsToKeep(*OptContext.File.Addresses, OptContext.CompileUnits,
3131 CurrentUnit->getOrigUnit().getUnitDIE(),
3132 OptContext.File, *CurrentUnit, 0);
3142 if (OptContext.File.Addresses->hasValidRelocs() ||
3144 SizeByObject[OptContext.File.FileName].Input =
3147 DIECloner(*
this, TheDwarfEmitter, OptContext.File, DIEAlloc,
3148 OptContext.CompileUnits, Options.Update, DebugStrPool,
3149 DebugLineStrPool, StringOffsetPool)
3150 .cloneAllCompileUnits(*OptContext.File.Dwarf, OptContext.File,
3151 OptContext.File.Dwarf->isLittleEndian());
3156 SizeByObject[OptContext.File.FileName].Output = *SizeOrErr;
3158 if ((TheDwarfEmitter !=
nullptr) && !OptContext.CompileUnits.empty() &&
3160 patchFrameInfoForObject(OptContext);
3163 cleanupAuxiliarryData(OptContext);
3166 auto EmitLambda = [&]() {
3168 if (TheDwarfEmitter !=
nullptr) {
3169 TheDwarfEmitter->emitAbbrevs(Abbreviations, Options.TargetDWARFVersion);
3170 TheDwarfEmitter->emitStrings(DebugStrPool);
3171 TheDwarfEmitter->emitStringOffsets(StringOffsetPool.
getValues(),
3172 Options.TargetDWARFVersion);
3173 TheDwarfEmitter->emitLineStrings(DebugLineStrPool);
3175 switch (TableKind) {
3177 TheDwarfEmitter->emitAppleNamespaces(AppleNamespaces);
3178 TheDwarfEmitter->emitAppleNames(AppleNames);
3179 TheDwarfEmitter->emitAppleTypes(AppleTypes);
3180 TheDwarfEmitter->emitAppleObjc(AppleObjc);
3187 TheDwarfEmitter->emitDebugNames(DebugNames);
3194 auto AnalyzeAll = [&]() {
3195 for (
unsigned I = 0,
E = NumObjects;
I !=
E; ++
I) {
3198 std::unique_lock<std::mutex> LockGuard(ProcessedFilesMutex);
3199 ProcessedFiles.
set(
I);
3200 ProcessedFilesConditionVariable.notify_one();
3205 for (
unsigned I = 0,
E = NumObjects;
I !=
E; ++
I) {
3207 std::unique_lock<std::mutex> LockGuard(ProcessedFilesMutex);
3208 if (!ProcessedFiles[
I]) {
3209 ProcessedFilesConditionVariable.wait(
3210 LockGuard, [&]() {
return ProcessedFiles[
I]; });
3226 if (Options.Threads == 1) {
3227 for (
unsigned I = 0,
E = NumObjects;
I !=
E; ++
I) {
3237 Pool.
async(AnalyzeAll);
3238 Pool.
async(CloneAll, std::reference_wrapper<Error>(CE));
3245 if (Options.Statistics) {
3247 std::vector<std::pair<StringRef, DebugInfoSize>> Sorted;
3248 for (
auto &
E : SizeByObject)
3249 Sorted.emplace_back(
E.first(),
E.second);
3251 return LHS.second.Output >
RHS.second.Output;
3254 auto ComputePercentange = [](int64_t
Input, int64_t Output) ->
float {
3255 const float Difference = Output -
Input;
3256 const float Sum =
Input + Output;
3259 return (Difference / (Sum / 2));
3262 int64_t InputTotal = 0;
3263 int64_t OutputTotal = 0;
3264 const char *FormatStr =
"{0,-45} {1,10}b {2,10}b {3,8:P}\n";
3267 outs() <<
".debug_info section size (in bytes)\n";
3268 outs() <<
"----------------------------------------------------------------"
3269 "---------------\n";
3270 outs() <<
"Filename Object "
3272 outs() <<
"----------------------------------------------------------------"
3273 "---------------\n";
3276 for (
auto &
E : Sorted) {
3277 InputTotal +=
E.second.Input;
3278 OutputTotal +=
E.second.Output;
3281 E.second.Output, ComputePercentange(
E.second.Input,
E.second.Output));
3284 outs() <<
"----------------------------------------------------------------"
3285 "---------------\n";
3287 ComputePercentange(InputTotal, OutputTotal));
3288 outs() <<
"----------------------------------------------------------------"
3289 "---------------\n\n";
3295Error DWARFLinker::cloneModuleUnit(LinkContext &Context, RefModuleUnit &Unit,
3301 assert(Unit.Unit.get() !=
nullptr);
3303 if (!Unit.Unit->getOrigUnit().getUnitDIE().hasChildren())
3308 outs() <<
"cloning .debug_info from " << Unit.File.FileName <<
"\n";
3313 &ODRContexts.
getRoot(), ODRContexts, 0,
3314 Options.ParseableSwiftInterfaces,
3316 reportWarning(Warning, Context.File, &DIE);
3319 Unit.Unit->markEverythingAsKept();
3323 CompileUnits.emplace_back(std::move(Unit.Unit));
3326 DIECloner(*
this, TheDwarfEmitter, Unit.File, DIEAlloc, CompileUnits,
3327 Options.Update, DebugStrPool, DebugLineStrPool,
3329 .cloneAllCompileUnits(*Unit.File.Dwarf, Unit.File,
3330 Unit.File.Dwarf->isLittleEndian());
3336void DWARFLinker::verifyInput(
const DWARFFile &File) {
3343 if (
Options.InputVerificationHandler)
3344 Options.InputVerificationHandler(File, OS.str());
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static uint32_t hashFullyQualifiedName(CompileUnit &InputCU, DWARFDie &InputDIE, int ChildRecurseDepth=0)
This file implements the BitVector class.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
#define LLVM_LIKELY(EXPR)
dxil DXContainer Global Emitter
Provides ErrorOr<T> smart pointer.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
BitVector & set()
Set all bits in the bitvector.
void setChildrenFlag(bool hasChild)
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
A structured debug information entry.
unsigned getAbbrevNumber() const
DIE & addChild(DIE *Child)
Add a child to the DIE.
LLVM_ABI DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
void setOffset(unsigned O)
dwarf::Tag getTag() const
static LLVM_ABI std::optional< uint64_t > getDefiningParentDieOffset(const DIE &Die)
If Die has a non-null parent and the parent is not a declaration, return its offset.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
uint64_t getOffset() const
Get the absolute offset into the debug info or types section.
iterator_range< iterator > children() const
LLVM_ABI std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
dwarf::Tag getTag() const
LLVM_ABI std::optional< unsigned > getSubCode() const
uint64_t getEndOffset() const
Encoding
Size and signedness of expression operations' operands.
const Description & getDescription() const
uint64_t getRawOperand(unsigned Idx) const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
void wait() override
Blocking wait for all the tasks to execute first.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(uint64_t Val)
static LLVM_ABI raw_ostream & error()
Convenience method for printing "error: " to stderr.
This class represents DWARF information for source file and it's address map.
std::map< std::string, std::string > ObjectPrefixMapTy
function_ref< void(const DWARFUnit &Unit)> CompileUnitHandlerTy
AccelTableKind
The kind of accelerator tables to be emitted.
@ DebugNames
.debug_names.
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
@ Pub
.debug_pubnames, .debug_pubtypes
std::map< std::string, std::string > SwiftInterfacesMapTy
std::function< ErrorOr< DWARFFile & >( StringRef ContainerName, StringRef Path)> ObjFileLoaderTy
const SmallVector< T > & getValues() const
Stores all information relating to a compile unit, be it in its original instance in the object file ...
void addObjectFile(DWARFFile &File, ObjFileLoaderTy Loader=nullptr, CompileUnitHandlerTy OnCUDieLoaded=[](const DWARFUnit &) {}) override
Add object file to be linked.
Error link() override
Link debug info for added objFiles. Object files are linked all together.
This class gives a tree-like API to the DenseMap that stores the DeclContext objects.
PointerIntPair< DeclContext *, 1 > getChildDeclContext(DeclContext &Context, const DWARFDie &DIE, CompileUnit &Unit, bool InClangModule)
Get the child of Context described by DIE in Unit.
A DeclContext is a named program scope that is used for ODR uniquing of types.
void setDefinedInClangModule(bool Val)
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
LLVM_ABI StringRef FormatString(DwarfFormat Format)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
SmallVector< PatchLocation > RngListAttributesTy
std::vector< std::unique_ptr< CompileUnit > > UnitListTy
IndexedValuesMap< uint64_t > DebugDieValuePool
AddressRangesMap RangesTy
Mapped value in the address map is the offset to apply to the linked address.
SmallVector< PatchLocation > LocListAttributesTy
StringRef guessDeveloperDir(StringRef SysRoot)
Make a best effort to guess the Xcode.app/Contents/Developer path from an SDK path.
void buildStmtSeqOffsetToFirstRowIndex(const DWARFDebugLine::LineTable <, ArrayRef< uint64_t > SortedStmtSeqOffsets, DenseMap< uint64_t, uint64_t > &SeqOffToFirstRow)
Build a map from an input DW_AT_LLVM_stmt_sequence byte offset to the first-row index (in LT....
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
bool isInToolchainDir(StringRef Path)
Make a best effort to determine whether Path is inside a toolchain.
bool isTlsAddressOp(uint8_t O)
std::optional< uint64_t > toAddress(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
LLVM_ABI bool doesFormBelongToClass(dwarf::Form Form, DWARFFormValue::FormClass FC, uint16_t DwarfVersion)
Check whether specified Form belongs to the FC class.
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
@ DW_FLAG_type_implementation
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
LLVM_ABI bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI bool replace_path_prefix(SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
constexpr bool IsLittleEndianHost
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
static void verifyKeepChain(CompileUnit &CU)
Verify the keep chain by looking for DIEs that are kept but who's parent isn't.
FunctionAddr VTableAddr Value
static void updateRefIncompleteness(const DWARFDie &Die, CompileUnit &CU, CompileUnit::DIEInfo &RefInfo)
Helper that updates the completeness of the current DIE based on the completeness of the DIEs it refe...
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
static void patchAddrBase(DIE &Die, DIEInteger Offset)
auto unique(Range &&R, Predicate P)
static std::string remapPath(StringRef Path, const DWARFLinkerBase::ObjectPrefixMapTy &ObjectPrefixMap)
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
static CompileUnit * getUnitForOffset(const UnitListTy &Units, uint64_t Offset)
Similar to DWARFUnitSection::getUnitForOffset(), but returning our CompileUnit object instead.
static void insertLineSequence(std::vector< TrackedRow > &Seq, std::vector< TrackedRow > &Rows)
Insert the new line info sequence Seq into the current set of already linked line info Rows.
static void resolveRelativeObjectPath(SmallVectorImpl< char > &Buf, DWARFDie CU)
Resolve the relative path to a build artifact referenced by DWARF by applying DW_AT_comp_dir.
static std::string getPCMFile(const DWARFDie &CUDie, const DWARFLinkerBase::ObjectPrefixMapTy *ObjectPrefixMap)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
static bool shouldSkipAttribute(bool Update, DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, bool SkipPC)
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
static uint64_t getDebugInfoSize(DWARFContext &Dwarf)
Compute the total size of the debug info.
static bool isTypeTag(uint16_t Tag)
@ Dwarf
DWARF v5 .debug_names.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI std::optional< StringRef > StripTemplateParameters(StringRef Name)
If Name is the name of a templated function that includes template parameters, returns a substring of...
static uint64_t getDwoId(const DWARFDie &CUDie)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
static bool updatePruning(const DWARFDie &Die, CompileUnit &CU, uint64_t ModulesEndOffset)
@ Success
The lock was released successfully.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Ref
The access may reference the value stored in memory.
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
static void updateChildIncompleteness(const DWARFDie &Die, CompileUnit &CU, CompileUnit::DIEInfo &ChildInfo)
Helper that updates the completeness of the current DIE based on the completeness of one of its child...
SingleThreadExecutor DefaultThreadPool
DWARFExpression::Operation Op
static void updateChildPruning(const DWARFDie &Die, CompileUnit &CU, CompileUnit::DIEInfo &ChildInfo)
uint32_t djbHash(StringRef Buffer, uint32_t H=5381)
The Bernstein hash function used by the DWARF accelerator tables.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI std::optional< ObjCSelectorNames > getObjCNamesIfSelector(StringRef Name)
If Name is the AT_name of a DIE which refers to an Objective-C selector, returns an instance of ObjCS...
static void analyzeContextInfo(const DWARFDie &DIE, unsigned ParentIdx, CompileUnit &CU, DeclContext *CurrentDeclContext, DeclContextTree &Contexts, uint64_t ModulesEndOffset, DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces, std::function< void(const Twine &, const DWARFDie &)> ReportWarning)
Recursive helper to build the global DeclContext information and gather the child->parent relationshi...
static bool dieNeedsChildrenToBeMeaningful(uint32_t Tag)
StrongType< NonRelocatableStringpool, OffsetsTag > OffsetsStringPool
static bool isODRCanonicalCandidate(const DWARFDie &Die, CompileUnit &CU)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
static void analyzeImportedModule(const DWARFDie &DIE, CompileUnit &CU, DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces, std::function< void(const Twine &, const DWARFDie &)> ReportWarning)
Collect references to parseable Swift interfaces in imported DW_TAG_module blocks.
ContextWorklistItemType
The distinct types of work performed by the work loop in analyzeContextInfo.
void consumeError(Error Err)
Consume a Error without doing anything.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
static bool isODRAttribute(uint16_t Attr)
static void patchStmtList(DIE &Die, DIEInteger Offset)
static void constructSeqOffsettoOrigRowMapping(CompileUnit &Unit, const DWARFDebugLine::LineTable <, DenseMap< uint64_t, uint64_t > &SeqOffToOrigRow)
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
int64_t LinkedOffsetFixupVal
uint64_t InputAttrStartOffset
uint64_t InputAttrEndOffset
A broken link in the keep chain.
BrokenLink(DWARFDie Parent, DWARFDie Child)
This class represents an item in the work list.
CompileUnit::DIEInfo * OtherInfo
ContextWorklistItem(DWARFDie Die, DeclContext *Context, unsigned ParentIdx, bool InImportedModule)
ContextWorklistItemType Type
ContextWorklistItem(DWARFDie Die, ContextWorklistItemType T, CompileUnit::DIEInfo *OtherInfo=nullptr)
Container for dump options that control which debug information will be dumped.
DIDumpOptions noImplicitRecursion() const
Return the options with RecurseDepth set to 0 unless explicitly required.
unsigned ChildRecurseDepth
static LLVM_ABI bool mayHaveLocationList(dwarf::Attribute Attr)
Identify DWARF attributes that may contain a pointer to a location list.
static LLVM_ABI bool mayHaveLocationExpr(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
Standard .debug_line state machine structure.
SmallVector< Encoding > Op
Encoding for Op operands.
Hold the input and output of the debug info size in bytes.
A helper struct to help keep track of the association between the input and output rows during line t...
Information gathered about a DIE in the object file.
bool Prune
Is this a pure forward declaration we can strip?
bool Incomplete
Does DIE transitively refer an incomplete decl?