1 //===- tools/dsymutil/DwarfLinker.cpp - Dwarf debug info linker -----------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "BinaryHolder.h"
13 #include "llvm/CodeGen/AsmPrinter.h"
14 #include "llvm/CodeGen/DIE.h"
15 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
17 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
18 #include "llvm/MC/MCAsmBackend.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCCodeEmitter.h"
22 #include "llvm/MC/MCInstrInfo.h"
23 #include "llvm/MC/MCObjectFileInfo.h"
24 #include "llvm/MC/MCRegisterInfo.h"
25 #include "llvm/MC/MCStreamer.h"
26 #include "llvm/Object/MachO.h"
27 #include "llvm/Support/Dwarf.h"
28 #include "llvm/Support/LEB128.h"
29 #include "llvm/Support/TargetRegistry.h"
30 #include "llvm/Target/TargetMachine.h"
31 #include "llvm/Target/TargetOptions.h"
39 void warn(const Twine &Warning, const Twine &Context) {
40 errs() << Twine("while processing ") + Context + ":\n";
41 errs() << Twine("warning: ") + Warning + "\n";
44 bool error(const Twine &Error, const Twine &Context) {
45 errs() << Twine("while processing ") + Context + ":\n";
46 errs() << Twine("error: ") + Error + "\n";
50 /// \brief Stores all information relating to a compile unit, be it in
51 /// its original instance in the object file to its brand new cloned
52 /// and linked DIE tree.
55 /// \brief Information gathered about a DIE in the object file.
57 uint64_t Address; ///< Linked address of the described entity.
58 uint32_t ParentIdx; ///< The index of this DIE's parent.
59 bool Keep; ///< Is the DIE part of the linked output?
60 bool InDebugMap; ///< Was this DIE's entity found in the map?
63 CompileUnit(DWARFUnit &OrigUnit) : OrigUnit(OrigUnit) {
64 Info.resize(OrigUnit.getNumDIEs());
67 // Workaround MSVC not supporting implicit move ops
68 CompileUnit(CompileUnit &&RHS) = default;
70 DWARFUnit &getOrigUnit() const { return OrigUnit; }
72 DIE *getOutputUnitDIE() const { return CUDie.get(); }
73 void setOutputUnitDIE(DIE *Die) { CUDie.reset(Die); }
75 DIEInfo &getInfo(unsigned Idx) { return Info[Idx]; }
76 const DIEInfo &getInfo(unsigned Idx) const { return Info[Idx]; }
78 uint64_t getStartOffset() const { return StartOffset; }
79 uint64_t getNextUnitOffset() const { return NextUnitOffset; }
81 /// \brief Set the start and end offsets for this unit. Must be
82 /// called after the CU's DIEs have been cloned. The unit start
83 /// offset will be set to \p DebugInfoSize.
84 /// \returns the next unit offset (which is also the current
85 /// debug_info section size).
86 uint64_t computeOffsets(uint64_t DebugInfoSize);
90 std::vector<DIEInfo> Info; ///< DIE info indexed by DIE index.
91 std::unique_ptr<DIE> CUDie; ///< Root of the linked DIE tree.
94 uint64_t NextUnitOffset;
97 uint64_t CompileUnit::computeOffsets(uint64_t DebugInfoSize) {
98 StartOffset = DebugInfoSize;
99 NextUnitOffset = StartOffset + 11 /* Header size */;
100 // The root DIE might be null, meaning that the Unit had nothing to
101 // contribute to the linked output. In that case, we will emit the
102 // unit header without any actual DIE.
104 NextUnitOffset += CUDie->getSize();
105 return NextUnitOffset;
108 /// \brief The Dwarf streaming logic
110 /// All interactions with the MC layer that is used to build the debug
111 /// information binary representation are handled in this class.
112 class DwarfStreamer {
113 /// \defgroup MCObjects MC layer objects constructed by the streamer
115 std::unique_ptr<MCRegisterInfo> MRI;
116 std::unique_ptr<MCAsmInfo> MAI;
117 std::unique_ptr<MCObjectFileInfo> MOFI;
118 std::unique_ptr<MCContext> MC;
119 MCAsmBackend *MAB; // Owned by MCStreamer
120 std::unique_ptr<MCInstrInfo> MII;
121 std::unique_ptr<MCSubtargetInfo> MSTI;
122 MCCodeEmitter *MCE; // Owned by MCStreamer
123 MCStreamer *MS; // Owned by AsmPrinter
124 std::unique_ptr<TargetMachine> TM;
125 std::unique_ptr<AsmPrinter> Asm;
128 /// \brief the file we stream the linked Dwarf to.
129 std::unique_ptr<raw_fd_ostream> OutFile;
132 /// \brief Actually create the streamer and the ouptut file.
134 /// This could be done directly in the constructor, but it feels
135 /// more natural to handle errors through return value.
136 bool init(Triple TheTriple, StringRef OutputFilename);
138 /// \brief Dump the file to the disk.
141 AsmPrinter &getAsmPrinter() const { return *Asm; }
143 /// \brief Set the current output section to debug_info and change
144 /// the MC Dwarf version to \p DwarfVersion.
145 void switchToDebugInfoSection(unsigned DwarfVersion);
147 /// \brief Emit the compilation unit header for \p Unit in the
148 /// debug_info section.
150 /// As a side effect, this also switches the current Dwarf version
151 /// of the MC layer to the one of U.getOrigUnit().
152 void emitCompileUnitHeader(CompileUnit &Unit);
154 /// \brief Recursively emit the DIE tree rooted at \p Die.
155 void emitDIE(DIE &Die);
157 /// \brief Emit the abbreviation table \p Abbrevs to the
158 /// debug_abbrev section.
159 void emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs);
162 bool DwarfStreamer::init(Triple TheTriple, StringRef OutputFilename) {
163 std::string ErrorStr;
164 std::string TripleName;
165 StringRef Context = "dwarf streamer init";
168 const Target *TheTarget =
169 TargetRegistry::lookupTarget(TripleName, TheTriple, ErrorStr);
171 return error(ErrorStr, Context);
172 TripleName = TheTriple.getTriple();
174 // Create all the MC Objects.
175 MRI.reset(TheTarget->createMCRegInfo(TripleName));
177 return error(Twine("no register info for target ") + TripleName, Context);
179 MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName));
181 return error("no asm info for target " + TripleName, Context);
183 MOFI.reset(new MCObjectFileInfo);
184 MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
185 MOFI->InitMCObjectFileInfo(TripleName, Reloc::Default, CodeModel::Default,
188 MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "");
190 return error("no asm backend for target " + TripleName, Context);
192 MII.reset(TheTarget->createMCInstrInfo());
194 return error("no instr info info for target " + TripleName, Context);
196 MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
198 return error("no subtarget info for target " + TripleName, Context);
200 MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MSTI, *MC);
202 return error("no code emitter for target " + TripleName, Context);
204 // Create the output file.
207 llvm::make_unique<raw_fd_ostream>(OutputFilename, EC, sys::fs::F_None);
209 return error(Twine(OutputFilename) + ": " + EC.message(), Context);
211 MS = TheTarget->createMCObjectStreamer(TripleName, *MC, *MAB, *OutFile, MCE,
214 return error("no object streamer for target " + TripleName, Context);
216 // Finally create the AsmPrinter we'll use to emit the DIEs.
217 TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions()));
219 return error("no target machine for target " + TripleName, Context);
221 Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr<MCStreamer>(MS)));
223 return error("no asm printer for target " + TripleName, Context);
228 bool DwarfStreamer::finish() {
233 /// \brief Set the current output section to debug_info and change
234 /// the MC Dwarf version to \p DwarfVersion.
235 void DwarfStreamer::switchToDebugInfoSection(unsigned DwarfVersion) {
236 MS->SwitchSection(MOFI->getDwarfInfoSection());
237 MC->setDwarfVersion(DwarfVersion);
240 /// \brief Emit the compilation unit header for \p Unit in the
241 /// debug_info section.
243 /// A Dwarf scetion header is encoded as:
244 /// uint32_t Unit length (omiting this field)
246 /// uint32_t Abbreviation table offset
247 /// uint8_t Address size
249 /// Leading to a total of 11 bytes.
250 void DwarfStreamer::emitCompileUnitHeader(CompileUnit &Unit) {
251 unsigned Version = Unit.getOrigUnit().getVersion();
252 switchToDebugInfoSection(Version);
254 // Emit size of content not including length itself. The size has
255 // already been computed in CompileUnit::computeOffsets(). Substract
256 // 4 to that size to account for the length field.
257 Asm->EmitInt32(Unit.getNextUnitOffset() - Unit.getStartOffset() - 4);
258 Asm->EmitInt16(Version);
259 // We share one abbreviations table across all units so it's always at the
260 // start of the section.
262 Asm->EmitInt8(Unit.getOrigUnit().getAddressByteSize());
265 /// \brief Emit the \p Abbrevs array as the shared abbreviation table
266 /// for the linked Dwarf file.
267 void DwarfStreamer::emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs) {
268 MS->SwitchSection(MOFI->getDwarfAbbrevSection());
269 Asm->emitDwarfAbbrevs(Abbrevs);
272 /// \brief Recursively emit the DIE tree rooted at \p Die.
273 void DwarfStreamer::emitDIE(DIE &Die) {
274 MS->SwitchSection(MOFI->getDwarfInfoSection());
275 Asm->emitDwarfDIE(Die);
278 /// \brief The core of the Dwarf linking logic.
280 /// The link of the dwarf information from the object files will be
281 /// driven by the selection of 'root DIEs', which are DIEs that
282 /// describe variables or functions that are present in the linked
283 /// binary (and thus have entries in the debug map). All the debug
284 /// information that will be linked (the DIEs, but also the line
285 /// tables, ranges, ...) is derived from that set of root DIEs.
287 /// The root DIEs are identified because they contain relocations that
288 /// correspond to a debug map entry at specific places (the low_pc for
289 /// a function, the location for a variable). These relocations are
290 /// called ValidRelocs in the DwarfLinker and are gathered as a very
291 /// first step when we start processing a DebugMapObject.
294 DwarfLinker(StringRef OutputFilename, const LinkOptions &Options)
295 : OutputFilename(OutputFilename), Options(Options),
296 BinHolder(Options.Verbose) {}
299 for (auto *Abbrev : Abbreviations)
303 /// \brief Link the contents of the DebugMap.
304 bool link(const DebugMap &);
307 /// \brief Called at the start of a debug object link.
308 void startDebugObject(DWARFContext &);
310 /// \brief Called at the end of a debug object link.
311 void endDebugObject();
313 /// \defgroup FindValidRelocations Translate debug map into a list
314 /// of relevant relocations
321 const DebugMapObject::DebugMapEntry *Mapping;
323 ValidReloc(uint32_t Offset, uint32_t Size, uint64_t Addend,
324 const DebugMapObject::DebugMapEntry *Mapping)
325 : Offset(Offset), Size(Size), Addend(Addend), Mapping(Mapping) {}
327 bool operator<(const ValidReloc &RHS) const { return Offset < RHS.Offset; }
330 /// \brief The valid relocations for the current DebugMapObject.
331 /// This vector is sorted by relocation offset.
332 std::vector<ValidReloc> ValidRelocs;
334 /// \brief Index into ValidRelocs of the next relocation to
335 /// consider. As we walk the DIEs in acsending file offset and as
336 /// ValidRelocs is sorted by file offset, keeping this index
337 /// uptodate is all we have to do to have a cheap lookup during the
338 /// root DIE selection.
339 unsigned NextValidReloc;
341 bool findValidRelocsInDebugInfo(const object::ObjectFile &Obj,
342 const DebugMapObject &DMO);
344 bool findValidRelocs(const object::SectionRef &Section,
345 const object::ObjectFile &Obj,
346 const DebugMapObject &DMO);
348 void findValidRelocsMachO(const object::SectionRef &Section,
349 const object::MachOObjectFile &Obj,
350 const DebugMapObject &DMO);
353 /// \defgroup FindRootDIEs Find DIEs corresponding to debug map entries.
356 /// \brief Recursively walk the \p DIE tree and look for DIEs to
357 /// keep. Store that information in \p CU's DIEInfo.
358 void lookForDIEsToKeep(const DWARFDebugInfoEntryMinimal &DIE,
359 const DebugMapObject &DMO, CompileUnit &CU,
362 /// \brief Flags passed to DwarfLinker::lookForDIEsToKeep
364 TF_Keep = 1 << 0, ///< Mark the traversed DIEs as kept.
365 TF_InFunctionScope = 1 << 1, ///< Current scope is a fucntion scope.
366 TF_DependencyWalk = 1 << 2, ///< Walking the dependencies of a kept DIE.
367 TF_ParentWalk = 1 << 3, ///< Walking up the parents of a kept DIE.
370 /// \brief Mark the passed DIE as well as all the ones it depends on
372 void keepDIEAndDenpendencies(const DWARFDebugInfoEntryMinimal &DIE,
373 CompileUnit::DIEInfo &MyInfo,
374 const DebugMapObject &DMO, CompileUnit &CU,
377 unsigned shouldKeepDIE(const DWARFDebugInfoEntryMinimal &DIE,
378 CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo,
381 unsigned shouldKeepVariableDIE(const DWARFDebugInfoEntryMinimal &DIE,
383 CompileUnit::DIEInfo &MyInfo, unsigned Flags);
385 unsigned shouldKeepSubprogramDIE(const DWARFDebugInfoEntryMinimal &DIE,
387 CompileUnit::DIEInfo &MyInfo,
390 bool hasValidRelocation(uint32_t StartOffset, uint32_t EndOffset,
391 CompileUnit::DIEInfo &Info);
394 /// \defgroup Linking Methods used to link the debug information
397 /// \brief Recursively clone \p InputDIE into an tree of DIE objects
398 /// where useless (as decided by lookForDIEsToKeep()) bits have been
399 /// stripped out and addresses have been rewritten according to the
402 /// \param OutOffset is the offset the cloned DIE in the output
405 /// \returns the root of the cloned tree.
406 DIE *cloneDIE(const DWARFDebugInfoEntryMinimal &InputDIE, CompileUnit &U,
409 typedef DWARFAbbreviationDeclaration::AttributeSpec AttributeSpec;
411 /// \brief Helper for cloneDIE.
412 unsigned cloneAttribute(DIE &Die, const DWARFDebugInfoEntryMinimal &InputDIE,
413 CompileUnit &U, const DWARFFormValue &Val,
414 const AttributeSpec AttrSpec, unsigned AttrSize);
416 /// \brief Helper for cloneDIE.
417 unsigned cloneStringAttribute(DIE &Die, AttributeSpec AttrSpec);
419 /// \brief Helper for cloneDIE.
420 unsigned cloneDieReferenceAttribute(DIE &Die, AttributeSpec AttrSpec,
423 /// \brief Helper for cloneDIE.
424 unsigned cloneBlockAttribute(DIE &Die, AttributeSpec AttrSpec,
425 const DWARFFormValue &Val, unsigned AttrSize);
427 /// \brief Helper for cloneDIE.
428 unsigned cloneScalarAttribute(DIE &Die,
429 const DWARFDebugInfoEntryMinimal &InputDIE,
430 const DWARFUnit &U, AttributeSpec AttrSpec,
431 const DWARFFormValue &Val, unsigned AttrSize);
433 /// \brief Assign an abbreviation number to \p Abbrev
434 void AssignAbbrev(DIEAbbrev &Abbrev);
436 /// \brief FoldingSet that uniques the abbreviations.
437 FoldingSet<DIEAbbrev> AbbreviationsSet;
438 /// \brief Storage for the unique Abbreviations.
439 /// This is passed to AsmPrinter::emitDwarfAbbrevs(), thus it cannot
440 /// be changed to a vecot of unique_ptrs.
441 std::vector<DIEAbbrev *> Abbreviations;
443 /// \brief DIELoc objects that need to be destructed (but not freed!).
444 std::vector<DIELoc *> DIELocs;
445 /// \brief DIEBlock objects that need to be destructed (but not freed!).
446 std::vector<DIEBlock *> DIEBlocks;
447 /// \brief Allocator used for all the DIEValue objects.
448 BumpPtrAllocator DIEAlloc;
451 /// \defgroup Helpers Various helper methods.
454 const DWARFDebugInfoEntryMinimal *
455 resolveDIEReference(DWARFFormValue &RefValue, const DWARFUnit &Unit,
456 const DWARFDebugInfoEntryMinimal &DIE,
457 CompileUnit *&ReferencedCU);
459 CompileUnit *getUnitForOffset(unsigned Offset);
461 void reportWarning(const Twine &Warning, const DWARFUnit *Unit = nullptr,
462 const DWARFDebugInfoEntryMinimal *DIE = nullptr);
464 bool createStreamer(Triple TheTriple, StringRef OutputFilename);
468 std::string OutputFilename;
470 BinaryHolder BinHolder;
471 std::unique_ptr<DwarfStreamer> Streamer;
473 /// The units of the current debug map object.
474 std::vector<CompileUnit> Units;
476 /// The debug map object curently under consideration.
477 DebugMapObject *CurrentDebugObject;
480 /// \brief Similar to DWARFUnitSection::getUnitForOffset(), but
481 /// returning our CompileUnit object instead.
482 CompileUnit *DwarfLinker::getUnitForOffset(unsigned Offset) {
484 std::upper_bound(Units.begin(), Units.end(), Offset,
485 [](uint32_t LHS, const CompileUnit &RHS) {
486 return LHS < RHS.getOrigUnit().getNextUnitOffset();
488 return CU != Units.end() ? &*CU : nullptr;
491 /// \brief Resolve the DIE attribute reference that has been
492 /// extracted in \p RefValue. The resulting DIE migh be in another
493 /// CompileUnit which is stored into \p ReferencedCU.
494 /// \returns null if resolving fails for any reason.
495 const DWARFDebugInfoEntryMinimal *DwarfLinker::resolveDIEReference(
496 DWARFFormValue &RefValue, const DWARFUnit &Unit,
497 const DWARFDebugInfoEntryMinimal &DIE, CompileUnit *&RefCU) {
498 assert(RefValue.isFormClass(DWARFFormValue::FC_Reference));
499 uint64_t RefOffset = *RefValue.getAsReference(&Unit);
501 if ((RefCU = getUnitForOffset(RefOffset)))
502 if (const auto *RefDie = RefCU->getOrigUnit().getDIEForOffset(RefOffset))
505 reportWarning("could not find referenced DIE", &Unit, &DIE);
509 /// \brief Report a warning to the user, optionaly including
510 /// information about a specific \p DIE related to the warning.
511 void DwarfLinker::reportWarning(const Twine &Warning, const DWARFUnit *Unit,
512 const DWARFDebugInfoEntryMinimal *DIE) {
513 StringRef Context = "<debug map>";
514 if (CurrentDebugObject)
515 Context = CurrentDebugObject->getObjectFilename();
516 warn(Warning, Context);
518 if (!Options.Verbose || !DIE)
521 errs() << " in DIE:\n";
522 DIE->dump(errs(), const_cast<DWARFUnit *>(Unit), 0 /* RecurseDepth */,
526 bool DwarfLinker::createStreamer(Triple TheTriple, StringRef OutputFilename) {
527 if (Options.NoOutput)
530 Streamer = llvm::make_unique<DwarfStreamer>();
531 return Streamer->init(TheTriple, OutputFilename);
534 /// \brief Recursive helper to gather the child->parent relationships in the
535 /// original compile unit.
536 static void gatherDIEParents(const DWARFDebugInfoEntryMinimal *DIE,
537 unsigned ParentIdx, CompileUnit &CU) {
538 unsigned MyIdx = CU.getOrigUnit().getDIEIndex(DIE);
539 CU.getInfo(MyIdx).ParentIdx = ParentIdx;
541 if (DIE->hasChildren())
542 for (auto *Child = DIE->getFirstChild(); Child && !Child->isNULL();
543 Child = Child->getSibling())
544 gatherDIEParents(Child, MyIdx, CU);
547 static bool dieNeedsChildrenToBeMeaningful(uint32_t Tag) {
551 case dwarf::DW_TAG_subprogram:
552 case dwarf::DW_TAG_lexical_block:
553 case dwarf::DW_TAG_subroutine_type:
554 case dwarf::DW_TAG_structure_type:
555 case dwarf::DW_TAG_class_type:
556 case dwarf::DW_TAG_union_type:
559 llvm_unreachable("Invalid Tag");
562 void DwarfLinker::startDebugObject(DWARFContext &Dwarf) {
563 Units.reserve(Dwarf.getNumCompileUnits());
567 void DwarfLinker::endDebugObject() {
571 for (auto *Block : DIEBlocks)
573 for (auto *Loc : DIELocs)
581 /// \brief Iterate over the relocations of the given \p Section and
582 /// store the ones that correspond to debug map entries into the
583 /// ValidRelocs array.
584 void DwarfLinker::findValidRelocsMachO(const object::SectionRef &Section,
585 const object::MachOObjectFile &Obj,
586 const DebugMapObject &DMO) {
588 Section.getContents(Contents);
589 DataExtractor Data(Contents, Obj.isLittleEndian(), 0);
591 for (const object::RelocationRef &Reloc : Section.relocations()) {
592 object::DataRefImpl RelocDataRef = Reloc.getRawDataRefImpl();
593 MachO::any_relocation_info MachOReloc = Obj.getRelocation(RelocDataRef);
594 unsigned RelocSize = 1 << Obj.getAnyRelocationLength(MachOReloc);
596 if ((RelocSize != 4 && RelocSize != 8) || Reloc.getOffset(Offset64)) {
597 reportWarning(" unsupported relocation in debug_info section.");
600 uint32_t Offset = Offset64;
601 // Mach-o uses REL relocations, the addend is at the relocation offset.
602 uint64_t Addend = Data.getUnsigned(&Offset, RelocSize);
604 auto Sym = Reloc.getSymbol();
605 if (Sym != Obj.symbol_end()) {
606 StringRef SymbolName;
607 if (Sym->getName(SymbolName)) {
608 reportWarning("error getting relocation symbol name.");
611 if (const auto *Mapping = DMO.lookupSymbol(SymbolName))
612 ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping);
613 } else if (const auto *Mapping = DMO.lookupObjectAddress(Addend)) {
614 // Do not store the addend. The addend was the address of the
615 // symbol in the object file, the address in the binary that is
616 // stored in the debug map doesn't need to be offseted.
617 ValidRelocs.emplace_back(Offset64, RelocSize, 0, Mapping);
622 /// \brief Dispatch the valid relocation finding logic to the
623 /// appropriate handler depending on the object file format.
624 bool DwarfLinker::findValidRelocs(const object::SectionRef &Section,
625 const object::ObjectFile &Obj,
626 const DebugMapObject &DMO) {
627 // Dispatch to the right handler depending on the file type.
628 if (auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Obj))
629 findValidRelocsMachO(Section, *MachOObj, DMO);
631 reportWarning(Twine("unsupported object file type: ") + Obj.getFileName());
633 if (ValidRelocs.empty())
636 // Sort the relocations by offset. We will walk the DIEs linearly in
637 // the file, this allows us to just keep an index in the relocation
638 // array that we advance during our walk, rather than resorting to
639 // some associative container. See DwarfLinker::NextValidReloc.
640 std::sort(ValidRelocs.begin(), ValidRelocs.end());
644 /// \brief Look for relocations in the debug_info section that match
645 /// entries in the debug map. These relocations will drive the Dwarf
646 /// link by indicating which DIEs refer to symbols present in the
648 /// \returns wether there are any valid relocations in the debug info.
649 bool DwarfLinker::findValidRelocsInDebugInfo(const object::ObjectFile &Obj,
650 const DebugMapObject &DMO) {
651 // Find the debug_info section.
652 for (const object::SectionRef &Section : Obj.sections()) {
653 StringRef SectionName;
654 Section.getName(SectionName);
655 SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
656 if (SectionName != "debug_info")
658 return findValidRelocs(Section, Obj, DMO);
663 /// \brief Checks that there is a relocation against an actual debug
664 /// map entry between \p StartOffset and \p NextOffset.
666 /// This function must be called with offsets in strictly ascending
667 /// order because it never looks back at relocations it already 'went past'.
668 /// \returns true and sets Info.InDebugMap if it is the case.
669 bool DwarfLinker::hasValidRelocation(uint32_t StartOffset, uint32_t EndOffset,
670 CompileUnit::DIEInfo &Info) {
671 assert(NextValidReloc == 0 ||
672 StartOffset > ValidRelocs[NextValidReloc - 1].Offset);
673 if (NextValidReloc >= ValidRelocs.size())
676 uint64_t RelocOffset = ValidRelocs[NextValidReloc].Offset;
678 // We might need to skip some relocs that we didn't consider. For
679 // example the high_pc of a discarded DIE might contain a reloc that
680 // is in the list because it actually corresponds to the start of a
681 // function that is in the debug map.
682 while (RelocOffset < StartOffset && NextValidReloc < ValidRelocs.size() - 1)
683 RelocOffset = ValidRelocs[++NextValidReloc].Offset;
685 if (RelocOffset < StartOffset || RelocOffset >= EndOffset)
688 const auto &ValidReloc = ValidRelocs[NextValidReloc++];
690 outs() << "Found valid debug map entry: " << ValidReloc.Mapping->getKey()
691 << " " << format("\t%016" PRIx64 " => %016" PRIx64,
692 ValidReloc.Mapping->getValue().ObjectAddress,
693 ValidReloc.Mapping->getValue().BinaryAddress);
696 ValidReloc.Mapping->getValue().BinaryAddress + ValidReloc.Addend;
697 Info.InDebugMap = true;
701 /// \brief Get the starting and ending (exclusive) offset for the
702 /// attribute with index \p Idx descibed by \p Abbrev. \p Offset is
703 /// supposed to point to the position of the first attribute described
705 /// \return [StartOffset, EndOffset) as a pair.
706 static std::pair<uint32_t, uint32_t>
707 getAttributeOffsets(const DWARFAbbreviationDeclaration *Abbrev, unsigned Idx,
708 unsigned Offset, const DWARFUnit &Unit) {
709 DataExtractor Data = Unit.getDebugInfoExtractor();
711 for (unsigned i = 0; i < Idx; ++i)
712 DWARFFormValue::skipValue(Abbrev->getFormByIndex(i), Data, &Offset, &Unit);
714 uint32_t End = Offset;
715 DWARFFormValue::skipValue(Abbrev->getFormByIndex(Idx), Data, &End, &Unit);
717 return std::make_pair(Offset, End);
720 /// \brief Check if a variable describing DIE should be kept.
721 /// \returns updated TraversalFlags.
722 unsigned DwarfLinker::shouldKeepVariableDIE(
723 const DWARFDebugInfoEntryMinimal &DIE, CompileUnit &Unit,
724 CompileUnit::DIEInfo &MyInfo, unsigned Flags) {
725 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
727 // Global variables with constant value can always be kept.
728 if (!(Flags & TF_InFunctionScope) &&
729 Abbrev->findAttributeIndex(dwarf::DW_AT_const_value) != -1U) {
730 MyInfo.InDebugMap = true;
731 return Flags | TF_Keep;
734 uint32_t LocationIdx = Abbrev->findAttributeIndex(dwarf::DW_AT_location);
735 if (LocationIdx == -1U)
738 uint32_t Offset = DIE.getOffset() + getULEB128Size(Abbrev->getCode());
739 const DWARFUnit &OrigUnit = Unit.getOrigUnit();
740 uint32_t LocationOffset, LocationEndOffset;
741 std::tie(LocationOffset, LocationEndOffset) =
742 getAttributeOffsets(Abbrev, LocationIdx, Offset, OrigUnit);
744 // See if there is a relocation to a valid debug map entry inside
745 // this variable's location. The order is important here. We want to
746 // always check in the variable has a valid relocation, so that the
747 // DIEInfo is filled. However, we don't want a static variable in a
748 // function to force us to keep the enclosing function.
749 if (!hasValidRelocation(LocationOffset, LocationEndOffset, MyInfo) ||
750 (Flags & TF_InFunctionScope))
754 DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */);
756 return Flags | TF_Keep;
759 /// \brief Check if a function describing DIE should be kept.
760 /// \returns updated TraversalFlags.
761 unsigned DwarfLinker::shouldKeepSubprogramDIE(
762 const DWARFDebugInfoEntryMinimal &DIE, CompileUnit &Unit,
763 CompileUnit::DIEInfo &MyInfo, unsigned Flags) {
764 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
766 Flags |= TF_InFunctionScope;
768 uint32_t LowPcIdx = Abbrev->findAttributeIndex(dwarf::DW_AT_low_pc);
772 uint32_t Offset = DIE.getOffset() + getULEB128Size(Abbrev->getCode());
773 const DWARFUnit &OrigUnit = Unit.getOrigUnit();
774 uint32_t LowPcOffset, LowPcEndOffset;
775 std::tie(LowPcOffset, LowPcEndOffset) =
776 getAttributeOffsets(Abbrev, LowPcIdx, Offset, OrigUnit);
779 DIE.getAttributeValueAsAddress(&OrigUnit, dwarf::DW_AT_low_pc, -1ULL);
780 assert(LowPc != -1ULL && "low_pc attribute is not an address.");
781 if (LowPc == -1ULL ||
782 !hasValidRelocation(LowPcOffset, LowPcEndOffset, MyInfo))
786 DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */);
788 return Flags | TF_Keep;
791 /// \brief Check if a DIE should be kept.
792 /// \returns updated TraversalFlags.
793 unsigned DwarfLinker::shouldKeepDIE(const DWARFDebugInfoEntryMinimal &DIE,
795 CompileUnit::DIEInfo &MyInfo,
797 switch (DIE.getTag()) {
798 case dwarf::DW_TAG_constant:
799 case dwarf::DW_TAG_variable:
800 return shouldKeepVariableDIE(DIE, Unit, MyInfo, Flags);
801 case dwarf::DW_TAG_subprogram:
802 return shouldKeepSubprogramDIE(DIE, Unit, MyInfo, Flags);
803 case dwarf::DW_TAG_module:
804 case dwarf::DW_TAG_imported_module:
805 case dwarf::DW_TAG_imported_declaration:
806 case dwarf::DW_TAG_imported_unit:
807 // We always want to keep these.
808 return Flags | TF_Keep;
814 /// \brief Mark the passed DIE as well as all the ones it depends on
817 /// This function is called by lookForDIEsToKeep on DIEs that are
818 /// newly discovered to be needed in the link. It recursively calls
819 /// back to lookForDIEsToKeep while adding TF_DependencyWalk to the
820 /// TraversalFlags to inform it that it's not doing the primary DIE
822 void DwarfLinker::keepDIEAndDenpendencies(const DWARFDebugInfoEntryMinimal &DIE,
823 CompileUnit::DIEInfo &MyInfo,
824 const DebugMapObject &DMO,
825 CompileUnit &CU, unsigned Flags) {
826 const DWARFUnit &Unit = CU.getOrigUnit();
829 // First mark all the parent chain as kept.
830 unsigned AncestorIdx = MyInfo.ParentIdx;
831 while (!CU.getInfo(AncestorIdx).Keep) {
832 lookForDIEsToKeep(*Unit.getDIEAtIndex(AncestorIdx), DMO, CU,
833 TF_ParentWalk | TF_Keep | TF_DependencyWalk);
834 AncestorIdx = CU.getInfo(AncestorIdx).ParentIdx;
837 // Then we need to mark all the DIEs referenced by this DIE's
838 // attributes as kept.
839 DataExtractor Data = Unit.getDebugInfoExtractor();
840 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
841 uint32_t Offset = DIE.getOffset() + getULEB128Size(Abbrev->getCode());
843 // Mark all DIEs referenced through atttributes as kept.
844 for (const auto &AttrSpec : Abbrev->attributes()) {
845 DWARFFormValue Val(AttrSpec.Form);
847 if (!Val.isFormClass(DWARFFormValue::FC_Reference)) {
848 DWARFFormValue::skipValue(AttrSpec.Form, Data, &Offset, &Unit);
852 Val.extractValue(Data, &Offset, &Unit);
853 CompileUnit *ReferencedCU;
854 if (const auto *RefDIE = resolveDIEReference(Val, Unit, DIE, ReferencedCU))
855 lookForDIEsToKeep(*RefDIE, DMO, *ReferencedCU,
856 TF_Keep | TF_DependencyWalk);
860 /// \brief Recursively walk the \p DIE tree and look for DIEs to
861 /// keep. Store that information in \p CU's DIEInfo.
863 /// This function is the entry point of the DIE selection
864 /// algorithm. It is expected to walk the DIE tree in file order and
865 /// (though the mediation of its helper) call hasValidRelocation() on
866 /// each DIE that might be a 'root DIE' (See DwarfLinker class
868 /// While walking the dependencies of root DIEs, this function is
869 /// also called, but during these dependency walks the file order is
870 /// not respected. The TF_DependencyWalk flag tells us which kind of
871 /// traversal we are currently doing.
872 void DwarfLinker::lookForDIEsToKeep(const DWARFDebugInfoEntryMinimal &DIE,
873 const DebugMapObject &DMO, CompileUnit &CU,
875 unsigned Idx = CU.getOrigUnit().getDIEIndex(&DIE);
876 CompileUnit::DIEInfo &MyInfo = CU.getInfo(Idx);
877 bool AlreadyKept = MyInfo.Keep;
879 // If the Keep flag is set, we are marking a required DIE's
880 // dependencies. If our target is already marked as kept, we're all
882 if ((Flags & TF_DependencyWalk) && AlreadyKept)
885 // We must not call shouldKeepDIE while called from keepDIEAndDenpendencies,
886 // because it would screw up the relocation finding logic.
887 if (!(Flags & TF_DependencyWalk))
888 Flags = shouldKeepDIE(DIE, CU, MyInfo, Flags);
890 // If it is a newly kept DIE mark it as well as all its dependencies as kept.
891 if (!AlreadyKept && (Flags & TF_Keep))
892 keepDIEAndDenpendencies(DIE, MyInfo, DMO, CU, Flags);
894 // The TF_ParentWalk flag tells us that we are currently walking up
895 // the parent chain of a required DIE, and we don't want to mark all
896 // the children of the parents as kept (consider for example a
897 // DW_TAG_namespace node in the parent chain). There are however a
898 // set of DIE types for which we want to ignore that directive and still
899 // walk their children.
900 if (dieNeedsChildrenToBeMeaningful(DIE.getTag()))
901 Flags &= ~TF_ParentWalk;
903 if (!DIE.hasChildren() || (Flags & TF_ParentWalk))
906 for (auto *Child = DIE.getFirstChild(); Child && !Child->isNULL();
907 Child = Child->getSibling())
908 lookForDIEsToKeep(*Child, DMO, CU, Flags);
911 /// \brief Assign an abbreviation numer to \p Abbrev.
913 /// Our DIEs get freed after every DebugMapObject has been processed,
914 /// thus the FoldingSet we use to unique DIEAbbrevs cannot refer to
915 /// the instances hold by the DIEs. When we encounter an abbreviation
916 /// that we don't know, we create a permanent copy of it.
917 void DwarfLinker::AssignAbbrev(DIEAbbrev &Abbrev) {
918 // Check the set for priors.
922 DIEAbbrev *InSet = AbbreviationsSet.FindNodeOrInsertPos(ID, InsertToken);
924 // If it's newly added.
926 // Assign existing abbreviation number.
927 Abbrev.setNumber(InSet->getNumber());
929 // Add to abbreviation list.
930 Abbreviations.push_back(
931 new DIEAbbrev(Abbrev.getTag(), Abbrev.hasChildren()));
932 for (const auto &Attr : Abbrev.getData())
933 Abbreviations.back()->AddAttribute(Attr.getAttribute(), Attr.getForm());
934 AbbreviationsSet.InsertNode(Abbreviations.back(), InsertToken);
935 // Assign the unique abbreviation number.
936 Abbrev.setNumber(Abbreviations.size());
937 Abbreviations.back()->setNumber(Abbreviations.size());
941 /// \brief Clone a string attribute described by \p AttrSpec and add
943 /// \returns the size of the new attribute.
944 unsigned DwarfLinker::cloneStringAttribute(DIE &Die, AttributeSpec AttrSpec) {
945 // Switch everything to out of line strings.
946 // FIXME: Construct the actual string table.
947 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::DW_FORM_strp,
948 new (DIEAlloc) DIEInteger(0));
952 /// \brief Clone an attribute referencing another DIE and add
954 /// \returns the size of the new attribute.
955 unsigned DwarfLinker::cloneDieReferenceAttribute(DIE &Die,
956 AttributeSpec AttrSpec,
958 // FIXME: Handle DIE references.
959 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::Form(AttrSpec.Form),
960 new (DIEAlloc) DIEInteger(0));
964 /// \brief Clone an attribute of block form (locations, constants) and add
966 /// \returns the size of the new attribute.
967 unsigned DwarfLinker::cloneBlockAttribute(DIE &Die, AttributeSpec AttrSpec,
968 const DWARFFormValue &Val,
972 DIELoc *Loc = nullptr;
973 DIEBlock *Block = nullptr;
974 // Just copy the block data over.
975 if (AttrSpec.Attr == dwarf::DW_FORM_exprloc) {
976 Loc = new (DIEAlloc) DIELoc();
977 DIELocs.push_back(Loc);
979 Block = new (DIEAlloc) DIEBlock();
980 DIEBlocks.push_back(Block);
982 Attr = Loc ? static_cast<DIE *>(Loc) : static_cast<DIE *>(Block);
983 Value = Loc ? static_cast<DIEValue *>(Loc) : static_cast<DIEValue *>(Block);
984 ArrayRef<uint8_t> Bytes = *Val.getAsBlock();
985 for (auto Byte : Bytes)
986 Attr->addValue(static_cast<dwarf::Attribute>(0), dwarf::DW_FORM_data1,
987 new (DIEAlloc) DIEInteger(Byte));
988 // FIXME: If DIEBlock and DIELoc just reuses the Size field of
989 // the DIE class, this if could be replaced by
990 // Attr->setSize(Bytes.size()).
993 Loc->ComputeSize(&Streamer->getAsmPrinter());
995 Block->ComputeSize(&Streamer->getAsmPrinter());
997 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::Form(AttrSpec.Form),
1002 /// \brief Clone a scalar attribute and add it to \p Die.
1003 /// \returns the size of the new attribute.
1004 unsigned DwarfLinker::cloneScalarAttribute(
1005 DIE &Die, const DWARFDebugInfoEntryMinimal &InputDIE, const DWARFUnit &U,
1006 AttributeSpec AttrSpec, const DWARFFormValue &Val, unsigned AttrSize) {
1008 if (AttrSpec.Form == dwarf::DW_FORM_sec_offset)
1009 Value = *Val.getAsSectionOffset();
1010 else if (AttrSpec.Form == dwarf::DW_FORM_sdata)
1011 Value = *Val.getAsSignedConstant();
1012 else if (AttrSpec.Form == dwarf::DW_FORM_addr)
1013 Value = *Val.getAsAddress(&U);
1014 else if (auto OptionalValue = Val.getAsUnsignedConstant())
1015 Value = *OptionalValue;
1017 reportWarning("Unsupported scalar attribute form. Dropping attribute.", &U,
1021 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::Form(AttrSpec.Form),
1022 new (DIEAlloc) DIEInteger(Value));
1026 /// \brief Clone \p InputDIE's attribute described by \p AttrSpec with
1027 /// value \p Val, and add it to \p Die.
1028 /// \returns the size of the cloned attribute.
1029 unsigned DwarfLinker::cloneAttribute(DIE &Die,
1030 const DWARFDebugInfoEntryMinimal &InputDIE,
1032 const DWARFFormValue &Val,
1033 const AttributeSpec AttrSpec,
1034 unsigned AttrSize) {
1035 const DWARFUnit &U = Unit.getOrigUnit();
1037 switch (AttrSpec.Form) {
1038 case dwarf::DW_FORM_strp:
1039 case dwarf::DW_FORM_string:
1040 return cloneStringAttribute(Die, AttrSpec);
1041 case dwarf::DW_FORM_ref_addr:
1042 case dwarf::DW_FORM_ref1:
1043 case dwarf::DW_FORM_ref2:
1044 case dwarf::DW_FORM_ref4:
1045 case dwarf::DW_FORM_ref8:
1046 return cloneDieReferenceAttribute(Die, AttrSpec, AttrSize);
1047 case dwarf::DW_FORM_block:
1048 case dwarf::DW_FORM_block1:
1049 case dwarf::DW_FORM_block2:
1050 case dwarf::DW_FORM_block4:
1051 case dwarf::DW_FORM_exprloc:
1052 return cloneBlockAttribute(Die, AttrSpec, Val, AttrSize);
1053 case dwarf::DW_FORM_addr:
1054 case dwarf::DW_FORM_data1:
1055 case dwarf::DW_FORM_data2:
1056 case dwarf::DW_FORM_data4:
1057 case dwarf::DW_FORM_data8:
1058 case dwarf::DW_FORM_udata:
1059 case dwarf::DW_FORM_sdata:
1060 case dwarf::DW_FORM_sec_offset:
1061 case dwarf::DW_FORM_flag:
1062 case dwarf::DW_FORM_flag_present:
1063 return cloneScalarAttribute(Die, InputDIE, U, AttrSpec, Val, AttrSize);
1065 reportWarning("Unsupported attribute form in cloneAttribute. Dropping.", &U,
1072 /// \brief Recursively clone \p InputDIE's subtrees that have been
1073 /// selected to appear in the linked output.
1075 /// \param OutOffset is the Offset where the newly created DIE will
1076 /// lie in the linked compile unit.
1078 /// \returns the cloned DIE object or null if nothing was selected.
1079 DIE *DwarfLinker::cloneDIE(const DWARFDebugInfoEntryMinimal &InputDIE,
1080 CompileUnit &Unit, uint32_t OutOffset) {
1081 DWARFUnit &U = Unit.getOrigUnit();
1082 unsigned Idx = U.getDIEIndex(&InputDIE);
1084 // Should the DIE appear in the output?
1085 if (!Unit.getInfo(Idx).Keep)
1088 uint32_t Offset = InputDIE.getOffset();
1090 DIE *Die = new DIE(static_cast<dwarf::Tag>(InputDIE.getTag()));
1091 Die->setOffset(OutOffset);
1093 // Extract and clone every attribute.
1094 DataExtractor Data = U.getDebugInfoExtractor();
1095 const auto *Abbrev = InputDIE.getAbbreviationDeclarationPtr();
1096 Offset += getULEB128Size(Abbrev->getCode());
1098 for (const auto &AttrSpec : Abbrev->attributes()) {
1099 DWARFFormValue Val(AttrSpec.Form);
1100 uint32_t AttrSize = Offset;
1101 Val.extractValue(Data, &Offset, &U);
1102 AttrSize = Offset - AttrSize;
1104 OutOffset += cloneAttribute(*Die, InputDIE, Unit, Val, AttrSpec, AttrSize);
1107 DIEAbbrev &NewAbbrev = Die->getAbbrev();
1108 // If a scope DIE is kept, we must have kept at least one child. If
1109 // it's not the case, we'll just be emitting one wasteful end of
1110 // children marker, but things won't break.
1111 if (InputDIE.hasChildren())
1112 NewAbbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
1113 // Assign a permanent abbrev number
1114 AssignAbbrev(Die->getAbbrev());
1116 // Add the size of the abbreviation number to the output offset.
1117 OutOffset += getULEB128Size(Die->getAbbrevNumber());
1119 if (!Abbrev->hasChildren()) {
1121 Die->setSize(OutOffset - Die->getOffset());
1125 // Recursively clone children.
1126 for (auto *Child = InputDIE.getFirstChild(); Child && !Child->isNULL();
1127 Child = Child->getSibling()) {
1128 if (DIE *Clone = cloneDIE(*Child, Unit, OutOffset)) {
1129 Die->addChild(std::unique_ptr<DIE>(Clone));
1130 OutOffset = Clone->getOffset() + Clone->getSize();
1134 // Account for the end of children marker.
1135 OutOffset += sizeof(int8_t);
1137 Die->setSize(OutOffset - Die->getOffset());
1141 bool DwarfLinker::link(const DebugMap &Map) {
1143 if (Map.begin() == Map.end()) {
1144 errs() << "Empty debug map.\n";
1148 if (!createStreamer(Map.getTriple(), OutputFilename))
1151 // Size of the DIEs (and headers) generated for the linked output.
1152 uint64_t OutputDebugInfoSize = 0;
1154 for (const auto &Obj : Map.objects()) {
1155 CurrentDebugObject = Obj.get();
1157 if (Options.Verbose)
1158 outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n";
1159 auto ErrOrObj = BinHolder.GetObjectFile(Obj->getObjectFilename());
1160 if (std::error_code EC = ErrOrObj.getError()) {
1161 reportWarning(Twine(Obj->getObjectFilename()) + ": " + EC.message());
1165 // Look for relocations that correspond to debug map entries.
1166 if (!findValidRelocsInDebugInfo(*ErrOrObj, *Obj)) {
1167 if (Options.Verbose)
1168 outs() << "No valid relocations found. Skipping.\n";
1172 // Setup access to the debug info.
1173 DWARFContextInMemory DwarfContext(*ErrOrObj);
1174 startDebugObject(DwarfContext);
1176 // In a first phase, just read in the debug info and store the DIE
1177 // parent links that we will use during the next phase.
1178 for (const auto &CU : DwarfContext.compile_units()) {
1179 auto *CUDie = CU->getCompileUnitDIE(false);
1180 if (Options.Verbose) {
1181 outs() << "Input compilation unit:";
1182 CUDie->dump(outs(), CU.get(), 0);
1184 Units.emplace_back(*CU);
1185 gatherDIEParents(CUDie, 0, Units.back());
1188 // Then mark all the DIEs that need to be present in the linked
1189 // output and collect some information about them. Note that this
1190 // loop can not be merged with the previous one becaue cross-cu
1191 // references require the ParentIdx to be setup for every CU in
1192 // the object file before calling this.
1193 for (auto &CurrentUnit : Units)
1194 lookForDIEsToKeep(*CurrentUnit.getOrigUnit().getCompileUnitDIE(), *Obj,
1197 // Construct the output DIE tree by cloning the DIEs we chose to
1198 // keep above. If there are no valid relocs, then there's nothing
1200 if (!ValidRelocs.empty())
1201 for (auto &CurrentUnit : Units) {
1202 const auto *InputDIE = CurrentUnit.getOrigUnit().getCompileUnitDIE();
1204 cloneDIE(*InputDIE, CurrentUnit, 11 /* Unit Header size */);
1205 CurrentUnit.setOutputUnitDIE(OutputDIE);
1206 OutputDebugInfoSize = CurrentUnit.computeOffsets(OutputDebugInfoSize);
1209 // Emit all the compile unit's debug information.
1210 if (!ValidRelocs.empty() && !Options.NoOutput)
1211 for (auto &CurrentUnit : Units) {
1212 Streamer->emitCompileUnitHeader(CurrentUnit);
1213 if (!CurrentUnit.getOutputUnitDIE())
1215 Streamer->emitDIE(*CurrentUnit.getOutputUnitDIE());
1218 // Clean-up before starting working on the next object.
1222 // Emit everything that's global.
1223 if (!Options.NoOutput)
1224 Streamer->emitAbbrevs(Abbreviations);
1226 return Options.NoOutput ? true : Streamer->finish();
1230 bool linkDwarf(StringRef OutputFilename, const DebugMap &DM,
1231 const LinkOptions &Options) {
1232 DwarfLinker Linker(OutputFilename, Options);
1233 return Linker.link(DM);