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)
69 : OrigUnit(RHS.OrigUnit), Info(std::move(RHS.Info)),
70 CUDie(std::move(RHS.CUDie)), StartOffset(RHS.StartOffset),
71 NextUnitOffset(RHS.NextUnitOffset) {}
73 DWARFUnit &getOrigUnit() const { return OrigUnit; }
75 DIE *getOutputUnitDIE() const { return CUDie.get(); }
76 void setOutputUnitDIE(DIE *Die) { CUDie.reset(Die); }
78 DIEInfo &getInfo(unsigned Idx) { return Info[Idx]; }
79 const DIEInfo &getInfo(unsigned Idx) const { return Info[Idx]; }
81 uint64_t getStartOffset() const { return StartOffset; }
82 uint64_t getNextUnitOffset() const { return NextUnitOffset; }
84 /// \brief Set the start and end offsets for this unit. Must be
85 /// called after the CU's DIEs have been cloned. The unit start
86 /// offset will be set to \p DebugInfoSize.
87 /// \returns the next unit offset (which is also the current
88 /// debug_info section size).
89 uint64_t computeOffsets(uint64_t DebugInfoSize);
93 std::vector<DIEInfo> Info; ///< DIE info indexed by DIE index.
94 std::unique_ptr<DIE> CUDie; ///< Root of the linked DIE tree.
97 uint64_t NextUnitOffset;
100 uint64_t CompileUnit::computeOffsets(uint64_t DebugInfoSize) {
101 StartOffset = DebugInfoSize;
102 NextUnitOffset = StartOffset + 11 /* Header size */;
103 // The root DIE might be null, meaning that the Unit had nothing to
104 // contribute to the linked output. In that case, we will emit the
105 // unit header without any actual DIE.
107 NextUnitOffset += CUDie->getSize();
108 return NextUnitOffset;
111 /// \brief The Dwarf streaming logic
113 /// All interactions with the MC layer that is used to build the debug
114 /// information binary representation are handled in this class.
115 class DwarfStreamer {
116 /// \defgroup MCObjects MC layer objects constructed by the streamer
118 std::unique_ptr<MCRegisterInfo> MRI;
119 std::unique_ptr<MCAsmInfo> MAI;
120 std::unique_ptr<MCObjectFileInfo> MOFI;
121 std::unique_ptr<MCContext> MC;
122 MCAsmBackend *MAB; // Owned by MCStreamer
123 std::unique_ptr<MCInstrInfo> MII;
124 std::unique_ptr<MCSubtargetInfo> MSTI;
125 MCCodeEmitter *MCE; // Owned by MCStreamer
126 MCStreamer *MS; // Owned by AsmPrinter
127 std::unique_ptr<TargetMachine> TM;
128 std::unique_ptr<AsmPrinter> Asm;
131 /// \brief the file we stream the linked Dwarf to.
132 std::unique_ptr<raw_fd_ostream> OutFile;
135 /// \brief Actually create the streamer and the ouptut file.
137 /// This could be done directly in the constructor, but it feels
138 /// more natural to handle errors through return value.
139 bool init(Triple TheTriple, StringRef OutputFilename);
141 /// \brief Dump the file to the disk.
144 AsmPrinter &getAsmPrinter() const { return *Asm; }
146 /// \brief Set the current output section to debug_info and change
147 /// the MC Dwarf version to \p DwarfVersion.
148 void switchToDebugInfoSection(unsigned DwarfVersion);
150 /// \brief Emit the compilation unit header for \p Unit in the
151 /// debug_info section.
153 /// As a side effect, this also switches the current Dwarf version
154 /// of the MC layer to the one of U.getOrigUnit().
155 void emitCompileUnitHeader(CompileUnit &Unit);
157 /// \brief Recursively emit the DIE tree rooted at \p Die.
158 void emitDIE(DIE &Die);
160 /// \brief Emit the abbreviation table \p Abbrevs to the
161 /// debug_abbrev section.
162 void emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs);
165 bool DwarfStreamer::init(Triple TheTriple, StringRef OutputFilename) {
166 std::string ErrorStr;
167 std::string TripleName;
168 StringRef Context = "dwarf streamer init";
171 const Target *TheTarget =
172 TargetRegistry::lookupTarget(TripleName, TheTriple, ErrorStr);
174 return error(ErrorStr, Context);
175 TripleName = TheTriple.getTriple();
177 // Create all the MC Objects.
178 MRI.reset(TheTarget->createMCRegInfo(TripleName));
180 return error(Twine("no register info for target ") + TripleName, Context);
182 MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName));
184 return error("no asm info for target " + TripleName, Context);
186 MOFI.reset(new MCObjectFileInfo);
187 MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
188 MOFI->InitMCObjectFileInfo(TripleName, Reloc::Default, CodeModel::Default,
191 MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "");
193 return error("no asm backend for target " + TripleName, Context);
195 MII.reset(TheTarget->createMCInstrInfo());
197 return error("no instr info info for target " + TripleName, Context);
199 MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
201 return error("no subtarget info for target " + TripleName, Context);
203 MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MSTI, *MC);
205 return error("no code emitter for target " + TripleName, Context);
207 // Create the output file.
210 llvm::make_unique<raw_fd_ostream>(OutputFilename, EC, sys::fs::F_None);
212 return error(Twine(OutputFilename) + ": " + EC.message(), Context);
214 MS = TheTarget->createMCObjectStreamer(TripleName, *MC, *MAB, *OutFile, MCE,
217 return error("no object streamer for target " + TripleName, Context);
219 // Finally create the AsmPrinter we'll use to emit the DIEs.
220 TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions()));
222 return error("no target machine for target " + TripleName, Context);
224 Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr<MCStreamer>(MS)));
226 return error("no asm printer for target " + TripleName, Context);
231 bool DwarfStreamer::finish() {
236 /// \brief Set the current output section to debug_info and change
237 /// the MC Dwarf version to \p DwarfVersion.
238 void DwarfStreamer::switchToDebugInfoSection(unsigned DwarfVersion) {
239 MS->SwitchSection(MOFI->getDwarfInfoSection());
240 MC->setDwarfVersion(DwarfVersion);
243 /// \brief Emit the compilation unit header for \p Unit in the
244 /// debug_info section.
246 /// A Dwarf scetion header is encoded as:
247 /// uint32_t Unit length (omiting this field)
249 /// uint32_t Abbreviation table offset
250 /// uint8_t Address size
252 /// Leading to a total of 11 bytes.
253 void DwarfStreamer::emitCompileUnitHeader(CompileUnit &Unit) {
254 unsigned Version = Unit.getOrigUnit().getVersion();
255 switchToDebugInfoSection(Version);
257 // Emit size of content not including length itself. The size has
258 // already been computed in CompileUnit::computeOffsets(). Substract
259 // 4 to that size to account for the length field.
260 Asm->EmitInt32(Unit.getNextUnitOffset() - Unit.getStartOffset() - 4);
261 Asm->EmitInt16(Version);
262 // We share one abbreviations table across all units so it's always at the
263 // start of the section.
265 Asm->EmitInt8(Unit.getOrigUnit().getAddressByteSize());
268 /// \brief Emit the \p Abbrevs array as the shared abbreviation table
269 /// for the linked Dwarf file.
270 void DwarfStreamer::emitAbbrevs(const std::vector<DIEAbbrev *> &Abbrevs) {
271 MS->SwitchSection(MOFI->getDwarfAbbrevSection());
272 Asm->emitDwarfAbbrevs(Abbrevs);
275 /// \brief Recursively emit the DIE tree rooted at \p Die.
276 void DwarfStreamer::emitDIE(DIE &Die) {
277 MS->SwitchSection(MOFI->getDwarfInfoSection());
278 Asm->emitDwarfDIE(Die);
281 /// \brief The core of the Dwarf linking logic.
283 /// The link of the dwarf information from the object files will be
284 /// driven by the selection of 'root DIEs', which are DIEs that
285 /// describe variables or functions that are present in the linked
286 /// binary (and thus have entries in the debug map). All the debug
287 /// information that will be linked (the DIEs, but also the line
288 /// tables, ranges, ...) is derived from that set of root DIEs.
290 /// The root DIEs are identified because they contain relocations that
291 /// correspond to a debug map entry at specific places (the low_pc for
292 /// a function, the location for a variable). These relocations are
293 /// called ValidRelocs in the DwarfLinker and are gathered as a very
294 /// first step when we start processing a DebugMapObject.
297 DwarfLinker(StringRef OutputFilename, const LinkOptions &Options)
298 : OutputFilename(OutputFilename), Options(Options),
299 BinHolder(Options.Verbose) {}
302 for (auto *Abbrev : Abbreviations)
306 /// \brief Link the contents of the DebugMap.
307 bool link(const DebugMap &);
310 /// \brief Called at the start of a debug object link.
311 void startDebugObject(DWARFContext &);
313 /// \brief Called at the end of a debug object link.
314 void endDebugObject();
316 /// \defgroup FindValidRelocations Translate debug map into a list
317 /// of relevant relocations
324 const DebugMapObject::DebugMapEntry *Mapping;
326 ValidReloc(uint32_t Offset, uint32_t Size, uint64_t Addend,
327 const DebugMapObject::DebugMapEntry *Mapping)
328 : Offset(Offset), Size(Size), Addend(Addend), Mapping(Mapping) {}
330 bool operator<(const ValidReloc &RHS) const { return Offset < RHS.Offset; }
333 /// \brief The valid relocations for the current DebugMapObject.
334 /// This vector is sorted by relocation offset.
335 std::vector<ValidReloc> ValidRelocs;
337 /// \brief Index into ValidRelocs of the next relocation to
338 /// consider. As we walk the DIEs in acsending file offset and as
339 /// ValidRelocs is sorted by file offset, keeping this index
340 /// uptodate is all we have to do to have a cheap lookup during the
341 /// root DIE selection.
342 unsigned NextValidReloc;
344 bool findValidRelocsInDebugInfo(const object::ObjectFile &Obj,
345 const DebugMapObject &DMO);
347 bool findValidRelocs(const object::SectionRef &Section,
348 const object::ObjectFile &Obj,
349 const DebugMapObject &DMO);
351 void findValidRelocsMachO(const object::SectionRef &Section,
352 const object::MachOObjectFile &Obj,
353 const DebugMapObject &DMO);
356 /// \defgroup FindRootDIEs Find DIEs corresponding to debug map entries.
359 /// \brief Recursively walk the \p DIE tree and look for DIEs to
360 /// keep. Store that information in \p CU's DIEInfo.
361 void lookForDIEsToKeep(const DWARFDebugInfoEntryMinimal &DIE,
362 const DebugMapObject &DMO, CompileUnit &CU,
365 /// \brief Flags passed to DwarfLinker::lookForDIEsToKeep
367 TF_Keep = 1 << 0, ///< Mark the traversed DIEs as kept.
368 TF_InFunctionScope = 1 << 1, ///< Current scope is a fucntion scope.
369 TF_DependencyWalk = 1 << 2, ///< Walking the dependencies of a kept DIE.
370 TF_ParentWalk = 1 << 3, ///< Walking up the parents of a kept DIE.
373 /// \brief Mark the passed DIE as well as all the ones it depends on
375 void keepDIEAndDenpendencies(const DWARFDebugInfoEntryMinimal &DIE,
376 CompileUnit::DIEInfo &MyInfo,
377 const DebugMapObject &DMO, CompileUnit &CU,
380 unsigned shouldKeepDIE(const DWARFDebugInfoEntryMinimal &DIE,
381 CompileUnit &Unit, CompileUnit::DIEInfo &MyInfo,
384 unsigned shouldKeepVariableDIE(const DWARFDebugInfoEntryMinimal &DIE,
386 CompileUnit::DIEInfo &MyInfo, unsigned Flags);
388 unsigned shouldKeepSubprogramDIE(const DWARFDebugInfoEntryMinimal &DIE,
390 CompileUnit::DIEInfo &MyInfo,
393 bool hasValidRelocation(uint32_t StartOffset, uint32_t EndOffset,
394 CompileUnit::DIEInfo &Info);
397 /// \defgroup Linking Methods used to link the debug information
400 /// \brief Recursively clone \p InputDIE into an tree of DIE objects
401 /// where useless (as decided by lookForDIEsToKeep()) bits have been
402 /// stripped out and addresses have been rewritten according to the
405 /// \param OutOffset is the offset the cloned DIE in the output
408 /// \returns the root of the cloned tree.
409 DIE *cloneDIE(const DWARFDebugInfoEntryMinimal &InputDIE, CompileUnit &U,
412 typedef DWARFAbbreviationDeclaration::AttributeSpec AttributeSpec;
414 /// \brief Helper for cloneDIE.
415 unsigned cloneAttribute(DIE &Die, const DWARFDebugInfoEntryMinimal &InputDIE,
416 CompileUnit &U, const DWARFFormValue &Val,
417 const AttributeSpec AttrSpec, unsigned AttrSize);
419 /// \brief Helper for cloneDIE.
420 unsigned cloneStringAttribute(DIE &Die, AttributeSpec AttrSpec);
422 /// \brief Helper for cloneDIE.
423 unsigned cloneDieReferenceAttribute(DIE &Die, AttributeSpec AttrSpec,
426 /// \brief Helper for cloneDIE.
427 unsigned cloneBlockAttribute(DIE &Die, AttributeSpec AttrSpec,
428 const DWARFFormValue &Val, unsigned AttrSize);
430 /// \brief Helper for cloneDIE.
431 unsigned cloneScalarAttribute(DIE &Die,
432 const DWARFDebugInfoEntryMinimal &InputDIE,
433 const DWARFUnit &U, AttributeSpec AttrSpec,
434 const DWARFFormValue &Val, unsigned AttrSize);
436 /// \brief Assign an abbreviation number to \p Abbrev
437 void AssignAbbrev(DIEAbbrev &Abbrev);
439 /// \brief FoldingSet that uniques the abbreviations.
440 FoldingSet<DIEAbbrev> AbbreviationsSet;
441 /// \brief Storage for the unique Abbreviations.
442 /// This is passed to AsmPrinter::emitDwarfAbbrevs(), thus it cannot
443 /// be changed to a vecot of unique_ptrs.
444 std::vector<DIEAbbrev *> Abbreviations;
446 /// \brief DIELoc objects that need to be destructed (but not freed!).
447 std::vector<DIELoc *> DIELocs;
448 /// \brief DIEBlock objects that need to be destructed (but not freed!).
449 std::vector<DIEBlock *> DIEBlocks;
450 /// \brief Allocator used for all the DIEValue objects.
451 BumpPtrAllocator DIEAlloc;
454 /// \defgroup Helpers Various helper methods.
457 const DWARFDebugInfoEntryMinimal *
458 resolveDIEReference(DWARFFormValue &RefValue, const DWARFUnit &Unit,
459 const DWARFDebugInfoEntryMinimal &DIE,
460 CompileUnit *&ReferencedCU);
462 CompileUnit *getUnitForOffset(unsigned Offset);
464 void reportWarning(const Twine &Warning, const DWARFUnit *Unit = nullptr,
465 const DWARFDebugInfoEntryMinimal *DIE = nullptr);
467 bool createStreamer(Triple TheTriple, StringRef OutputFilename);
471 std::string OutputFilename;
473 BinaryHolder BinHolder;
474 std::unique_ptr<DwarfStreamer> Streamer;
476 /// The units of the current debug map object.
477 std::vector<CompileUnit> Units;
479 /// The debug map object curently under consideration.
480 DebugMapObject *CurrentDebugObject;
483 /// \brief Similar to DWARFUnitSection::getUnitForOffset(), but
484 /// returning our CompileUnit object instead.
485 CompileUnit *DwarfLinker::getUnitForOffset(unsigned Offset) {
487 std::upper_bound(Units.begin(), Units.end(), Offset,
488 [](uint32_t LHS, const CompileUnit &RHS) {
489 return LHS < RHS.getOrigUnit().getNextUnitOffset();
491 return CU != Units.end() ? &*CU : nullptr;
494 /// \brief Resolve the DIE attribute reference that has been
495 /// extracted in \p RefValue. The resulting DIE migh be in another
496 /// CompileUnit which is stored into \p ReferencedCU.
497 /// \returns null if resolving fails for any reason.
498 const DWARFDebugInfoEntryMinimal *DwarfLinker::resolveDIEReference(
499 DWARFFormValue &RefValue, const DWARFUnit &Unit,
500 const DWARFDebugInfoEntryMinimal &DIE, CompileUnit *&RefCU) {
501 assert(RefValue.isFormClass(DWARFFormValue::FC_Reference));
502 uint64_t RefOffset = *RefValue.getAsReference(&Unit);
504 if ((RefCU = getUnitForOffset(RefOffset)))
505 if (const auto *RefDie = RefCU->getOrigUnit().getDIEForOffset(RefOffset))
508 reportWarning("could not find referenced DIE", &Unit, &DIE);
512 /// \brief Report a warning to the user, optionaly including
513 /// information about a specific \p DIE related to the warning.
514 void DwarfLinker::reportWarning(const Twine &Warning, const DWARFUnit *Unit,
515 const DWARFDebugInfoEntryMinimal *DIE) {
516 StringRef Context = "<debug map>";
517 if (CurrentDebugObject)
518 Context = CurrentDebugObject->getObjectFilename();
519 warn(Warning, Context);
521 if (!Options.Verbose || !DIE)
524 errs() << " in DIE:\n";
525 DIE->dump(errs(), const_cast<DWARFUnit *>(Unit), 0 /* RecurseDepth */,
529 bool DwarfLinker::createStreamer(Triple TheTriple, StringRef OutputFilename) {
530 if (Options.NoOutput)
533 Streamer = llvm::make_unique<DwarfStreamer>();
534 return Streamer->init(TheTriple, OutputFilename);
537 /// \brief Recursive helper to gather the child->parent relationships in the
538 /// original compile unit.
539 static void gatherDIEParents(const DWARFDebugInfoEntryMinimal *DIE,
540 unsigned ParentIdx, CompileUnit &CU) {
541 unsigned MyIdx = CU.getOrigUnit().getDIEIndex(DIE);
542 CU.getInfo(MyIdx).ParentIdx = ParentIdx;
544 if (DIE->hasChildren())
545 for (auto *Child = DIE->getFirstChild(); Child && !Child->isNULL();
546 Child = Child->getSibling())
547 gatherDIEParents(Child, MyIdx, CU);
550 static bool dieNeedsChildrenToBeMeaningful(uint32_t Tag) {
554 case dwarf::DW_TAG_subprogram:
555 case dwarf::DW_TAG_lexical_block:
556 case dwarf::DW_TAG_subroutine_type:
557 case dwarf::DW_TAG_structure_type:
558 case dwarf::DW_TAG_class_type:
559 case dwarf::DW_TAG_union_type:
562 llvm_unreachable("Invalid Tag");
565 void DwarfLinker::startDebugObject(DWARFContext &Dwarf) {
566 Units.reserve(Dwarf.getNumCompileUnits());
570 void DwarfLinker::endDebugObject() {
574 for (auto *Block : DIEBlocks)
576 for (auto *Loc : DIELocs)
584 /// \brief Iterate over the relocations of the given \p Section and
585 /// store the ones that correspond to debug map entries into the
586 /// ValidRelocs array.
587 void DwarfLinker::findValidRelocsMachO(const object::SectionRef &Section,
588 const object::MachOObjectFile &Obj,
589 const DebugMapObject &DMO) {
591 Section.getContents(Contents);
592 DataExtractor Data(Contents, Obj.isLittleEndian(), 0);
594 for (const object::RelocationRef &Reloc : Section.relocations()) {
595 object::DataRefImpl RelocDataRef = Reloc.getRawDataRefImpl();
596 MachO::any_relocation_info MachOReloc = Obj.getRelocation(RelocDataRef);
597 unsigned RelocSize = 1 << Obj.getAnyRelocationLength(MachOReloc);
599 if ((RelocSize != 4 && RelocSize != 8) || Reloc.getOffset(Offset64)) {
600 reportWarning(" unsupported relocation in debug_info section.");
603 uint32_t Offset = Offset64;
604 // Mach-o uses REL relocations, the addend is at the relocation offset.
605 uint64_t Addend = Data.getUnsigned(&Offset, RelocSize);
607 auto Sym = Reloc.getSymbol();
608 if (Sym != Obj.symbol_end()) {
609 StringRef SymbolName;
610 if (Sym->getName(SymbolName)) {
611 reportWarning("error getting relocation symbol name.");
614 if (const auto *Mapping = DMO.lookupSymbol(SymbolName))
615 ValidRelocs.emplace_back(Offset64, RelocSize, Addend, Mapping);
616 } else if (const auto *Mapping = DMO.lookupObjectAddress(Addend)) {
617 // Do not store the addend. The addend was the address of the
618 // symbol in the object file, the address in the binary that is
619 // stored in the debug map doesn't need to be offseted.
620 ValidRelocs.emplace_back(Offset64, RelocSize, 0, Mapping);
625 /// \brief Dispatch the valid relocation finding logic to the
626 /// appropriate handler depending on the object file format.
627 bool DwarfLinker::findValidRelocs(const object::SectionRef &Section,
628 const object::ObjectFile &Obj,
629 const DebugMapObject &DMO) {
630 // Dispatch to the right handler depending on the file type.
631 if (auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Obj))
632 findValidRelocsMachO(Section, *MachOObj, DMO);
634 reportWarning(Twine("unsupported object file type: ") + Obj.getFileName());
636 if (ValidRelocs.empty())
639 // Sort the relocations by offset. We will walk the DIEs linearly in
640 // the file, this allows us to just keep an index in the relocation
641 // array that we advance during our walk, rather than resorting to
642 // some associative container. See DwarfLinker::NextValidReloc.
643 std::sort(ValidRelocs.begin(), ValidRelocs.end());
647 /// \brief Look for relocations in the debug_info section that match
648 /// entries in the debug map. These relocations will drive the Dwarf
649 /// link by indicating which DIEs refer to symbols present in the
651 /// \returns wether there are any valid relocations in the debug info.
652 bool DwarfLinker::findValidRelocsInDebugInfo(const object::ObjectFile &Obj,
653 const DebugMapObject &DMO) {
654 // Find the debug_info section.
655 for (const object::SectionRef &Section : Obj.sections()) {
656 StringRef SectionName;
657 Section.getName(SectionName);
658 SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
659 if (SectionName != "debug_info")
661 return findValidRelocs(Section, Obj, DMO);
666 /// \brief Checks that there is a relocation against an actual debug
667 /// map entry between \p StartOffset and \p NextOffset.
669 /// This function must be called with offsets in strictly ascending
670 /// order because it never looks back at relocations it already 'went past'.
671 /// \returns true and sets Info.InDebugMap if it is the case.
672 bool DwarfLinker::hasValidRelocation(uint32_t StartOffset, uint32_t EndOffset,
673 CompileUnit::DIEInfo &Info) {
674 assert(NextValidReloc == 0 ||
675 StartOffset > ValidRelocs[NextValidReloc - 1].Offset);
676 if (NextValidReloc >= ValidRelocs.size())
679 uint64_t RelocOffset = ValidRelocs[NextValidReloc].Offset;
681 // We might need to skip some relocs that we didn't consider. For
682 // example the high_pc of a discarded DIE might contain a reloc that
683 // is in the list because it actually corresponds to the start of a
684 // function that is in the debug map.
685 while (RelocOffset < StartOffset && NextValidReloc < ValidRelocs.size() - 1)
686 RelocOffset = ValidRelocs[++NextValidReloc].Offset;
688 if (RelocOffset < StartOffset || RelocOffset >= EndOffset)
691 const auto &ValidReloc = ValidRelocs[NextValidReloc++];
693 outs() << "Found valid debug map entry: " << ValidReloc.Mapping->getKey()
694 << " " << format("\t%016" PRIx64 " => %016" PRIx64,
695 ValidReloc.Mapping->getValue().ObjectAddress,
696 ValidReloc.Mapping->getValue().BinaryAddress);
699 ValidReloc.Mapping->getValue().BinaryAddress + ValidReloc.Addend;
700 Info.InDebugMap = true;
704 /// \brief Get the starting and ending (exclusive) offset for the
705 /// attribute with index \p Idx descibed by \p Abbrev. \p Offset is
706 /// supposed to point to the position of the first attribute described
708 /// \return [StartOffset, EndOffset) as a pair.
709 static std::pair<uint32_t, uint32_t>
710 getAttributeOffsets(const DWARFAbbreviationDeclaration *Abbrev, unsigned Idx,
711 unsigned Offset, const DWARFUnit &Unit) {
712 DataExtractor Data = Unit.getDebugInfoExtractor();
714 for (unsigned i = 0; i < Idx; ++i)
715 DWARFFormValue::skipValue(Abbrev->getFormByIndex(i), Data, &Offset, &Unit);
717 uint32_t End = Offset;
718 DWARFFormValue::skipValue(Abbrev->getFormByIndex(Idx), Data, &End, &Unit);
720 return std::make_pair(Offset, End);
723 /// \brief Check if a variable describing DIE should be kept.
724 /// \returns updated TraversalFlags.
725 unsigned DwarfLinker::shouldKeepVariableDIE(
726 const DWARFDebugInfoEntryMinimal &DIE, CompileUnit &Unit,
727 CompileUnit::DIEInfo &MyInfo, unsigned Flags) {
728 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
730 // Global variables with constant value can always be kept.
731 if (!(Flags & TF_InFunctionScope) &&
732 Abbrev->findAttributeIndex(dwarf::DW_AT_const_value) != -1U) {
733 MyInfo.InDebugMap = true;
734 return Flags | TF_Keep;
737 uint32_t LocationIdx = Abbrev->findAttributeIndex(dwarf::DW_AT_location);
738 if (LocationIdx == -1U)
741 uint32_t Offset = DIE.getOffset() + getULEB128Size(Abbrev->getCode());
742 const DWARFUnit &OrigUnit = Unit.getOrigUnit();
743 uint32_t LocationOffset, LocationEndOffset;
744 std::tie(LocationOffset, LocationEndOffset) =
745 getAttributeOffsets(Abbrev, LocationIdx, Offset, OrigUnit);
747 // See if there is a relocation to a valid debug map entry inside
748 // this variable's location. The order is important here. We want to
749 // always check in the variable has a valid relocation, so that the
750 // DIEInfo is filled. However, we don't want a static variable in a
751 // function to force us to keep the enclosing function.
752 if (!hasValidRelocation(LocationOffset, LocationEndOffset, MyInfo) ||
753 (Flags & TF_InFunctionScope))
757 DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */);
759 return Flags | TF_Keep;
762 /// \brief Check if a function describing DIE should be kept.
763 /// \returns updated TraversalFlags.
764 unsigned DwarfLinker::shouldKeepSubprogramDIE(
765 const DWARFDebugInfoEntryMinimal &DIE, CompileUnit &Unit,
766 CompileUnit::DIEInfo &MyInfo, unsigned Flags) {
767 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
769 Flags |= TF_InFunctionScope;
771 uint32_t LowPcIdx = Abbrev->findAttributeIndex(dwarf::DW_AT_low_pc);
775 uint32_t Offset = DIE.getOffset() + getULEB128Size(Abbrev->getCode());
776 const DWARFUnit &OrigUnit = Unit.getOrigUnit();
777 uint32_t LowPcOffset, LowPcEndOffset;
778 std::tie(LowPcOffset, LowPcEndOffset) =
779 getAttributeOffsets(Abbrev, LowPcIdx, Offset, OrigUnit);
782 DIE.getAttributeValueAsAddress(&OrigUnit, dwarf::DW_AT_low_pc, -1ULL);
783 assert(LowPc != -1ULL && "low_pc attribute is not an address.");
784 if (LowPc == -1ULL ||
785 !hasValidRelocation(LowPcOffset, LowPcEndOffset, MyInfo))
789 DIE.dump(outs(), const_cast<DWARFUnit *>(&OrigUnit), 0, 8 /* Indent */);
791 return Flags | TF_Keep;
794 /// \brief Check if a DIE should be kept.
795 /// \returns updated TraversalFlags.
796 unsigned DwarfLinker::shouldKeepDIE(const DWARFDebugInfoEntryMinimal &DIE,
798 CompileUnit::DIEInfo &MyInfo,
800 switch (DIE.getTag()) {
801 case dwarf::DW_TAG_constant:
802 case dwarf::DW_TAG_variable:
803 return shouldKeepVariableDIE(DIE, Unit, MyInfo, Flags);
804 case dwarf::DW_TAG_subprogram:
805 return shouldKeepSubprogramDIE(DIE, Unit, MyInfo, Flags);
806 case dwarf::DW_TAG_module:
807 case dwarf::DW_TAG_imported_module:
808 case dwarf::DW_TAG_imported_declaration:
809 case dwarf::DW_TAG_imported_unit:
810 // We always want to keep these.
811 return Flags | TF_Keep;
817 /// \brief Mark the passed DIE as well as all the ones it depends on
820 /// This function is called by lookForDIEsToKeep on DIEs that are
821 /// newly discovered to be needed in the link. It recursively calls
822 /// back to lookForDIEsToKeep while adding TF_DependencyWalk to the
823 /// TraversalFlags to inform it that it's not doing the primary DIE
825 void DwarfLinker::keepDIEAndDenpendencies(const DWARFDebugInfoEntryMinimal &DIE,
826 CompileUnit::DIEInfo &MyInfo,
827 const DebugMapObject &DMO,
828 CompileUnit &CU, unsigned Flags) {
829 const DWARFUnit &Unit = CU.getOrigUnit();
832 // First mark all the parent chain as kept.
833 unsigned AncestorIdx = MyInfo.ParentIdx;
834 while (!CU.getInfo(AncestorIdx).Keep) {
835 lookForDIEsToKeep(*Unit.getDIEAtIndex(AncestorIdx), DMO, CU,
836 TF_ParentWalk | TF_Keep | TF_DependencyWalk);
837 AncestorIdx = CU.getInfo(AncestorIdx).ParentIdx;
840 // Then we need to mark all the DIEs referenced by this DIE's
841 // attributes as kept.
842 DataExtractor Data = Unit.getDebugInfoExtractor();
843 const auto *Abbrev = DIE.getAbbreviationDeclarationPtr();
844 uint32_t Offset = DIE.getOffset() + getULEB128Size(Abbrev->getCode());
846 // Mark all DIEs referenced through atttributes as kept.
847 for (const auto &AttrSpec : Abbrev->attributes()) {
848 DWARFFormValue Val(AttrSpec.Form);
850 if (!Val.isFormClass(DWARFFormValue::FC_Reference)) {
851 DWARFFormValue::skipValue(AttrSpec.Form, Data, &Offset, &Unit);
855 Val.extractValue(Data, &Offset, &Unit);
856 CompileUnit *ReferencedCU;
857 if (const auto *RefDIE = resolveDIEReference(Val, Unit, DIE, ReferencedCU))
858 lookForDIEsToKeep(*RefDIE, DMO, *ReferencedCU,
859 TF_Keep | TF_DependencyWalk);
863 /// \brief Recursively walk the \p DIE tree and look for DIEs to
864 /// keep. Store that information in \p CU's DIEInfo.
866 /// This function is the entry point of the DIE selection
867 /// algorithm. It is expected to walk the DIE tree in file order and
868 /// (though the mediation of its helper) call hasValidRelocation() on
869 /// each DIE that might be a 'root DIE' (See DwarfLinker class
871 /// While walking the dependencies of root DIEs, this function is
872 /// also called, but during these dependency walks the file order is
873 /// not respected. The TF_DependencyWalk flag tells us which kind of
874 /// traversal we are currently doing.
875 void DwarfLinker::lookForDIEsToKeep(const DWARFDebugInfoEntryMinimal &DIE,
876 const DebugMapObject &DMO, CompileUnit &CU,
878 unsigned Idx = CU.getOrigUnit().getDIEIndex(&DIE);
879 CompileUnit::DIEInfo &MyInfo = CU.getInfo(Idx);
880 bool AlreadyKept = MyInfo.Keep;
882 // If the Keep flag is set, we are marking a required DIE's
883 // dependencies. If our target is already marked as kept, we're all
885 if ((Flags & TF_DependencyWalk) && AlreadyKept)
888 // We must not call shouldKeepDIE while called from keepDIEAndDenpendencies,
889 // because it would screw up the relocation finding logic.
890 if (!(Flags & TF_DependencyWalk))
891 Flags = shouldKeepDIE(DIE, CU, MyInfo, Flags);
893 // If it is a newly kept DIE mark it as well as all its dependencies as kept.
894 if (!AlreadyKept && (Flags & TF_Keep))
895 keepDIEAndDenpendencies(DIE, MyInfo, DMO, CU, Flags);
897 // The TF_ParentWalk flag tells us that we are currently walking up
898 // the parent chain of a required DIE, and we don't want to mark all
899 // the children of the parents as kept (consider for example a
900 // DW_TAG_namespace node in the parent chain). There are however a
901 // set of DIE types for which we want to ignore that directive and still
902 // walk their children.
903 if (dieNeedsChildrenToBeMeaningful(DIE.getTag()))
904 Flags &= ~TF_ParentWalk;
906 if (!DIE.hasChildren() || (Flags & TF_ParentWalk))
909 for (auto *Child = DIE.getFirstChild(); Child && !Child->isNULL();
910 Child = Child->getSibling())
911 lookForDIEsToKeep(*Child, DMO, CU, Flags);
914 /// \brief Assign an abbreviation numer to \p Abbrev.
916 /// Our DIEs get freed after every DebugMapObject has been processed,
917 /// thus the FoldingSet we use to unique DIEAbbrevs cannot refer to
918 /// the instances hold by the DIEs. When we encounter an abbreviation
919 /// that we don't know, we create a permanent copy of it.
920 void DwarfLinker::AssignAbbrev(DIEAbbrev &Abbrev) {
921 // Check the set for priors.
925 DIEAbbrev *InSet = AbbreviationsSet.FindNodeOrInsertPos(ID, InsertToken);
927 // If it's newly added.
929 // Assign existing abbreviation number.
930 Abbrev.setNumber(InSet->getNumber());
932 // Add to abbreviation list.
933 Abbreviations.push_back(
934 new DIEAbbrev(Abbrev.getTag(), Abbrev.hasChildren()));
935 for (const auto &Attr : Abbrev.getData())
936 Abbreviations.back()->AddAttribute(Attr.getAttribute(), Attr.getForm());
937 AbbreviationsSet.InsertNode(Abbreviations.back(), InsertToken);
938 // Assign the unique abbreviation number.
939 Abbrev.setNumber(Abbreviations.size());
940 Abbreviations.back()->setNumber(Abbreviations.size());
944 /// \brief Clone a string attribute described by \p AttrSpec and add
946 /// \returns the size of the new attribute.
947 unsigned DwarfLinker::cloneStringAttribute(DIE &Die, AttributeSpec AttrSpec) {
948 // Switch everything to out of line strings.
949 // FIXME: Construct the actual string table.
950 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::DW_FORM_strp,
951 new (DIEAlloc) DIEInteger(0));
955 /// \brief Clone an attribute referencing another DIE and add
957 /// \returns the size of the new attribute.
958 unsigned DwarfLinker::cloneDieReferenceAttribute(DIE &Die,
959 AttributeSpec AttrSpec,
961 // FIXME: Handle DIE references.
962 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::Form(AttrSpec.Form),
963 new (DIEAlloc) DIEInteger(0));
967 /// \brief Clone an attribute of block form (locations, constants) and add
969 /// \returns the size of the new attribute.
970 unsigned DwarfLinker::cloneBlockAttribute(DIE &Die, AttributeSpec AttrSpec,
971 const DWARFFormValue &Val,
975 DIELoc *Loc = nullptr;
976 DIEBlock *Block = nullptr;
977 // Just copy the block data over.
978 if (AttrSpec.Attr == dwarf::DW_FORM_exprloc) {
979 Loc = new (DIEAlloc) DIELoc();
980 DIELocs.push_back(Loc);
982 Block = new (DIEAlloc) DIEBlock();
983 DIEBlocks.push_back(Block);
985 Attr = Loc ? static_cast<DIE *>(Loc) : static_cast<DIE *>(Block);
986 Value = Loc ? static_cast<DIEValue *>(Loc) : static_cast<DIEValue *>(Block);
987 ArrayRef<uint8_t> Bytes = *Val.getAsBlock();
988 for (auto Byte : Bytes)
989 Attr->addValue(static_cast<dwarf::Attribute>(0), dwarf::DW_FORM_data1,
990 new (DIEAlloc) DIEInteger(Byte));
991 // FIXME: If DIEBlock and DIELoc just reuses the Size field of
992 // the DIE class, this if could be replaced by
993 // Attr->setSize(Bytes.size()).
996 Loc->ComputeSize(&Streamer->getAsmPrinter());
998 Block->ComputeSize(&Streamer->getAsmPrinter());
1000 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::Form(AttrSpec.Form),
1005 /// \brief Clone a scalar attribute and add it to \p Die.
1006 /// \returns the size of the new attribute.
1007 unsigned DwarfLinker::cloneScalarAttribute(
1008 DIE &Die, const DWARFDebugInfoEntryMinimal &InputDIE, const DWARFUnit &U,
1009 AttributeSpec AttrSpec, const DWARFFormValue &Val, unsigned AttrSize) {
1011 if (AttrSpec.Form == dwarf::DW_FORM_sec_offset)
1012 Value = *Val.getAsSectionOffset();
1013 else if (AttrSpec.Form == dwarf::DW_FORM_sdata)
1014 Value = *Val.getAsSignedConstant();
1015 else if (AttrSpec.Form == dwarf::DW_FORM_addr)
1016 Value = *Val.getAsAddress(&U);
1017 else if (auto OptionalValue = Val.getAsUnsignedConstant())
1018 Value = *OptionalValue;
1020 reportWarning("Unsupported scalar attribute form. Dropping attribute.", &U,
1024 Die.addValue(dwarf::Attribute(AttrSpec.Attr), dwarf::Form(AttrSpec.Form),
1025 new (DIEAlloc) DIEInteger(Value));
1029 /// \brief Clone \p InputDIE's attribute described by \p AttrSpec with
1030 /// value \p Val, and add it to \p Die.
1031 /// \returns the size of the cloned attribute.
1032 unsigned DwarfLinker::cloneAttribute(DIE &Die,
1033 const DWARFDebugInfoEntryMinimal &InputDIE,
1035 const DWARFFormValue &Val,
1036 const AttributeSpec AttrSpec,
1037 unsigned AttrSize) {
1038 const DWARFUnit &U = Unit.getOrigUnit();
1040 switch (AttrSpec.Form) {
1041 case dwarf::DW_FORM_strp:
1042 case dwarf::DW_FORM_string:
1043 return cloneStringAttribute(Die, AttrSpec);
1044 case dwarf::DW_FORM_ref_addr:
1045 case dwarf::DW_FORM_ref1:
1046 case dwarf::DW_FORM_ref2:
1047 case dwarf::DW_FORM_ref4:
1048 case dwarf::DW_FORM_ref8:
1049 return cloneDieReferenceAttribute(Die, AttrSpec, AttrSize);
1050 case dwarf::DW_FORM_block:
1051 case dwarf::DW_FORM_block1:
1052 case dwarf::DW_FORM_block2:
1053 case dwarf::DW_FORM_block4:
1054 case dwarf::DW_FORM_exprloc:
1055 return cloneBlockAttribute(Die, AttrSpec, Val, AttrSize);
1056 case dwarf::DW_FORM_addr:
1057 case dwarf::DW_FORM_data1:
1058 case dwarf::DW_FORM_data2:
1059 case dwarf::DW_FORM_data4:
1060 case dwarf::DW_FORM_data8:
1061 case dwarf::DW_FORM_udata:
1062 case dwarf::DW_FORM_sdata:
1063 case dwarf::DW_FORM_sec_offset:
1064 case dwarf::DW_FORM_flag:
1065 case dwarf::DW_FORM_flag_present:
1066 return cloneScalarAttribute(Die, InputDIE, U, AttrSpec, Val, AttrSize);
1068 reportWarning("Unsupported attribute form in cloneAttribute. Dropping.", &U,
1075 /// \brief Recursively clone \p InputDIE's subtrees that have been
1076 /// selected to appear in the linked output.
1078 /// \param OutOffset is the Offset where the newly created DIE will
1079 /// lie in the linked compile unit.
1081 /// \returns the cloned DIE object or null if nothing was selected.
1082 DIE *DwarfLinker::cloneDIE(const DWARFDebugInfoEntryMinimal &InputDIE,
1083 CompileUnit &Unit, uint32_t OutOffset) {
1084 DWARFUnit &U = Unit.getOrigUnit();
1085 unsigned Idx = U.getDIEIndex(&InputDIE);
1087 // Should the DIE appear in the output?
1088 if (!Unit.getInfo(Idx).Keep)
1091 uint32_t Offset = InputDIE.getOffset();
1093 DIE *Die = new DIE(static_cast<dwarf::Tag>(InputDIE.getTag()));
1094 Die->setOffset(OutOffset);
1096 // Extract and clone every attribute.
1097 DataExtractor Data = U.getDebugInfoExtractor();
1098 const auto *Abbrev = InputDIE.getAbbreviationDeclarationPtr();
1099 Offset += getULEB128Size(Abbrev->getCode());
1101 for (const auto &AttrSpec : Abbrev->attributes()) {
1102 DWARFFormValue Val(AttrSpec.Form);
1103 uint32_t AttrSize = Offset;
1104 Val.extractValue(Data, &Offset, &U);
1105 AttrSize = Offset - AttrSize;
1107 OutOffset += cloneAttribute(*Die, InputDIE, Unit, Val, AttrSpec, AttrSize);
1110 DIEAbbrev &NewAbbrev = Die->getAbbrev();
1111 // If a scope DIE is kept, we must have kept at least one child. If
1112 // it's not the case, we'll just be emitting one wasteful end of
1113 // children marker, but things won't break.
1114 if (InputDIE.hasChildren())
1115 NewAbbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
1116 // Assign a permanent abbrev number
1117 AssignAbbrev(Die->getAbbrev());
1119 // Add the size of the abbreviation number to the output offset.
1120 OutOffset += getULEB128Size(Die->getAbbrevNumber());
1122 if (!Abbrev->hasChildren()) {
1124 Die->setSize(OutOffset - Die->getOffset());
1128 // Recursively clone children.
1129 for (auto *Child = InputDIE.getFirstChild(); Child && !Child->isNULL();
1130 Child = Child->getSibling()) {
1131 if (DIE *Clone = cloneDIE(*Child, Unit, OutOffset)) {
1132 Die->addChild(std::unique_ptr<DIE>(Clone));
1133 OutOffset = Clone->getOffset() + Clone->getSize();
1137 // Account for the end of children marker.
1138 OutOffset += sizeof(int8_t);
1140 Die->setSize(OutOffset - Die->getOffset());
1144 bool DwarfLinker::link(const DebugMap &Map) {
1146 if (Map.begin() == Map.end()) {
1147 errs() << "Empty debug map.\n";
1151 if (!createStreamer(Map.getTriple(), OutputFilename))
1154 // Size of the DIEs (and headers) generated for the linked output.
1155 uint64_t OutputDebugInfoSize = 0;
1157 for (const auto &Obj : Map.objects()) {
1158 CurrentDebugObject = Obj.get();
1160 if (Options.Verbose)
1161 outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n";
1162 auto ErrOrObj = BinHolder.GetObjectFile(Obj->getObjectFilename());
1163 if (std::error_code EC = ErrOrObj.getError()) {
1164 reportWarning(Twine(Obj->getObjectFilename()) + ": " + EC.message());
1168 // Look for relocations that correspond to debug map entries.
1169 if (!findValidRelocsInDebugInfo(*ErrOrObj, *Obj)) {
1170 if (Options.Verbose)
1171 outs() << "No valid relocations found. Skipping.\n";
1175 // Setup access to the debug info.
1176 DWARFContextInMemory DwarfContext(*ErrOrObj);
1177 startDebugObject(DwarfContext);
1179 // In a first phase, just read in the debug info and store the DIE
1180 // parent links that we will use during the next phase.
1181 for (const auto &CU : DwarfContext.compile_units()) {
1182 auto *CUDie = CU->getCompileUnitDIE(false);
1183 if (Options.Verbose) {
1184 outs() << "Input compilation unit:";
1185 CUDie->dump(outs(), CU.get(), 0);
1187 Units.emplace_back(*CU);
1188 gatherDIEParents(CUDie, 0, Units.back());
1191 // Then mark all the DIEs that need to be present in the linked
1192 // output and collect some information about them. Note that this
1193 // loop can not be merged with the previous one becaue cross-cu
1194 // references require the ParentIdx to be setup for every CU in
1195 // the object file before calling this.
1196 for (auto &CurrentUnit : Units)
1197 lookForDIEsToKeep(*CurrentUnit.getOrigUnit().getCompileUnitDIE(), *Obj,
1200 // Construct the output DIE tree by cloning the DIEs we chose to
1201 // keep above. If there are no valid relocs, then there's nothing
1203 if (!ValidRelocs.empty())
1204 for (auto &CurrentUnit : Units) {
1205 const auto *InputDIE = CurrentUnit.getOrigUnit().getCompileUnitDIE();
1207 cloneDIE(*InputDIE, CurrentUnit, 11 /* Unit Header size */);
1208 CurrentUnit.setOutputUnitDIE(OutputDIE);
1209 OutputDebugInfoSize = CurrentUnit.computeOffsets(OutputDebugInfoSize);
1212 // Emit all the compile unit's debug information.
1213 if (!ValidRelocs.empty() && !Options.NoOutput)
1214 for (auto &CurrentUnit : Units) {
1215 Streamer->emitCompileUnitHeader(CurrentUnit);
1216 if (!CurrentUnit.getOutputUnitDIE())
1218 Streamer->emitDIE(*CurrentUnit.getOutputUnitDIE());
1221 // Clean-up before starting working on the next object.
1225 // Emit everything that's global.
1226 if (!Options.NoOutput)
1227 Streamer->emitAbbrevs(Abbreviations);
1229 return Options.NoOutput ? true : Streamer->finish();
1233 bool linkDwarf(StringRef OutputFilename, const DebugMap &DM,
1234 const LinkOptions &Options) {
1235 DwarfLinker Linker(OutputFilename, Options);
1236 return Linker.link(DM);