diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/DWARFLinker.h --- a/llvm/include/llvm/DWARFLinker/DWARFLinker.h +++ b/llvm/include/llvm/DWARFLinker/DWARFLinker.h @@ -98,10 +98,8 @@ /// Emit DIE containing warnings. virtual void emitPaperTrailWarningsDie(DIE &Die) = 0; - /// Emit section named SecName with content equals to - /// corresponding section in Obj. - virtual void emitSectionContents(const object::ObjectFile &Obj, - StringRef SecName) = 0; + /// Emit section named SecName with data SecData. + virtual void emitSectionContents(StringRef SecData, StringRef SecName) = 0; /// Emit the abbreviation table \p Abbrevs to the debug_abbrev section. virtual void @@ -202,19 +200,21 @@ using UnitListTy = std::vector>; -/// this class represents Object File and it`s additional info. -class DwarfLinkerObjFile { +/// this class represents DWARF information for source file +/// and it`s address map. +class DwarfFile { public: - DwarfLinkerObjFile(StringRef Name, const object::ObjectFile *File, - const std::vector &Warnings) - : FileName(Name), ObjFile(File), Warnings(Warnings) {} + DwarfFile(StringRef Name, DWARFContext *Dwarf, AddressesMap *Addresses, + const std::vector &Warnings) + : FileName(Name), Dwarf(Dwarf), Addresses(Addresses), Warnings(Warnings) { + } /// object file name. StringRef FileName; - /// object file. - const object::ObjectFile *ObjFile; + /// source DWARF information. + DWARFContext *Dwarf = nullptr; /// helpful address information(list of valid address ranges, relocations). - std::unique_ptr Addresses; + AddressesMap *Addresses = nullptr; /// warnings for object file. const std::vector &Warnings; }; @@ -222,8 +222,8 @@ typedef std::function messageHandler; -typedef std::function(StringRef ContainerName, - StringRef Path)> +typedef std::function(StringRef ContainerName, + StringRef Path)> objFileLoader; typedef std::map swiftInterfacesMap; @@ -248,7 +248,7 @@ : TheDwarfEmitter(Emitter), DwarfLinkerClientID(ClientID) {} /// Add object file to be linked. - void addObjectFile(DwarfLinkerObjFile &ObjFile); + void addObjectFile(DwarfFile &File); /// Link debug info for added objFiles. Object /// files are linked all together. @@ -367,16 +367,16 @@ /// returns true if we need to translate strings. bool needToTranslateStrings() { return StringsTranslator != nullptr; } - void reportWarning(const Twine &Warning, const DwarfLinkerObjFile &OF, + void reportWarning(const Twine &Warning, const DwarfFile &File, const DWARFDie *DIE = nullptr) const { if (Options.WarningHandler != nullptr) - Options.WarningHandler(Warning, OF.FileName, DIE); + Options.WarningHandler(Warning, File.FileName, DIE); } - void reportError(const Twine &Warning, const DwarfLinkerObjFile &OF, + void reportError(const Twine &Warning, const DwarfFile &File, const DWARFDie *DIE = nullptr) const { if (Options.ErrorHandler != nullptr) - Options.ErrorHandler(Warning, OF.FileName, DIE); + Options.ErrorHandler(Warning, File.FileName, DIE); } /// Remembers the oldest and newest DWARF version we've seen in a unit. @@ -389,30 +389,24 @@ void updateAccelKind(DWARFContext &Dwarf); /// Emit warnings as Dwarf compile units to leave a trail after linking. - bool emitPaperTrailWarnings(const DwarfLinkerObjFile &OF, + bool emitPaperTrailWarnings(const DwarfFile &File, OffsetsStringPool &StringPool); - void copyInvariantDebugSection(const object::ObjectFile &Obj); + void copyInvariantDebugSection(DWARFContext &Dwarf); /// Keeps track of data associated with one object during linking. struct LinkContext { - DwarfLinkerObjFile &ObjectFile; - std::unique_ptr DwarfContext; + DwarfFile &File; UnitListTy CompileUnits; bool Skip = false; - LinkContext(DwarfLinkerObjFile &objFile) : ObjectFile(objFile) { - - if (ObjectFile.ObjFile) - DwarfContext = DWARFContext::create(*ObjectFile.ObjFile); - } + LinkContext(DwarfFile &File) : File(File) {} /// Clear part of the context that's no longer needed when we're done with /// the debug object. void clear() { - DwarfContext.reset(nullptr); CompileUnits.clear(); - ObjectFile.Addresses->clear(); + File.Addresses->clear(); } }; @@ -435,7 +429,7 @@ /// kept. All DIEs referenced though attributes should be kept. void lookForRefDIEsToKeep(const DWARFDie &Die, CompileUnit &CU, unsigned Flags, const UnitListTy &Units, - const DwarfLinkerObjFile &OF, + const DwarfFile &File, SmallVectorImpl &Worklist); /// \defgroup FindRootDIEs Find DIEs corresponding to Address map entries. @@ -447,7 +441,7 @@ /// The return value indicates whether the DIE is incomplete. void lookForDIEsToKeep(AddressesMap &RelocMgr, RangesTy &Ranges, const UnitListTy &Units, const DWARFDie &DIE, - const DwarfLinkerObjFile &OF, CompileUnit &CU, + const DwarfFile &File, CompileUnit &CU, unsigned Flags); /// If this compile unit is really a skeleton CU that points to a @@ -457,7 +451,7 @@ /// pointing to the module, and a DW_AT_gnu_dwo_id with the module /// hash. bool registerModuleReference(DWARFDie CUDie, const DWARFUnit &Unit, - const DwarfLinkerObjFile &OF, + const DwarfFile &File, OffsetsStringPool &OffsetsStringPool, UniquingStringPool &UniquingStringPoolStringPool, DeclContextTree &ODRContexts, @@ -470,7 +464,7 @@ /// to Units. Error loadClangModule(DWARFDie CUDie, StringRef FilePath, StringRef ModuleName, uint64_t DwoId, - const DwarfLinkerObjFile &OF, + const DwarfFile &File, OffsetsStringPool &OffsetsStringPool, UniquingStringPool &UniquingStringPool, DeclContextTree &ODRContexts, uint64_t ModulesEndOffset, @@ -481,11 +475,11 @@ void keepDIEAndDependencies(AddressesMap &RelocMgr, RangesTy &Ranges, const UnitListTy &Units, const DWARFDie &DIE, CompileUnit::DIEInfo &MyInfo, - const DwarfLinkerObjFile &OF, CompileUnit &CU, + const DwarfFile &File, CompileUnit &CU, bool UseODR); unsigned shouldKeepDIE(AddressesMap &RelocMgr, RangesTy &Ranges, - const DWARFDie &DIE, const DwarfLinkerObjFile &OF, + const DWARFDie &DIE, const DwarfFile &File, CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo, unsigned Flags); @@ -496,8 +490,7 @@ CompileUnit::DIEInfo &MyInfo, unsigned Flags); unsigned shouldKeepSubprogramDIE(AddressesMap &RelocMgr, RangesTy &Ranges, - const DWARFDie &DIE, - const DwarfLinkerObjFile &OF, + const DWARFDie &DIE, const DwarfFile &File, CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo, unsigned Flags); @@ -506,8 +499,7 @@ /// RefValue. The resulting DIE might be in another CompileUnit which is /// stored into \p ReferencedCU. \returns null if resolving fails for any /// reason. - DWARFDie resolveDIEReference(const DwarfLinkerObjFile &OF, - const UnitListTy &Units, + DWARFDie resolveDIEReference(const DwarfFile &File, const UnitListTy &Units, const DWARFFormValue &RefValue, const DWARFDie &DIE, CompileUnit *&RefCU); @@ -522,7 +514,7 @@ class DIECloner { DWARFLinker &Linker; DwarfEmitter *Emitter; - DwarfLinkerObjFile &ObjFile; + DwarfFile &ObjFile; /// Allocator used for all the DIEValue objects. BumpPtrAllocator &DIEAlloc; @@ -532,8 +524,8 @@ bool Update; public: - DIECloner(DWARFLinker &Linker, DwarfEmitter *Emitter, - DwarfLinkerObjFile &ObjFile, BumpPtrAllocator &DIEAlloc, + DIECloner(DWARFLinker &Linker, DwarfEmitter *Emitter, DwarfFile &ObjFile, + BumpPtrAllocator &DIEAlloc, std::vector> &CompileUnits, bool Update) : Linker(Linker), Emitter(Emitter), ObjFile(ObjFile), @@ -550,7 +542,7 @@ /// applied to the entry point of the function to get the linked address. /// \param Die the output DIE to use, pass NULL to create one. /// \returns the root of the cloned tree or null if nothing was selected. - DIE *cloneDIE(const DWARFDie &InputDIE, const DwarfLinkerObjFile &OF, + DIE *cloneDIE(const DWARFDie &InputDIE, const DwarfFile &File, CompileUnit &U, OffsetsStringPool &StringPool, int64_t PCOffset, uint32_t OutOffset, unsigned Flags, bool IsLittleEndian, DIE *Die = nullptr); @@ -558,8 +550,7 @@ /// Construct the output DIE tree by cloning the DIEs we /// chose to keep above. If there are no valid relocs, then there's /// nothing to clone/emit. - void cloneAllCompileUnits(DWARFContext &DwarfContext, - const DwarfLinkerObjFile &OF, + void cloneAllCompileUnits(DWARFContext &DwarfContext, const DwarfFile &File, OffsetsStringPool &StringPool, bool IsLittleEndian); @@ -602,7 +593,7 @@ /// Helper for cloneDIE. unsigned cloneAttribute(DIE &Die, const DWARFDie &InputDIE, - const DwarfLinkerObjFile &OF, CompileUnit &U, + const DwarfFile &File, CompileUnit &U, OffsetsStringPool &StringPool, const DWARFFormValue &Val, const AttributeSpec AttrSpec, unsigned AttrSize, @@ -623,18 +614,18 @@ AttributeSpec AttrSpec, unsigned AttrSize, const DWARFFormValue &Val, - const DwarfLinkerObjFile &OF, + const DwarfFile &File, CompileUnit &Unit); /// Clone a DWARF expression that may be referencing another DIE. void cloneExpression(DataExtractor &Data, DWARFExpression Expression, - const DwarfLinkerObjFile &OF, CompileUnit &Unit, + const DwarfFile &File, CompileUnit &Unit, SmallVectorImpl &OutputBuffer); /// Clone an attribute referencing another DIE and add /// it to \p Die. /// \returns the size of the new attribute. - unsigned cloneBlockAttribute(DIE &Die, const DwarfLinkerObjFile &OF, + unsigned cloneBlockAttribute(DIE &Die, const DwarfFile &File, CompileUnit &Unit, AttributeSpec AttrSpec, const DWARFFormValue &Val, unsigned AttrSize, bool IsLittleEndian); @@ -650,7 +641,7 @@ /// Clone a scalar attribute and add it to \p Die. /// \returns the size of the new attribute. unsigned cloneScalarAttribute(DIE &Die, const DWARFDie &InputDIE, - const DwarfLinkerObjFile &OF, CompileUnit &U, + const DwarfFile &File, CompileUnit &U, AttributeSpec AttrSpec, const DWARFFormValue &Val, unsigned AttrSize, AttributesInfo &Info); @@ -666,7 +657,7 @@ void copyAbbrev(const DWARFAbbreviationDeclaration &Abbrev, bool hasODR); uint32_t hashFullyQualifiedName(DWARFDie DIE, CompileUnit &U, - const DwarfLinkerObjFile &OF, + const DwarfFile &File, int RecurseDepth = 0); /// Helper for cloneDIE. @@ -681,7 +672,7 @@ /// Compute and emit debug_ranges section for \p Unit, and /// patch the attributes referencing it. void patchRangesForUnit(const CompileUnit &Unit, DWARFContext &Dwarf, - const DwarfLinkerObjFile &OF) const; + const DwarfFile &File) const; /// Generate and emit the DW_AT_ranges attribute for a compile_unit if it had /// one. @@ -691,7 +682,7 @@ /// parts according to the linked function ranges and emit the result in the /// debug_line section. void patchLineTableForUnit(CompileUnit &Unit, DWARFContext &OrigDwarf, - const DwarfLinkerObjFile &OF); + const DwarfFile &File); /// Emit the accelerator entries for \p Unit. void emitAcceleratorEntriesForUnit(CompileUnit &Unit); @@ -699,7 +690,7 @@ void emitAppleAcceleratorEntriesForUnit(CompileUnit &Unit); /// Patch the frame info for an object file and emit it. - void patchFrameInfoForObject(const DwarfLinkerObjFile &, RangesTy &Ranges, + void patchFrameInfoForObject(const DwarfFile &, RangesTy &Ranges, DWARFContext &, unsigned AddressSize); /// FoldingSet that uniques the abbreviations. diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp --- a/llvm/lib/DWARFLinker/DWARFLinker.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp @@ -21,7 +21,6 @@ #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFSection.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" -#include "llvm/Object/ObjectFile.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" @@ -47,7 +46,7 @@ /// Resolve the DIE attribute reference that has been extracted in \p RefValue. /// The resulting DIE might be in another CompileUnit which is stored into \p /// ReferencedCU. \returns null if resolving fails for any reason. -DWARFDie DWARFLinker::resolveDIEReference(const DwarfLinkerObjFile &OF, +DWARFDie DWARFLinker::resolveDIEReference(const DwarfFile &File, const UnitListTy &Units, const DWARFFormValue &RefValue, const DWARFDie &DIE, @@ -62,7 +61,7 @@ return RefDie; } - reportWarning("could not find referenced DIE", OF, &DIE); + reportWarning("could not find referenced DIE", File, &DIE); return DWARFDie(); } @@ -373,8 +372,8 @@ /// \returns updated TraversalFlags. unsigned DWARFLinker::shouldKeepSubprogramDIE( AddressesMap &RelocMgr, RangesTy &Ranges, const DWARFDie &DIE, - const DwarfLinkerObjFile &OF, CompileUnit &Unit, - CompileUnit::DIEInfo &MyInfo, unsigned Flags) { + const DwarfFile &File, CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo, + unsigned Flags) { const auto *Abbrev = DIE.getAbbreviationDeclarationPtr(); Flags |= TF_InFunctionScope; @@ -421,7 +420,7 @@ Optional HighPc = DIE.getHighPC(*LowPc); if (!HighPc) { - reportWarning("Function without high_pc. Range will be discarded.\n", OF, + reportWarning("Function without high_pc. Range will be discarded.\n", File, &DIE); return Flags; } @@ -435,8 +434,7 @@ /// Check if a DIE should be kept. /// \returns updated TraversalFlags. unsigned DWARFLinker::shouldKeepDIE(AddressesMap &RelocMgr, RangesTy &Ranges, - const DWARFDie &DIE, - const DwarfLinkerObjFile &OF, + const DWARFDie &DIE, const DwarfFile &File, CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo, unsigned Flags) { @@ -446,7 +444,7 @@ return shouldKeepVariableDIE(RelocMgr, DIE, Unit, MyInfo, Flags); case dwarf::DW_TAG_subprogram: case dwarf::DW_TAG_label: - return shouldKeepSubprogramDIE(RelocMgr, Ranges, DIE, OF, Unit, MyInfo, + return shouldKeepSubprogramDIE(RelocMgr, Ranges, DIE, File, Unit, MyInfo, Flags); case dwarf::DW_TAG_base_type: // DWARF Expressions may reference basic types, but scanning them @@ -544,7 +542,7 @@ /// kept. All DIEs referenced though attributes should be kept. void DWARFLinker::lookForRefDIEsToKeep( const DWARFDie &Die, CompileUnit &CU, unsigned Flags, - const UnitListTy &Units, const DwarfLinkerObjFile &OF, + const UnitListTy &Units, const DwarfFile &File, SmallVectorImpl &Worklist) { bool UseOdr = (Flags & DWARFLinker::TF_DependencyWalk) ? (Flags & DWARFLinker::TF_ODR) @@ -566,7 +564,8 @@ Val.extractValue(Data, &Offset, Unit.getFormParams(), &Unit); CompileUnit *ReferencedCU; - if (auto RefDie = resolveDIEReference(OF, Units, Val, Die, ReferencedCU)) { + if (auto RefDie = + resolveDIEReference(File, Units, Val, Die, ReferencedCU)) { uint32_t RefIdx = ReferencedCU->getOrigUnit().getDIEIndex(RefDie); CompileUnit::DIEInfo &Info = ReferencedCU->getInfo(RefIdx); bool IsModuleRef = Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset() && @@ -653,8 +652,7 @@ /// The return value indicates whether the DIE is incomplete. void DWARFLinker::lookForDIEsToKeep(AddressesMap &AddressesMap, RangesTy &Ranges, const UnitListTy &Units, - const DWARFDie &Die, - const DwarfLinkerObjFile &OF, + const DWARFDie &Die, const DwarfFile &File, CompileUnit &Cu, unsigned Flags) { // LIFO work list. SmallVector Worklist; @@ -676,7 +674,7 @@ lookForChildDIEsToKeep(Current.Die, Current.CU, Current.Flags, Worklist); continue; case WorklistItemType::LookForRefDIEsToKeep: - lookForRefDIEsToKeep(Current.Die, Current.CU, Current.Flags, Units, OF, + lookForRefDIEsToKeep(Current.Die, Current.CU, Current.Flags, Units, File, Worklist); continue; case WorklistItemType::LookForParentDIEsToKeep: @@ -702,7 +700,7 @@ // We must not call shouldKeepDIE while called from keepDIEAndDependencies, // because it would screw up the relocation finding logic. if (!(Current.Flags & TF_DependencyWalk)) - Current.Flags = shouldKeepDIE(AddressesMap, Ranges, Current.Die, OF, + Current.Flags = shouldKeepDIE(AddressesMap, Ranges, Current.Die, File, Current.CU, MyInfo, Current.Flags); // Finish by looking for child DIEs. Because of the LIFO worklist we need @@ -792,7 +790,7 @@ unsigned DWARFLinker::DIECloner::cloneDieReferenceAttribute( DIE &Die, const DWARFDie &InputDIE, AttributeSpec AttrSpec, - unsigned AttrSize, const DWARFFormValue &Val, const DwarfLinkerObjFile &OF, + unsigned AttrSize, const DWARFFormValue &Val, const DwarfFile &File, CompileUnit &Unit) { const DWARFUnit &U = Unit.getOrigUnit(); uint64_t Ref = *Val.getAsReference(); @@ -802,7 +800,7 @@ DeclContext *Ctxt = nullptr; DWARFDie RefDie = - Linker.resolveDIEReference(OF, CompileUnits, Val, InputDIE, RefUnit); + Linker.resolveDIEReference(File, CompileUnits, Val, InputDIE, RefUnit); // If the referenced DIE is not found, drop the attribute. if (!RefDie || AttrSpec.Attr == dwarf::DW_AT_sibling) @@ -864,9 +862,8 @@ } void DWARFLinker::DIECloner::cloneExpression( - DataExtractor &Data, DWARFExpression Expression, - const DwarfLinkerObjFile &OF, CompileUnit &Unit, - SmallVectorImpl &OutputBuffer) { + DataExtractor &Data, DWARFExpression Expression, const DwarfFile &File, + CompileUnit &Unit, SmallVectorImpl &OutputBuffer) { using Encoding = DWARFExpression::Operation::Encoding; uint64_t OpOffset = 0; @@ -878,7 +875,7 @@ auto Op1 = Description.Op[1]; if ((Op0 == Encoding::BaseTypeRef && Op1 != Encoding::SizeNA) || (Op1 == Encoding::BaseTypeRef && Op0 != Encoding::Size1)) - Linker.reportWarning("Unsupported DW_OP encoding.", OF); + Linker.reportWarning("Unsupported DW_OP encoding.", File); if ((Op0 == Encoding::BaseTypeRef && Op1 == Encoding::SizeNA) || (Op1 == Encoding::BaseTypeRef && Op0 == Encoding::Size1)) { @@ -904,13 +901,13 @@ Offset = Clone->getOffset(); else Linker.reportWarning("base type ref doesn't point to DW_TAG_base_type.", - OF); + File); uint8_t ULEB[16]; unsigned RealSize = encodeULEB128(Offset, ULEB, ULEBsize); if (RealSize > ULEBsize) { // Emit the generic type as a fallback. RealSize = encodeULEB128(0, ULEB, ULEBsize); - Linker.reportWarning("base type ref doesn't fit.", OF); + Linker.reportWarning("base type ref doesn't fit.", File); } assert(RealSize == ULEBsize && "padding failed"); ArrayRef ULEBbytes(ULEB, ULEBsize); @@ -925,9 +922,8 @@ } unsigned DWARFLinker::DIECloner::cloneBlockAttribute( - DIE &Die, const DwarfLinkerObjFile &OF, CompileUnit &Unit, - AttributeSpec AttrSpec, const DWARFFormValue &Val, unsigned AttrSize, - bool IsLittleEndian) { + DIE &Die, const DwarfFile &File, CompileUnit &Unit, AttributeSpec AttrSpec, + const DWARFFormValue &Val, unsigned AttrSize, bool IsLittleEndian) { DIEValueList *Attr; DIEValue Value; DIELoc *Loc = nullptr; @@ -960,7 +956,7 @@ DataExtractor Data(StringRef((const char *)Bytes.data(), Bytes.size()), IsLittleEndian, OrigUnit.getAddressByteSize()); DWARFExpression Expr(Data, OrigUnit.getAddressByteSize()); - cloneExpression(Data, Expr, OF, Unit, Buffer); + cloneExpression(Data, Expr, File, Unit, Buffer); Bytes = Buffer; } for (auto Byte : Bytes) @@ -1033,7 +1029,7 @@ } unsigned DWARFLinker::DIECloner::cloneScalarAttribute( - DIE &Die, const DWARFDie &InputDIE, const DwarfLinkerObjFile &OF, + DIE &Die, const DWARFDie &InputDIE, const DwarfFile &File, CompileUnit &Unit, AttributeSpec AttrSpec, const DWARFFormValue &Val, unsigned AttrSize, AttributesInfo &Info) { uint64_t Value; @@ -1047,7 +1043,7 @@ Value = *OptionalValue; else { Linker.reportWarning( - "Unsupported scalar attribute form. Dropping attribute.", OF, + "Unsupported scalar attribute form. Dropping attribute.", File, &InputDIE); return 0; } @@ -1072,7 +1068,7 @@ Value = *OptionalValue; else { Linker.reportWarning( - "Unsupported scalar attribute form. Dropping attribute.", OF, + "Unsupported scalar attribute form. Dropping attribute.", File, &InputDIE); return 0; } @@ -1101,7 +1097,7 @@ /// value \p Val, and add it to \p Die. /// \returns the size of the cloned attribute. unsigned DWARFLinker::DIECloner::cloneAttribute( - DIE &Die, const DWARFDie &InputDIE, const DwarfLinkerObjFile &OF, + DIE &Die, const DWARFDie &InputDIE, const DwarfFile &File, CompileUnit &Unit, OffsetsStringPool &StringPool, const DWARFFormValue &Val, const AttributeSpec AttrSpec, unsigned AttrSize, AttributesInfo &Info, bool IsLittleEndian) { @@ -1117,13 +1113,13 @@ case dwarf::DW_FORM_ref4: case dwarf::DW_FORM_ref8: return cloneDieReferenceAttribute(Die, InputDIE, AttrSpec, AttrSize, Val, - OF, Unit); + File, Unit); case dwarf::DW_FORM_block: case dwarf::DW_FORM_block1: case dwarf::DW_FORM_block2: case dwarf::DW_FORM_block4: case dwarf::DW_FORM_exprloc: - return cloneBlockAttribute(Die, OF, Unit, AttrSpec, Val, AttrSize, + return cloneBlockAttribute(Die, File, Unit, AttrSpec, Val, AttrSize, IsLittleEndian); case dwarf::DW_FORM_addr: return cloneAddressAttribute(Die, AttrSpec, Val, Unit, Info); @@ -1136,11 +1132,11 @@ case dwarf::DW_FORM_sec_offset: case dwarf::DW_FORM_flag: case dwarf::DW_FORM_flag_present: - return cloneScalarAttribute(Die, InputDIE, OF, Unit, AttrSpec, Val, + return cloneScalarAttribute(Die, InputDIE, File, Unit, AttrSpec, Val, AttrSize, Info); default: Linker.reportWarning( - "Unsupported attribute form in cloneAttribute. Dropping.", OF, + "Unsupported attribute form in cloneAttribute. Dropping.", File, &InputDIE); } @@ -1218,10 +1214,12 @@ } } -DIE *DWARFLinker::DIECloner::cloneDIE( - const DWARFDie &InputDIE, const DwarfLinkerObjFile &OF, CompileUnit &Unit, - OffsetsStringPool &StringPool, int64_t PCOffset, uint32_t OutOffset, - unsigned Flags, bool IsLittleEndian, DIE *Die) { +DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE, + const DwarfFile &File, CompileUnit &Unit, + OffsetsStringPool &StringPool, + int64_t PCOffset, uint32_t OutOffset, + unsigned Flags, bool IsLittleEndian, + DIE *Die) { DWARFUnit &U = Unit.getOrigUnit(); unsigned Idx = U.getDIEIndex(InputDIE); CompileUnit::DIEInfo &Info = Unit.getInfo(Idx); @@ -1331,7 +1329,7 @@ Val.extractValue(Data, &Offset, U.getFormParams(), &U); AttrSize = Offset - AttrSize; - OutOffset += cloneAttribute(*Die, InputDIE, OF, Unit, StringPool, Val, + OutOffset += cloneAttribute(*Die, InputDIE, File, Unit, StringPool, Val, AttrSpec, AttrSize, AttrInfo, IsLittleEndian); } @@ -1365,7 +1363,7 @@ } else if (isTypeTag(Tag) && !AttrInfo.IsDeclaration && getDIENames(InputDIE, AttrInfo, StringPool) && AttrInfo.Name && AttrInfo.Name.getString()[0]) { - uint32_t Hash = hashFullyQualifiedName(InputDIE, Unit, OF); + uint32_t Hash = hashFullyQualifiedName(InputDIE, Unit, File); uint64_t RuntimeLang = dwarf::toUnsigned(InputDIE.find(dwarf::DW_AT_APPLE_runtime_class)) .getValueOr(0); @@ -1406,8 +1404,8 @@ // Recursively clone children. for (auto Child : InputDIE.children()) { - if (DIE *Clone = cloneDIE(Child, OF, Unit, StringPool, PCOffset, OutOffset, - Flags, IsLittleEndian)) { + if (DIE *Clone = cloneDIE(Child, File, Unit, StringPool, PCOffset, + OutOffset, Flags, IsLittleEndian)) { Die->addChild(Clone); OutOffset = Clone->getOffset() + Clone->getSize(); } @@ -1425,7 +1423,7 @@ /// to point at the new entries. void DWARFLinker::patchRangesForUnit(const CompileUnit &Unit, DWARFContext &OrigDwarf, - const DwarfLinkerObjFile &OF) const { + const DwarfFile &File) const { DWARFDebugRangeList RangeList; const auto &FunctionRanges = Unit.getFunctionRanges(); unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize(); @@ -1448,7 +1446,7 @@ RangeAttribute.set(TheDwarfEmitter->getRangesSectionSize()); if (Error E = RangeList.extract(RangeExtractor, &Offset)) { llvm::consumeError(std::move(E)); - reportWarning("invalid range list ignored.", OF); + reportWarning("invalid range list ignored.", File); RangeList.clear(); } const auto &Entries = RangeList.getEntries(); @@ -1461,7 +1459,7 @@ CurrRange = FunctionRanges.find(First.StartAddress + OrigLowPc); if (CurrRange == InvalidRange || CurrRange.start() > First.StartAddress + OrigLowPc) { - reportWarning("no mapping for range.", OF); + reportWarning("no mapping for range.", File); continue; } } @@ -1532,7 +1530,7 @@ /// are present in the binary. void DWARFLinker::patchLineTableForUnit(CompileUnit &Unit, DWARFContext &OrigDwarf, - const DwarfLinkerObjFile &OF) { + const DwarfFile &File) { DWARFDie CUDie = Unit.getOrigUnit().getUnitDIE(); auto StmtList = dwarf::toSectionOffset(CUDie.find(dwarf::DW_AT_stmt_list)); if (!StmtList) @@ -1543,7 +1541,7 @@ patchStmtList(*OutputDIE, DIEInteger(TheDwarfEmitter->getLineSectionSize())); - RangesTy &Ranges = OF.Addresses->getValidAddressRanges(); + RangesTy &Ranges = File.Addresses->getValidAddressRanges(); // Parse the original line info for the unit. DWARFDebugLine::LineTable LineTable; @@ -1654,7 +1652,7 @@ LineTable.Prologue.getVersion() > 5 || LineTable.Prologue.DefaultIsStmt != DWARF2_LINE_DEFAULT_IS_STMT || LineTable.Prologue.OpcodeBase > 13) - reportWarning("line table parameters mismatch. Cannot emit.", OF); + reportWarning("line table parameters mismatch. Cannot emit.", File); else { uint32_t PrologueEnd = *StmtList + 10 + LineTable.Prologue.PrologueLength; // DWARF v5 has an extra 2 bytes of information before the header_length @@ -1732,7 +1730,7 @@ /// This is actually pretty easy as the data of the CIEs and FDEs can /// be considered as black boxes and moved as is. The only thing to do /// is to patch the addresses in the headers. -void DWARFLinker::patchFrameInfoForObject(const DwarfLinkerObjFile &OF, +void DWARFLinker::patchFrameInfoForObject(const DwarfFile &File, RangesTy &Ranges, DWARFContext &OrigDwarf, unsigned AddrSize) { @@ -1751,7 +1749,7 @@ uint64_t EntryOffset = InputOffset; uint32_t InitialLength = Data.getU32(&InputOffset); if (InitialLength == 0xFFFFFFFF) - return reportWarning("Dwarf64 bits no supported", OF); + return reportWarning("Dwarf64 bits no supported", File); uint32_t CIEId = Data.getU32(&InputOffset); if (CIEId == 0xFFFFFFFF) { @@ -1783,7 +1781,7 @@ // Have we already emitted a corresponding CIE? StringRef CIEData = LocalCIES[CIEId]; if (CIEData.empty()) - return reportWarning("Inconsistent debug_frame content. Dropping.", OF); + return reportWarning("Inconsistent debug_frame content. Dropping.", File); // Look if we already emitted a CIE that corresponds to the // referenced one (the CIE data is the key of that lookup). @@ -1827,10 +1825,10 @@ Linker.assignAbbrev(Copy); } -uint32_t -DWARFLinker::DIECloner::hashFullyQualifiedName(DWARFDie DIE, CompileUnit &U, - const DwarfLinkerObjFile &OF, - int ChildRecurseDepth) { +uint32_t DWARFLinker::DIECloner::hashFullyQualifiedName(DWARFDie DIE, + CompileUnit &U, + const DwarfFile &File, + int ChildRecurseDepth) { const char *Name = nullptr; DWARFUnit *OrigUnit = &U.getOrigUnit(); CompileUnit *CU = &U; @@ -1849,7 +1847,7 @@ CompileUnit *RefCU; if (auto RefDIE = - Linker.resolveDIEReference(OF, CompileUnits, *Ref, DIE, RefCU)) { + Linker.resolveDIEReference(File, CompileUnits, *Ref, DIE, RefCU)) { CU = RefCU; OrigUnit = &RefCU->getOrigUnit(); DIE = RefDIE; @@ -1870,7 +1868,7 @@ return djbHash( (Name ? Name : ""), djbHash((Name ? "::" : ""), - hashFullyQualifiedName(Die, *CU, OF, ++ChildRecurseDepth))); + hashFullyQualifiedName(Die, *CU, File, ++ChildRecurseDepth))); } static uint64_t getDwoId(const DWARFDie &CUDie, const DWARFUnit &Unit) { @@ -1882,7 +1880,7 @@ } bool DWARFLinker::registerModuleReference( - DWARFDie CUDie, const DWARFUnit &Unit, const DwarfLinkerObjFile &OF, + DWARFDie CUDie, const DWARFUnit &Unit, const DwarfFile &File, OffsetsStringPool &StringPool, UniquingStringPool &UniquingStringPool, DeclContextTree &ODRContexts, uint64_t ModulesEndOffset, unsigned &UnitID, bool IsLittleEndian, unsigned Indent, bool Quiet) { @@ -1897,7 +1895,7 @@ std::string Name = dwarf::toString(CUDie.find(dwarf::DW_AT_name), ""); if (Name.empty()) { if (!Quiet) - reportWarning("Anonymous module skeleton CU for " + PCMfile, OF); + reportWarning("Anonymous module skeleton CU for " + PCMfile, File); return true; } @@ -1915,7 +1913,7 @@ reportWarning(Twine("hash mismatch: this object file was built against a " "different version of the module ") + PCMfile, - OF); + File); if (!Quiet && Options.Verbose) outs() << " [cached].\n"; return true; @@ -1928,7 +1926,7 @@ ClangModules.insert({PCMfile, DwoId}); if (Error E = - loadClangModule(CUDie, PCMfile, Name, DwoId, OF, StringPool, + loadClangModule(CUDie, PCMfile, Name, DwoId, File, StringPool, UniquingStringPool, ODRContexts, ModulesEndOffset, UnitID, IsLittleEndian, Indent + 2, Quiet)) { consumeError(std::move(E)); @@ -1939,7 +1937,7 @@ Error DWARFLinker::loadClangModule( DWARFDie CUDie, StringRef Filename, StringRef ModuleName, uint64_t DwoId, - const DwarfLinkerObjFile &OF, OffsetsStringPool &StringPool, + const DwarfFile &File, OffsetsStringPool &StringPool, UniquingStringPool &UniquingStringPool, DeclContextTree &ODRContexts, uint64_t ModulesEndOffset, unsigned &UnitID, bool IsLittleEndian, unsigned Indent, bool Quiet) { @@ -1954,30 +1952,27 @@ if (Options.ObjFileLoader == nullptr) return Error::success(); - auto ErrOrObj = Options.ObjFileLoader(OF.FileName, Path); + auto ErrOrObj = Options.ObjFileLoader(File.FileName, Path); if (!ErrOrObj) return Error::success(); std::unique_ptr Unit; - // Setup access to the debug info. - auto DwarfContext = DWARFContext::create(*ErrOrObj->ObjFile); - - for (const auto &CU : DwarfContext->compile_units()) { + for (const auto &CU : ErrOrObj->Dwarf->compile_units()) { updateDwarfVersion(CU->getVersion()); // Recursively get all modules imported by this one. auto CUDie = CU->getUnitDIE(false); if (!CUDie) continue; - if (!registerModuleReference(CUDie, *CU, OF, StringPool, UniquingStringPool, - ODRContexts, ModulesEndOffset, UnitID, - IsLittleEndian, Indent, Quiet)) { + if (!registerModuleReference( + CUDie, *CU, File, StringPool, UniquingStringPool, ODRContexts, + ModulesEndOffset, UnitID, IsLittleEndian, Indent, Quiet)) { if (Unit) { std::string Err = (Filename + ": Clang modules are expected to have exactly 1 compile unit.\n") .str(); - reportError(Err, OF); + reportError(Err, File); return make_error(Err, inconvertibleErrorCode()); } // FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is @@ -1990,7 +1985,7 @@ Twine("hash mismatch: this object file was built against a " "different version of the module ") + Filename, - OF); + File); // Update the cache entry with the DwoId of the module loaded from disk. ClangModules[Filename] = PCMDwoId; } @@ -2003,7 +1998,7 @@ UniquingStringPool, ODRContexts, ModulesEndOffset, Options.ParseableSwiftInterfaces, [&](const Twine &Warning, const DWARFDie &DIE) { - reportWarning(Warning, OF, &DIE); + reportWarning(Warning, File, &DIE); }); // Keep everything. Unit->markEverythingAsKept(); @@ -2021,12 +2016,13 @@ assert(TheDwarfEmitter); DIECloner(*this, TheDwarfEmitter, *ErrOrObj, DIEAlloc, CompileUnits, Options.Update) - .cloneAllCompileUnits(*DwarfContext, OF, StringPool, IsLittleEndian); + .cloneAllCompileUnits(*(ErrOrObj->Dwarf), File, StringPool, + IsLittleEndian); return Error::success(); } void DWARFLinker::DIECloner::cloneAllCompileUnits(DWARFContext &DwarfContext, - const DwarfLinkerObjFile &OF, + const DwarfFile &File, OffsetsStringPool &StringPool, bool IsLittleEndian) { uint64_t OutputDebugInfoSize = @@ -2042,7 +2038,7 @@ // Clone the InputDIE into your Unit DIE in our compile unit since it // already has a DIE inside of it. CurrentUnit->createOutputDIE(); - cloneDIE(InputDIE, OF, *CurrentUnit, StringPool, 0 /* PC offset */, + cloneDIE(InputDIE, File, *CurrentUnit, StringPool, 0 /* PC offset */, 11 /* Unit Header size */, 0, IsLittleEndian, CurrentUnit->getOutputUnitDIE()); } @@ -2054,14 +2050,14 @@ if (LLVM_LIKELY(!Linker.Options.Update) || Linker.needToTranslateStrings()) - Linker.patchLineTableForUnit(*CurrentUnit, DwarfContext, OF); + Linker.patchLineTableForUnit(*CurrentUnit, DwarfContext, File); Linker.emitAcceleratorEntriesForUnit(*CurrentUnit); if (LLVM_UNLIKELY(Linker.Options.Update)) continue; - Linker.patchRangesForUnit(*CurrentUnit, DwarfContext, OF); + Linker.patchRangesForUnit(*CurrentUnit, DwarfContext, File); auto ProcessExpr = [&](StringRef Bytes, SmallVectorImpl &Buffer) { DWARFUnit &OrigUnit = CurrentUnit->getOrigUnit(); @@ -2069,7 +2065,7 @@ OrigUnit.getAddressByteSize()); cloneExpression(Data, DWARFExpression(Data, OrigUnit.getAddressByteSize()), - OF, *CurrentUnit, Buffer); + File, *CurrentUnit, Buffer); }; Emitter->emitLocationsForUnit(*CurrentUnit, DwarfContext, ProcessExpr); } @@ -2116,11 +2112,10 @@ } } -bool DWARFLinker::emitPaperTrailWarnings(const DwarfLinkerObjFile &OF, +bool DWARFLinker::emitPaperTrailWarnings(const DwarfFile &File, OffsetsStringPool &StringPool) { - if (OF.Warnings.empty() || (OF.ObjFile && (OF.ObjFile->symbols().begin() != - OF.ObjFile->symbols().end()))) + if (File.Warnings.empty()) return false; DIE *CUDie = DIE::get(DIEAlloc, dwarf::DW_TAG_compile_unit); @@ -2140,19 +2135,19 @@ break; } - StringRef File = StringPool.internString(OF.FileName); + StringRef FileName = StringPool.internString(File.FileName); CUDie->addValue(DIEAlloc, dwarf::DW_AT_producer, dwarf::DW_FORM_strp, DIEInteger(StringPool.getStringOffset(Producer))); DIEBlock *String = new (DIEAlloc) DIEBlock(); DIEBlocks.push_back(String); - for (auto &C : File) + for (auto &C : FileName) String->addValue(DIEAlloc, dwarf::Attribute(0), dwarf::DW_FORM_data1, DIEInteger(C)); String->addValue(DIEAlloc, dwarf::Attribute(0), dwarf::DW_FORM_data1, DIEInteger(0)); CUDie->addValue(DIEAlloc, dwarf::DW_AT_name, dwarf::DW_FORM_string, String); - for (const auto &Warning : OF.Warnings) { + for (const auto &Warning : File.Warnings) { DIE &ConstDie = CUDie->addChild(DIE::get(DIEAlloc, dwarf::DW_TAG_constant)); ConstDie.addValue(DIEAlloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp, DIEInteger(StringPool.getStringOffset(WarningHeader))); @@ -2161,8 +2156,8 @@ ConstDie.addValue(DIEAlloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_strp, DIEInteger(StringPool.getStringOffset(Warning))); } - unsigned Size = 4 /* FORM_strp */ + File.size() + 1 + - OF.Warnings.size() * (4 + 1 + 4) + 1 /* End of children */; + unsigned Size = 4 /* FORM_strp */ + FileName.size() + 1 + + File.Warnings.size() * (4 + 1 + 4) + 1 /* End of children */; DIEAbbrev Abbrev = CUDie->generateAbbrev(); assignAbbrev(Abbrev); CUDie->setAbbrevNumber(Abbrev.getNumber()); @@ -2180,20 +2175,25 @@ return true; } -void DWARFLinker::copyInvariantDebugSection(const object::ObjectFile &Obj) { +void DWARFLinker::copyInvariantDebugSection(DWARFContext &Dwarf) { if (!needToTranslateStrings()) - TheDwarfEmitter->emitSectionContents(Obj, "debug_line"); - TheDwarfEmitter->emitSectionContents(Obj, "debug_loc"); - TheDwarfEmitter->emitSectionContents(Obj, "debug_ranges"); - TheDwarfEmitter->emitSectionContents(Obj, "debug_frame"); - TheDwarfEmitter->emitSectionContents(Obj, "debug_aranges"); + TheDwarfEmitter->emitSectionContents( + Dwarf.getDWARFObj().getLineSection().Data, "debug_line"); + TheDwarfEmitter->emitSectionContents(Dwarf.getDWARFObj().getLocSection().Data, + "debug_loc"); + TheDwarfEmitter->emitSectionContents( + Dwarf.getDWARFObj().getRangesSection().Data, "debug_ranges"); + TheDwarfEmitter->emitSectionContents( + Dwarf.getDWARFObj().getFrameSection().Data, "debug_frame"); + TheDwarfEmitter->emitSectionContents(Dwarf.getDWARFObj().getArangesSection(), + "debug_aranges"); } -void DWARFLinker::addObjectFile(DwarfLinkerObjFile &ObjFile) { - ObjectContexts.emplace_back(LinkContext(ObjFile)); +void DWARFLinker::addObjectFile(DwarfFile &File) { + ObjectContexts.emplace_back(LinkContext(File)); - if (ObjectContexts.back().DwarfContext) - updateAccelKind(*ObjectContexts.back().DwarfContext); + if (ObjectContexts.back().File.Dwarf) + updateAccelKind(*ObjectContexts.back().File.Dwarf); } bool DWARFLinker::link() { @@ -2234,23 +2234,22 @@ for (LinkContext &OptContext : ObjectContexts) { if (Options.Verbose) { if (DwarfLinkerClientID == DwarfLinkerClient::Dsymutil) - outs() << "DEBUG MAP OBJECT: " << OptContext.ObjectFile.FileName - << "\n"; + outs() << "DEBUG MAP OBJECT: " << OptContext.File.FileName << "\n"; else - outs() << "OBJECT FILE: " << OptContext.ObjectFile.FileName << "\n"; + outs() << "OBJECT FILE: " << OptContext.File.FileName << "\n"; } - if (emitPaperTrailWarnings(OptContext.ObjectFile, OffsetsStringPool)) + if (emitPaperTrailWarnings(OptContext.File, OffsetsStringPool)) continue; - if (!OptContext.ObjectFile.ObjFile) + if (!OptContext.File.Dwarf) continue; // Look for relocations that correspond to address map entries. // there was findvalidrelocations previously ... probably we need to gather // info here if (LLVM_LIKELY(!Options.Update) && - !OptContext.ObjectFile.Addresses->hasValidRelocs()) { + !OptContext.File.Addresses->hasValidRelocs()) { if (Options.Verbose) outs() << "No valid relocations found. Skipping.\n"; @@ -2261,14 +2260,14 @@ } // Setup access to the debug info. - if (!OptContext.DwarfContext) + if (!OptContext.File.Dwarf) continue; // In a first phase, just read in the debug info and load all clang modules. OptContext.CompileUnits.reserve( - OptContext.DwarfContext->getNumCompileUnits()); + OptContext.File.Dwarf->getNumCompileUnits()); - for (const auto &CU : OptContext.DwarfContext->compile_units()) { + for (const auto &CU : OptContext.File.Dwarf->compile_units()) { updateDwarfVersion(CU->getVersion()); auto CUDie = CU->getUnitDIE(false); if (Options.Verbose) { @@ -2279,10 +2278,9 @@ CUDie.dump(outs(), 0, DumpOpts); } if (CUDie && !LLVM_UNLIKELY(Options.Update)) - registerModuleReference(CUDie, *CU, OptContext.ObjectFile, - OffsetsStringPool, UniquingStringPool, - ODRContexts, 0, UnitID, - OptContext.DwarfContext->isLittleEndian()); + registerModuleReference(CUDie, *CU, OptContext.File, OffsetsStringPool, + UniquingStringPool, ODRContexts, 0, UnitID, + OptContext.File.Dwarf->isLittleEndian()); } } @@ -2309,10 +2307,10 @@ auto AnalyzeLambda = [&](size_t I) { auto &Context = ObjectContexts[I]; - if (Context.Skip || !Context.DwarfContext) + if (Context.Skip || !Context.File.Dwarf) return; - for (const auto &CU : Context.DwarfContext->compile_units()) { + for (const auto &CU : Context.File.Dwarf->compile_units()) { updateDwarfVersion(CU->getVersion()); // The !registerModuleReference() condition effectively skips // over fully resolved skeleton units. This second pass of @@ -2322,10 +2320,9 @@ bool Quiet = true; auto CUDie = CU->getUnitDIE(false); if (!CUDie || LLVM_UNLIKELY(Options.Update) || - !registerModuleReference(CUDie, *CU, Context.ObjectFile, - OffsetsStringPool, UniquingStringPool, - ODRContexts, ModulesEndOffset, UnitID, - Quiet)) { + !registerModuleReference(CUDie, *CU, Context.File, OffsetsStringPool, + UniquingStringPool, ODRContexts, + ModulesEndOffset, UnitID, Quiet)) { Context.CompileUnits.push_back(std::make_unique( *CU, UnitID++, !Options.NoODR && !Options.Update, "")); } @@ -2341,7 +2338,7 @@ UniquingStringPool, ODRContexts, ModulesEndOffset, Options.ParseableSwiftInterfaces, [&](const Twine &Warning, const DWARFDie &DIE) { - reportWarning(Warning, Context.ObjectFile, &DIE); + reportWarning(Warning, Context.File, &DIE); }); } }; @@ -2352,7 +2349,7 @@ // than those processed by analyzeContextInfo. auto CloneLambda = [&](size_t I) { auto &OptContext = ObjectContexts[I]; - if (OptContext.Skip || !OptContext.ObjectFile.ObjFile) + if (OptContext.Skip || !OptContext.File.Dwarf) return; // Then mark all the DIEs that need to be present in the generated output @@ -2363,33 +2360,32 @@ if (LLVM_UNLIKELY(Options.Update)) { for (auto &CurrentUnit : OptContext.CompileUnits) CurrentUnit->markEverythingAsKept(); - copyInvariantDebugSection(*OptContext.ObjectFile.ObjFile); + copyInvariantDebugSection(*OptContext.File.Dwarf); } else { for (auto &CurrentUnit : OptContext.CompileUnits) - lookForDIEsToKeep( - *OptContext.ObjectFile.Addresses, - OptContext.ObjectFile.Addresses->getValidAddressRanges(), - OptContext.CompileUnits, CurrentUnit->getOrigUnit().getUnitDIE(), - OptContext.ObjectFile, *CurrentUnit, 0); + lookForDIEsToKeep(*OptContext.File.Addresses, + OptContext.File.Addresses->getValidAddressRanges(), + OptContext.CompileUnits, + CurrentUnit->getOrigUnit().getUnitDIE(), + OptContext.File, *CurrentUnit, 0); } // The calls to applyValidRelocs inside cloneDIE will walk the reloc // array again (in the same way findValidRelocsInDebugInfo() did). We // need to reset the NextValidReloc index to the beginning. - if (OptContext.ObjectFile.Addresses->hasValidRelocs() || + if (OptContext.File.Addresses->hasValidRelocs() || LLVM_UNLIKELY(Options.Update)) { - DIECloner(*this, TheDwarfEmitter, OptContext.ObjectFile, DIEAlloc, + DIECloner(*this, TheDwarfEmitter, OptContext.File, DIEAlloc, OptContext.CompileUnits, Options.Update) - .cloneAllCompileUnits(*OptContext.DwarfContext, OptContext.ObjectFile, + .cloneAllCompileUnits(*OptContext.File.Dwarf, OptContext.File, OffsetsStringPool, - OptContext.DwarfContext->isLittleEndian()); + OptContext.File.Dwarf->isLittleEndian()); } if (!Options.NoOutput && !OptContext.CompileUnits.empty() && LLVM_LIKELY(!Options.Update)) patchFrameInfoForObject( - OptContext.ObjectFile, - OptContext.ObjectFile.Addresses->getValidAddressRanges(), - *OptContext.DwarfContext, + OptContext.File, OptContext.File.Addresses->getValidAddressRanges(), + *OptContext.File.Dwarf, OptContext.CompileUnits[0]->getOrigUnit().getAddressByteSize()); // Clean-up before starting working on the next object. diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.h b/llvm/tools/dsymutil/DwarfLinkerForBinary.h --- a/llvm/tools/dsymutil/DwarfLinkerForBinary.h +++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.h @@ -167,15 +167,18 @@ /// Attempt to load a debug object from disk. ErrorOr loadObject(const DebugMapObject &Obj, const Triple &triple); - ErrorOr loadObject(const DebugMapObject &Obj, - const DebugMap &DebugMap, - remarks::RemarkLinker &RL); + ErrorOr loadObject(const DebugMapObject &Obj, + const DebugMap &DebugMap, + remarks::RemarkLinker &RL); raw_fd_ostream &OutFile; BinaryHolder &BinHolder; LinkOptions Options; std::unique_ptr Streamer; - std::vector> ObjectsForLinking; + std::vector> ObjectsForLinking; + std::vector> ContextForLinking; + std::vector> AddressMapForLinking; + std::vector EmptyWarnings; /// A list of all .swiftinterface files referenced by the debug /// info, mapping Module name to path on disk. The entries need to diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp --- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp +++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp @@ -252,21 +252,24 @@ return Error::success(); } -ErrorOr +ErrorOr DwarfLinkerForBinary::loadObject(const DebugMapObject &Obj, const DebugMap &DebugMap, remarks::RemarkLinker &RL) { auto ErrorOrObj = loadObject(Obj, DebugMap.getTriple()); if (ErrorOrObj) { - ObjectsForLinking.push_back( - std::unique_ptr(new DwarfLinkerObjFile( - Obj.getObjectFilename(), &*ErrorOrObj, Obj.getWarnings()))); + ContextForLinking.push_back( + std::unique_ptr(DWARFContext::create(*ErrorOrObj))); + AddressMapForLinking.push_back( + std::make_unique(*this, *ErrorOrObj, Obj)); - ObjectsForLinking.back()->Addresses.reset( - new AddressManager(*this, *ErrorOrObj, Obj)); + ObjectsForLinking.push_back(std::make_unique( + Obj.getObjectFilename(), ContextForLinking.back().get(), + AddressMapForLinking.back().get(), + Obj.empty() ? Obj.getWarnings() : EmptyWarnings)); - Error E = RL.link(*ObjectsForLinking.back()->ObjFile); + Error E = RL.link(*ErrorOrObj); if (Error NewE = handleErrors( std::move(E), [&](std::unique_ptr EC) -> Error { return remarksErrorHandler(Obj, *this, std::move(EC)); @@ -284,6 +287,8 @@ return false; ObjectsForLinking.clear(); + ContextForLinking.clear(); + AddressMapForLinking.clear(); DebugMap DebugMap(Map.getTriple(), Map.getBinaryPath()); @@ -317,7 +322,7 @@ }); GeneralLinker.setObjFileLoader( [&DebugMap, &RL, this](StringRef ContainerName, - StringRef Path) -> ErrorOr { + StringRef Path) -> ErrorOr { auto &Obj = DebugMap.addDebugMapObject( Path, sys::TimePoint(), MachO::N_OSO); @@ -412,9 +417,9 @@ if (auto ErrorOrObj = loadObject(*Obj, Map, RL)) GeneralLinker.addObjectFile(*ErrorOrObj); else { - ObjectsForLinking.push_back( - std::unique_ptr(new DwarfLinkerObjFile( - Obj->getObjectFilename(), nullptr, Obj->getWarnings()))); + ObjectsForLinking.push_back(std::make_unique( + Obj->getObjectFilename(), nullptr, nullptr, + Obj->empty() ? Obj->getWarnings() : EmptyWarnings)); GeneralLinker.addObjectFile(*ObjectsForLinking.back()); } } diff --git a/llvm/tools/dsymutil/DwarfStreamer.h b/llvm/tools/dsymutil/DwarfStreamer.h --- a/llvm/tools/dsymutil/DwarfStreamer.h +++ b/llvm/tools/dsymutil/DwarfStreamer.h @@ -76,8 +76,7 @@ void emitPaperTrailWarningsDie(DIE &Die) override; /// Emit contents of section SecName From Obj. - void emitSectionContents(const object::ObjectFile &Obj, - StringRef SecName) override; + void emitSectionContents(StringRef SecData, StringRef SecName) override; /// Emit the string table described by \p Pool. void emitStrings(const NonRelocatableStringpool &Pool) override; @@ -118,9 +117,6 @@ /// file names and directories. void translateLineTable(DataExtractor LineData, uint64_t Offset) override; - /// Copy over the debug sections that are not modified when updating. - void copyInvariantDebugSection(const object::ObjectFile &Obj); - uint64_t getLineSectionSize() const override { return LineSectionSize; } /// Emit the .debug_pubnames contribution for \p Unit. diff --git a/llvm/tools/dsymutil/DwarfStreamer.cpp b/llvm/tools/dsymutil/DwarfStreamer.cpp --- a/llvm/tools/dsymutil/DwarfStreamer.cpp +++ b/llvm/tools/dsymutil/DwarfStreamer.cpp @@ -194,8 +194,7 @@ } /// Emit contents of section SecName From Obj. -void DwarfStreamer::emitSectionContents(const object::ObjectFile &Obj, - StringRef SecName) { +void DwarfStreamer::emitSectionContents(StringRef SecData, StringRef SecName) { MCSection *Section = StringSwitch(SecName) .Case("debug_line", MC->getObjectFileInfo()->getDwarfLineSection()) @@ -210,12 +209,7 @@ if (Section) { MS->SwitchSection(Section); - if (auto Sec = getSectionByName(Obj, SecName)) { - if (Expected E = Sec->getContents()) - MS->emitBytes(*E); - else - consumeError(E.takeError()); - } + MS->emitBytes(SecData); } } @@ -721,25 +715,6 @@ Offset = UnitEnd; } -void DwarfStreamer::copyInvariantDebugSection(const object::ObjectFile &Obj) { - if (!Options.Translator) { - MS->SwitchSection(MC->getObjectFileInfo()->getDwarfLineSection()); - emitSectionContents(Obj, "debug_line"); - } - - MS->SwitchSection(MC->getObjectFileInfo()->getDwarfLocSection()); - emitSectionContents(Obj, "debug_loc"); - - MS->SwitchSection(MC->getObjectFileInfo()->getDwarfRangesSection()); - emitSectionContents(Obj, "debug_ranges"); - - MS->SwitchSection(MC->getObjectFileInfo()->getDwarfFrameSection()); - emitSectionContents(Obj, "debug_frame"); - - MS->SwitchSection(MC->getObjectFileInfo()->getDwarfARangesSection()); - emitSectionContents(Obj, "debug_aranges"); -} - /// Emit the pubnames or pubtypes section contribution for \p /// Unit into \p Sec. The data is provided in \p Names. void DwarfStreamer::emitPubSectionForUnit(