LLVM 18.0.0git
DWARFLinker.h
Go to the documentation of this file.
1//===- DWARFLinker.h --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DWARFLINKER_DWARFLINKER_H
10#define LLVM_DWARFLINKER_DWARFLINKER_H
11
13#include "llvm/ADT/DenseMap.h"
22#include <map>
23
24namespace llvm {
25class DWARFExpression;
26class DWARFUnit;
27class DataExtractor;
28class DeclContextTree;
29template <typename T> class SmallVectorImpl;
30
32
33/// AddressesMap represents information about valid addresses used
34/// by debug information. Valid addresses are those which points to
35/// live code sections. i.e. relocations for these addresses point
36/// into sections which would be/are placed into resulting binary.
38public:
39 virtual ~AddressesMap();
40
41 /// Checks that there are valid relocations against a .debug_info
42 /// section.
43 virtual bool hasValidRelocs() = 0;
44
45 /// Checks that the specified DWARF expression operand \p Op references live
46 /// code section and returns the relocation adjustment value (to get the
47 /// linked address this value might be added to the source expression operand
48 /// address).
49 /// \returns relocation adjustment value or std::nullopt if there is no
50 /// corresponding live address.
51 virtual std::optional<int64_t>
54 uint64_t StartOffset, uint64_t EndOffset) = 0;
55
56 /// Checks that the specified subprogram \p DIE references the live code
57 /// section and returns the relocation adjustment value (to get the linked
58 /// address this value might be added to the source subprogram address).
59 /// Allowed kinds of input DIE: DW_TAG_subprogram, DW_TAG_label.
60 /// \returns relocation adjustment value or std::nullopt if there is no
61 /// corresponding live address.
62 virtual std::optional<int64_t>
64
65 /// Returns the file name associated to the AddessesMap
66 virtual std::optional<StringRef> getLibraryInstallName() = 0;
67
68 /// Apply the valid relocations to the buffer \p Data, taking into
69 /// account that Data is at \p BaseOffset in the .debug_info section.
70 ///
71 /// \returns true whether any reloc has been applied.
73 bool IsLittleEndian) = 0;
74
75 /// Check if the linker needs to gather and save relocation info.
76 virtual bool needToSaveValidRelocs() = 0;
77
78 /// Update and save original relocations located in between StartOffset and
79 /// EndOffset. LinkedOffset is the value which should be added to the original
80 /// relocation offset to get new relocation offset in linked binary.
81 virtual void updateAndSaveValidRelocs(bool IsDWARF5,
82 uint64_t OriginalUnitOffset,
83 int64_t LinkedOffset,
84 uint64_t StartOffset,
85 uint64_t EndOffset) = 0;
86
87 /// Update the valid relocations that used OriginalUnitOffset as the compile
88 /// unit offset, and update their values to reflect OutputUnitOffset.
89 virtual void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset,
90 uint64_t OutputUnitOffset) = 0;
91
92 /// Erases all data.
93 virtual void clear() = 0;
94};
95
97
101
104 if (It == DieValueMap.end()) {
105 It = DieValueMap.insert(std::make_pair(Value, DieValues.size())).first;
107 }
108 return It->second;
109 }
110
111 void clear() {
114 }
115};
116
117/// DwarfEmitter presents interface to generate all debug info tables.
119public:
120 virtual ~DwarfEmitter();
121
122 /// Emit section named SecName with data SecData.
123 virtual void emitSectionContents(StringRef SecData, StringRef SecName) = 0;
124
125 /// Emit the abbreviation table \p Abbrevs to the .debug_abbrev section.
126 virtual void
127 emitAbbrevs(const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
128 unsigned DwarfVersion) = 0;
129
130 /// Emit the string table described by \p Pool into .debug_str table.
131 virtual void emitStrings(const NonRelocatableStringpool &Pool) = 0;
132
133 /// Emit the debug string offset table described by \p StringOffsets into the
134 /// .debug_str_offsets table.
135 virtual void emitStringOffsets(const SmallVector<uint64_t> &StringOffsets,
136 uint16_t TargetDWARFVersion) = 0;
137
138 /// Emit the string table described by \p Pool into .debug_line_str table.
139 virtual void emitLineStrings(const NonRelocatableStringpool &Pool) = 0;
140
141 /// Emit DWARF debug names.
142 virtual void emitDebugNames(DWARF5AccelTable &Table) = 0;
143
144 /// Emit Apple namespaces accelerator table.
145 virtual void
147
148 /// Emit Apple names accelerator table.
149 virtual void
151
152 /// Emit Apple Objective-C accelerator table.
153 virtual void
155
156 /// Emit Apple type accelerator table.
157 virtual void
159
160 /// Emit debug ranges (.debug_ranges, .debug_rnglists) header.
162
163 /// Emit debug ranges (.debug_ranges, .debug_rnglists) fragment.
165 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
166 PatchLocation Patch, DebugDieValuePool &AddrPool) = 0;
167
168 /// Emit debug ranges (.debug_ranges, .debug_rnglists) footer.
170 MCSymbol *EndLabel) = 0;
171
172 /// Emit debug locations (.debug_loc, .debug_loclists) header.
174
175 /// Emit debug locations (.debug_loc, .debug_loclists) fragment.
177 const CompileUnit &Unit,
178 const DWARFLocationExpressionsVector &LinkedLocationExpression,
179 PatchLocation Patch, DebugDieValuePool &AddrPool) = 0;
180
181 /// Emit debug locations (.debug_loc, .debug_loclists) footer.
182 virtual void emitDwarfDebugLocListFooter(const CompileUnit &Unit,
183 MCSymbol *EndLabel) = 0;
184
185 /// Emit .debug_addr header.
187
188 /// Emit the addresses described by \p Addrs into the .debug_addr section.
190 uint8_t AddrSize) = 0;
191
192 /// Emit .debug_addr footer.
193 virtual void emitDwarfDebugAddrsFooter(const CompileUnit &Unit,
194 MCSymbol *EndLabel) = 0;
195
196 /// Emit .debug_aranges entries for \p Unit
197 virtual void
199 const AddressRanges &LinkedRanges) = 0;
200
201 /// Emit specified \p LineTable into .debug_line table.
202 virtual void emitLineTableForUnit(const DWARFDebugLine::LineTable &LineTable,
203 const CompileUnit &Unit,
204 OffsetsStringPool &DebugStrPool,
205 OffsetsStringPool &DebugLineStrPool) = 0;
206
207 /// Emit the .debug_pubnames contribution for \p Unit.
208 virtual void emitPubNamesForUnit(const CompileUnit &Unit) = 0;
209
210 /// Emit the .debug_pubtypes contribution for \p Unit.
211 virtual void emitPubTypesForUnit(const CompileUnit &Unit) = 0;
212
213 /// Emit a CIE.
214 virtual void emitCIE(StringRef CIEBytes) = 0;
215
216 /// Emit an FDE with data \p Bytes.
217 virtual void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint64_t Address,
218 StringRef Bytes) = 0;
219
220 /// Emit the compilation unit header for \p Unit in the
221 /// .debug_info section.
222 ///
223 /// As a side effect, this also switches the current Dwarf version
224 /// of the MC layer to the one of U.getOrigUnit().
226 unsigned DwarfVersion) = 0;
227
228 /// Recursively emit the DIE tree rooted at \p Die.
229 virtual void emitDIE(DIE &Die) = 0;
230
231 /// Emit all available macro tables(DWARFv4 and DWARFv5).
232 /// Use \p UnitMacroMap to get compilation unit by macro table offset.
233 /// Side effects: Fill \p StringPool with macro strings, update
234 /// DW_AT_macro_info, DW_AT_macros attributes for corresponding compile
235 /// units.
236 virtual void emitMacroTables(DWARFContext *Context,
237 const Offset2UnitMap &UnitMacroMap,
238 OffsetsStringPool &StringPool) = 0;
239
240 /// Returns size of generated .debug_line section.
241 virtual uint64_t getLineSectionSize() const = 0;
242
243 /// Returns size of generated .debug_frame section.
244 virtual uint64_t getFrameSectionSize() const = 0;
245
246 /// Returns size of generated .debug_ranges section.
247 virtual uint64_t getRangesSectionSize() const = 0;
248
249 /// Returns size of generated .debug_rnglists section.
250 virtual uint64_t getRngListsSectionSize() const = 0;
251
252 /// Returns size of generated .debug_info section.
254
255 /// Returns size of generated .debug_macinfo section.
257
258 /// Returns size of generated .debug_macro section.
260
261 /// Returns size of generated .debug_loclists section.
262 virtual uint64_t getLocListsSectionSize() const = 0;
263
264 /// Returns size of generated .debug_addr section.
266
267 /// Dump the file to the disk.
268 virtual void finish() = 0;
269
270 /// Emit the swift_ast section stored in \p Buffer.
271 virtual void emitSwiftAST(StringRef Buffer) = 0;
272
273 /// Emit the swift reflection section stored in \p Buffer.
276 StringRef Buffer, uint32_t Alignment, uint32_t Size) = 0;
277
278 /// Returns underlying AsmPrinter.
279 virtual AsmPrinter &getAsmPrinter() const = 0;
280};
281
282class DwarfStreamer;
283using UnitListTy = std::vector<std::unique_ptr<CompileUnit>>;
284
285/// This class represents DWARF information for source file
286/// and its address map.
288public:
289 using UnloadCallbackTy = std::function<void(StringRef FileName)>;
290 DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
291 std::unique_ptr<AddressesMap> Addresses,
295
296 /// The object file name.
298
299 /// The source DWARF information.
300 std::unique_ptr<DWARFContext> Dwarf;
301
302 /// Helpful address information(list of valid address ranges, relocations).
303 std::unique_ptr<AddressesMap> Addresses;
304
305 /// Callback to the module keeping object file to unload.
307
308 /// Unloads object file and corresponding AddressesMap and Dwarf Context.
309 void unload() {
310 Addresses.reset();
311 Dwarf.reset();
312
313 if (UnloadFunc)
315 }
316};
317
318typedef std::map<std::string, std::string> swiftInterfacesMap;
319typedef std::map<std::string, std::string> objectPrefixMap;
320
321typedef function_ref<void(const DWARFUnit &Unit)> CompileUnitHandler;
322
323/// The core of the Dwarf linking logic.
324///
325/// The generation of the dwarf information from the object files will be
326/// driven by the selection of 'root DIEs', which are DIEs that
327/// describe variables or functions that resolves to the corresponding
328/// code section(and thus have entries in the Addresses map). All the debug
329/// information that will be generated(the DIEs, but also the line
330/// tables, ranges, ...) is derived from that set of root DIEs.
331///
332/// The root DIEs are identified because they contain relocations that
333/// points to code section(the low_pc for a function, the location for
334/// a variable). These relocations are called ValidRelocs in the
335/// AddressesInfo and are gathered as a very first step when we start
336/// processing a object file.
338public:
339 typedef std::function<void(const Twine &Warning, StringRef Context,
340 const DWARFDie *DIE)>
342 DWARFLinker(messageHandler ErrorHandler, messageHandler WarningHandler,
343 std::function<StringRef(StringRef)> StringsTranslator)
344 : DwarfLinkerClientID(DwarfLinkerClient::Dsymutil),
345 StringsTranslator(StringsTranslator), ErrorHandler(ErrorHandler),
346 WarningHandler(WarningHandler) {}
347
348 static std::unique_ptr<DWARFLinker> createLinker(
349 messageHandler ErrorHandler, messageHandler WarningHandler,
350 std::function<StringRef(StringRef)> StringsTranslator = nullptr) {
351 return std::make_unique<DWARFLinker>(ErrorHandler, WarningHandler,
352 StringsTranslator);
353 }
354
355 /// Type of output file.
356 enum class OutputFileType {
357 Object,
358 Assembly,
359 };
360
361 /// The kind of accelerator tables we should emit.
362 enum class AccelTableKind : uint8_t {
363 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
364 Pub, ///< .debug_pubnames, .debug_pubtypes
365 DebugNames ///< .debug_names.
366 };
367 typedef std::function<void(const DWARFFile &File, llvm::StringRef Output)> inputVerificationHandler;
368 typedef std::function<ErrorOr<DWARFFile &>(StringRef ContainerName,
369 StringRef Path)>
371
372 Error createEmitter(const Triple &TheTriple, OutputFileType FileType,
373 raw_pwrite_stream &OutFile);
374
376
377 /// Add object file to be linked. Pre-load compile unit die. Call
378 /// \p OnCUDieLoaded for each compile unit die. If specified \p File
379 /// has reference to the Clang module then such module would be
380 /// pre-loaded by \p Loader for !Update case.
381 ///
382 /// \pre NoODR, Update options should be set before call to addObjectFile.
383 void addObjectFile(
384 DWARFFile &File, objFileLoader Loader = nullptr,
385 CompileUnitHandler OnCUDieLoaded = [](const DWARFUnit &) {});
386
387 /// Link debug info for added objFiles. Object files are linked all together.
388 Error link();
389
390 /// A number of methods setting various linking options:
391
392 /// Allows to generate log of linking process to the standard output.
393 void setVerbosity(bool Verbose) { Options.Verbose = Verbose; }
394
395 /// Print statistics to standard output.
396 void setStatistics(bool Statistics) { Options.Statistics = Statistics; }
397
398 /// Verify the input DWARF.
399 void setVerifyInputDWARF(bool Verify) { Options.VerifyInputDWARF = Verify; }
400
401 /// Do not unique types according to ODR.
402 void setNoODR(bool NoODR) { Options.NoODR = NoODR; }
403
404 /// Update index tables only(do not modify rest of DWARF).
405 void setUpdateIndexTablesOnly(bool Update) { Options.Update = Update; }
406
407 /// Allow generating valid, but non-deterministic output.
408 void setAllowNonDeterministicOutput(bool) { /* Nothing to do. */
409 }
410
411 /// Set whether to keep the enclosing function for a static variable.
412 void setKeepFunctionForStatic(bool KeepFunctionForStatic) {
413 Options.KeepFunctionForStatic = KeepFunctionForStatic;
414 }
415
416 /// Use specified number of threads for parallel files linking.
417 void setNumThreads(unsigned NumThreads) { Options.Threads = NumThreads; }
418
419 /// Add kind of accelerator tables to be generated.
421 assert(!llvm::is_contained(Options.AccelTables, Kind));
422 Options.AccelTables.emplace_back(Kind);
423 }
424
425 /// Set prepend path for clang modules.
426 void setPrependPath(const std::string &Ppath) { Options.PrependPath = Ppath; }
427
428 /// Set estimated objects files amount, for preliminary data allocation.
429 void setEstimatedObjfilesAmount(unsigned ObjFilesNum) {
430 ObjectContexts.reserve(ObjFilesNum);
431 }
432
433 /// Set verification handler which would be used to report verification
434 /// errors.
436 Options.InputVerificationHandler = Handler;
437 }
438
439 /// Set map for Swift interfaces.
441 Options.ParseableSwiftInterfaces = Map;
442 }
443
444 /// Set prefix map for objects.
446 Options.ObjectPrefixMap = Map;
447 }
448
449 /// Set target DWARF version.
451 if ((TargetDWARFVersion < 1) || (TargetDWARFVersion > 5))
452 return createStringError(std::errc::invalid_argument,
453 "unsupported DWARF version: %d",
454 TargetDWARFVersion);
455
456 Options.TargetDWARFVersion = TargetDWARFVersion;
457 return Error::success();
458 }
459
460private:
461 /// Flags passed to DwarfLinker::lookForDIEsToKeep
462 enum TraversalFlags {
463 TF_Keep = 1 << 0, ///< Mark the traversed DIEs as kept.
464 TF_InFunctionScope = 1 << 1, ///< Current scope is a function scope.
465 TF_DependencyWalk = 1 << 2, ///< Walking the dependencies of a kept DIE.
466 TF_ParentWalk = 1 << 3, ///< Walking up the parents of a kept DIE.
467 TF_ODR = 1 << 4, ///< Use the ODR while keeping dependents.
468 TF_SkipPC = 1 << 5, ///< Skip all location attributes.
469 };
470
471 /// The distinct types of work performed by the work loop.
472 enum class WorklistItemType {
473 /// Given a DIE, look for DIEs to be kept.
474 LookForDIEsToKeep,
475 /// Given a DIE, look for children of this DIE to be kept.
476 LookForChildDIEsToKeep,
477 /// Given a DIE, look for DIEs referencing this DIE to be kept.
478 LookForRefDIEsToKeep,
479 /// Given a DIE, look for parent DIEs to be kept.
480 LookForParentDIEsToKeep,
481 /// Given a DIE, update its incompleteness based on whether its children are
482 /// incomplete.
483 UpdateChildIncompleteness,
484 /// Given a DIE, update its incompleteness based on whether the DIEs it
485 /// references are incomplete.
486 UpdateRefIncompleteness,
487 /// Given a DIE, mark it as ODR Canonical if applicable.
488 MarkODRCanonicalDie,
489 };
490
491 /// This class represents an item in the work list. The type defines what kind
492 /// of work needs to be performed when processing the current item. The flags
493 /// and info fields are optional based on the type.
494 struct WorklistItem {
495 DWARFDie Die;
496 WorklistItemType Type;
497 CompileUnit &CU;
498 unsigned Flags;
499 union {
500 const unsigned AncestorIdx;
501 CompileUnit::DIEInfo *OtherInfo;
502 };
503
504 WorklistItem(DWARFDie Die, CompileUnit &CU, unsigned Flags,
505 WorklistItemType T = WorklistItemType::LookForDIEsToKeep)
506 : Die(Die), Type(T), CU(CU), Flags(Flags), AncestorIdx(0) {}
507
508 WorklistItem(DWARFDie Die, CompileUnit &CU, WorklistItemType T,
509 CompileUnit::DIEInfo *OtherInfo = nullptr)
510 : Die(Die), Type(T), CU(CU), Flags(0), OtherInfo(OtherInfo) {}
511
512 WorklistItem(unsigned AncestorIdx, CompileUnit &CU, unsigned Flags)
513 : Type(WorklistItemType::LookForParentDIEsToKeep), CU(CU), Flags(Flags),
514 AncestorIdx(AncestorIdx) {}
515 };
516
517 /// Verify the given DWARF file.
518 void verifyInput(const DWARFFile &File);
519
520 /// returns true if we need to translate strings.
521 bool needToTranslateStrings() { return StringsTranslator != nullptr; }
522
523 void reportWarning(const Twine &Warning, const DWARFFile &File,
524 const DWARFDie *DIE = nullptr) const {
525 if (WarningHandler != nullptr)
526 WarningHandler(Warning, File.FileName, DIE);
527 }
528
529 void reportError(const Twine &Warning, const DWARFFile &File,
530 const DWARFDie *DIE = nullptr) const {
531 if (ErrorHandler != nullptr)
532 ErrorHandler(Warning, File.FileName, DIE);
533 }
534
535 void copyInvariantDebugSection(DWARFContext &Dwarf);
536
537 /// Keep information for referenced clang module: already loaded DWARF info
538 /// of the clang module and a CompileUnit of the module.
539 struct RefModuleUnit {
540 RefModuleUnit(DWARFFile &File, std::unique_ptr<CompileUnit> Unit)
541 : File(File), Unit(std::move(Unit)) {}
542 RefModuleUnit(RefModuleUnit &&Other)
543 : File(Other.File), Unit(std::move(Other.Unit)) {}
544 RefModuleUnit(const RefModuleUnit &) = delete;
545
546 DWARFFile &File;
547 std::unique_ptr<CompileUnit> Unit;
548 };
549 using ModuleUnitListTy = std::vector<RefModuleUnit>;
550
551 /// Keeps track of data associated with one object during linking.
552 struct LinkContext {
553 DWARFFile &File;
554 UnitListTy CompileUnits;
555 ModuleUnitListTy ModuleUnits;
556 bool Skip = false;
557
558 LinkContext(DWARFFile &File) : File(File) {}
559
560 /// Clear part of the context that's no longer needed when we're done with
561 /// the debug object.
562 void clear() {
563 CompileUnits.clear();
564 ModuleUnits.clear();
565 File.unload();
566 }
567 };
568
569 /// Called before emitting object data
570 void cleanupAuxiliarryData(LinkContext &Context);
571
572 /// Look at the parent of the given DIE and decide whether they should be
573 /// kept.
574 void lookForParentDIEsToKeep(unsigned AncestorIdx, CompileUnit &CU,
575 unsigned Flags,
576 SmallVectorImpl<WorklistItem> &Worklist);
577
578 /// Look at the children of the given DIE and decide whether they should be
579 /// kept.
580 void lookForChildDIEsToKeep(const DWARFDie &Die, CompileUnit &CU,
581 unsigned Flags,
582 SmallVectorImpl<WorklistItem> &Worklist);
583
584 /// Look at DIEs referenced by the given DIE and decide whether they should be
585 /// kept. All DIEs referenced though attributes should be kept.
586 void lookForRefDIEsToKeep(const DWARFDie &Die, CompileUnit &CU,
587 unsigned Flags, const UnitListTy &Units,
588 const DWARFFile &File,
589 SmallVectorImpl<WorklistItem> &Worklist);
590
591 /// Mark context corresponding to the specified \p Die as having canonical
592 /// die, if applicable.
593 void markODRCanonicalDie(const DWARFDie &Die, CompileUnit &CU);
594
595 /// \defgroup FindRootDIEs Find DIEs corresponding to Address map entries.
596 ///
597 /// @{
598 /// Recursively walk the \p DIE tree and look for DIEs to
599 /// keep. Store that information in \p CU's DIEInfo.
600 ///
601 /// The return value indicates whether the DIE is incomplete.
602 void lookForDIEsToKeep(AddressesMap &RelocMgr, const UnitListTy &Units,
603 const DWARFDie &DIE, const DWARFFile &File,
604 CompileUnit &CU, unsigned Flags);
605
606 /// Check whether specified \p CUDie is a Clang module reference.
607 /// if \p Quiet is false then display error messages.
608 /// \return first == true if CUDie is a Clang module reference.
609 /// second == true if module is already loaded.
610 std::pair<bool, bool> isClangModuleRef(const DWARFDie &CUDie,
611 std::string &PCMFile,
612 LinkContext &Context, unsigned Indent,
613 bool Quiet);
614
615 /// If this compile unit is really a skeleton CU that points to a
616 /// clang module, register it in ClangModules and return true.
617 ///
618 /// A skeleton CU is a CU without children, a DW_AT_gnu_dwo_name
619 /// pointing to the module, and a DW_AT_gnu_dwo_id with the module
620 /// hash.
621 bool registerModuleReference(const DWARFDie &CUDie, LinkContext &Context,
622 objFileLoader Loader,
623 CompileUnitHandler OnCUDieLoaded,
624 unsigned Indent = 0);
625
626 /// Recursively add the debug info in this clang module .pcm
627 /// file (and all the modules imported by it in a bottom-up fashion)
628 /// to ModuleUnits.
629 Error loadClangModule(objFileLoader Loader, const DWARFDie &CUDie,
630 const std::string &PCMFile, LinkContext &Context,
631 CompileUnitHandler OnCUDieLoaded, unsigned Indent = 0);
632
633 /// Clone specified Clang module unit \p Unit.
634 Error cloneModuleUnit(LinkContext &Context, RefModuleUnit &Unit,
635 DeclContextTree &ODRContexts,
636 OffsetsStringPool &DebugStrPool,
637 OffsetsStringPool &DebugLineStrPool,
638 DebugDieValuePool &StringOffsetPool,
639 unsigned Indent = 0);
640
641 unsigned shouldKeepDIE(AddressesMap &RelocMgr, const DWARFDie &DIE,
642 const DWARFFile &File, CompileUnit &Unit,
643 CompileUnit::DIEInfo &MyInfo, unsigned Flags);
644
645 /// This function checks whether variable has DWARF expression containing
646 /// operation referencing live address(f.e. DW_OP_addr, DW_OP_addrx...).
647 /// \returns first is true if the expression has an operation referencing an
648 /// address.
649 /// second is the relocation adjustment value if the live address is
650 /// referenced.
651 std::pair<bool, std::optional<int64_t>>
652 getVariableRelocAdjustment(AddressesMap &RelocMgr, const DWARFDie &DIE);
653
654 /// Check if a variable describing DIE should be kept.
655 /// \returns updated TraversalFlags.
656 unsigned shouldKeepVariableDIE(AddressesMap &RelocMgr, const DWARFDie &DIE,
657 CompileUnit::DIEInfo &MyInfo, unsigned Flags);
658
659 unsigned shouldKeepSubprogramDIE(AddressesMap &RelocMgr, const DWARFDie &DIE,
660 const DWARFFile &File, CompileUnit &Unit,
661 CompileUnit::DIEInfo &MyInfo,
662 unsigned Flags);
663
664 /// Resolve the DIE attribute reference that has been extracted in \p
665 /// RefValue. The resulting DIE might be in another CompileUnit which is
666 /// stored into \p ReferencedCU. \returns null if resolving fails for any
667 /// reason.
668 DWARFDie resolveDIEReference(const DWARFFile &File, const UnitListTy &Units,
669 const DWARFFormValue &RefValue,
670 const DWARFDie &DIE, CompileUnit *&RefCU);
671
672 /// @}
673
674 /// \defgroup Methods used to link the debug information
675 ///
676 /// @{
677
678 struct DWARFLinkerOptions;
679
680 class DIECloner {
681 DWARFLinker &Linker;
682 DwarfEmitter *Emitter;
683 DWARFFile &ObjFile;
684 OffsetsStringPool &DebugStrPool;
685 OffsetsStringPool &DebugLineStrPool;
686 DebugDieValuePool &StringOffsetPool;
687 DebugDieValuePool AddrPool;
688
689 /// Allocator used for all the DIEValue objects.
690 BumpPtrAllocator &DIEAlloc;
691
692 std::vector<std::unique_ptr<CompileUnit>> &CompileUnits;
693
694 /// Keeps mapping from offset of the macro table to corresponding
695 /// compile unit.
696 Offset2UnitMap UnitMacroMap;
697
698 bool Update;
699
700 public:
701 DIECloner(DWARFLinker &Linker, DwarfEmitter *Emitter, DWARFFile &ObjFile,
702 BumpPtrAllocator &DIEAlloc,
703 std::vector<std::unique_ptr<CompileUnit>> &CompileUnits,
704 bool Update, OffsetsStringPool &DebugStrPool,
705 OffsetsStringPool &DebugLineStrPool,
706 DebugDieValuePool &StringOffsetPool)
707 : Linker(Linker), Emitter(Emitter), ObjFile(ObjFile),
708 DebugStrPool(DebugStrPool), DebugLineStrPool(DebugLineStrPool),
709 StringOffsetPool(StringOffsetPool), DIEAlloc(DIEAlloc),
710 CompileUnits(CompileUnits), Update(Update) {}
711
712 /// Recursively clone \p InputDIE into an tree of DIE objects
713 /// where useless (as decided by lookForDIEsToKeep()) bits have been
714 /// stripped out and addresses have been rewritten according to the
715 /// address map.
716 ///
717 /// \param OutOffset is the offset the cloned DIE in the output
718 /// compile unit.
719 /// \param PCOffset (while cloning a function scope) is the offset
720 /// applied to the entry point of the function to get the linked address.
721 /// \param Die the output DIE to use, pass NULL to create one.
722 /// \returns the root of the cloned tree or null if nothing was selected.
723 DIE *cloneDIE(const DWARFDie &InputDIE, const DWARFFile &File,
724 CompileUnit &U, int64_t PCOffset, uint32_t OutOffset,
725 unsigned Flags, bool IsLittleEndian, DIE *Die = nullptr);
726
727 /// Construct the output DIE tree by cloning the DIEs we
728 /// chose to keep above. If there are no valid relocs, then there's
729 /// nothing to clone/emit.
730 uint64_t cloneAllCompileUnits(DWARFContext &DwarfContext,
731 const DWARFFile &File, bool IsLittleEndian);
732
733 /// Emit the .debug_addr section for the \p Unit.
734 void emitDebugAddrSection(CompileUnit &Unit,
735 const uint16_t DwarfVersion) const;
736
737 using ExpressionHandlerRef = function_ref<void(
738 SmallVectorImpl<uint8_t> &, SmallVectorImpl<uint8_t> &,
739 int64_t AddrRelocAdjustment)>;
740
741 /// Compute and emit debug locations (.debug_loc, .debug_loclists)
742 /// for \p Unit, patch the attributes referencing it.
743 void generateUnitLocations(CompileUnit &Unit, const DWARFFile &File,
744 ExpressionHandlerRef ExprHandler);
745
746 private:
747 using AttributeSpec = DWARFAbbreviationDeclaration::AttributeSpec;
748
749 /// Information gathered and exchanged between the various
750 /// clone*Attributes helpers about the attributes of a particular DIE.
751 struct AttributesInfo {
752 /// Names.
753 DwarfStringPoolEntryRef Name, MangledName, NameWithoutTemplate;
754
755 /// Offsets in the string pool.
756 uint32_t NameOffset = 0;
757 uint32_t MangledNameOffset = 0;
758
759 /// Offset to apply to PC addresses inside a function.
760 int64_t PCOffset = 0;
761
762 /// Does the DIE have a low_pc attribute?
763 bool HasLowPc = false;
764
765 /// Does the DIE have a ranges attribute?
766 bool HasRanges = false;
767
768 /// Is this DIE only a declaration?
769 bool IsDeclaration = false;
770
771 /// Is there a DW_AT_str_offsets_base in the CU?
772 bool AttrStrOffsetBaseSeen = false;
773
774 /// Is there a DW_AT_APPLE_origin in the CU?
775 bool HasAppleOrigin = false;
776
777 AttributesInfo() = default;
778 };
779
780 /// Helper for cloneDIE.
781 unsigned cloneAttribute(DIE &Die, const DWARFDie &InputDIE,
782 const DWARFFile &File, CompileUnit &U,
783 const DWARFFormValue &Val,
784 const AttributeSpec AttrSpec, unsigned AttrSize,
785 AttributesInfo &AttrInfo, bool IsLittleEndian);
786
787 /// Clone a string attribute described by \p AttrSpec and add
788 /// it to \p Die.
789 /// \returns the size of the new attribute.
790 unsigned cloneStringAttribute(DIE &Die, AttributeSpec AttrSpec,
791 const DWARFFormValue &Val, const DWARFUnit &U,
792 AttributesInfo &Info);
793
794 /// Clone an attribute referencing another DIE and add
795 /// it to \p Die.
796 /// \returns the size of the new attribute.
797 unsigned cloneDieReferenceAttribute(DIE &Die, const DWARFDie &InputDIE,
798 AttributeSpec AttrSpec,
799 unsigned AttrSize,
800 const DWARFFormValue &Val,
801 const DWARFFile &File,
802 CompileUnit &Unit);
803
804 /// Clone a DWARF expression that may be referencing another DIE.
805 void cloneExpression(DataExtractor &Data, DWARFExpression Expression,
806 const DWARFFile &File, CompileUnit &Unit,
807 SmallVectorImpl<uint8_t> &OutputBuffer,
808 int64_t AddrRelocAdjustment, bool IsLittleEndian);
809
810 /// Clone an attribute referencing another DIE and add
811 /// it to \p Die.
812 /// \returns the size of the new attribute.
813 unsigned cloneBlockAttribute(DIE &Die, const DWARFDie &InputDIE,
814 const DWARFFile &File, CompileUnit &Unit,
815 AttributeSpec AttrSpec,
816 const DWARFFormValue &Val,
817 bool IsLittleEndian);
818
819 /// Clone an attribute referencing another DIE and add
820 /// it to \p Die.
821 /// \returns the size of the new attribute.
822 unsigned cloneAddressAttribute(DIE &Die, const DWARFDie &InputDIE,
823 AttributeSpec AttrSpec, unsigned AttrSize,
824 const DWARFFormValue &Val,
825 const CompileUnit &Unit,
826 AttributesInfo &Info);
827
828 /// Clone a scalar attribute and add it to \p Die.
829 /// \returns the size of the new attribute.
830 unsigned cloneScalarAttribute(DIE &Die, const DWARFDie &InputDIE,
831 const DWARFFile &File, CompileUnit &U,
832 AttributeSpec AttrSpec,
833 const DWARFFormValue &Val, unsigned AttrSize,
834 AttributesInfo &Info);
835
836 /// Get the potential name and mangled name for the entity
837 /// described by \p Die and store them in \Info if they are not
838 /// already there.
839 /// \returns is a name was found.
840 bool getDIENames(const DWARFDie &Die, AttributesInfo &Info,
841 OffsetsStringPool &StringPool, bool StripTemplate = false);
842
843 uint32_t hashFullyQualifiedName(DWARFDie DIE, CompileUnit &U,
844 const DWARFFile &File,
845 int RecurseDepth = 0);
846
847 /// Helper for cloneDIE.
848 void addObjCAccelerator(CompileUnit &Unit, const DIE *Die,
849 DwarfStringPoolEntryRef Name,
850 OffsetsStringPool &StringPool, bool SkipPubSection);
851
852 void rememberUnitForMacroOffset(CompileUnit &Unit);
853
854 /// Clone and emit the line table for the specified \p Unit.
855 /// Translate directories and file names if necessary.
856 /// Relocate address ranges.
857 void generateLineTableForUnit(CompileUnit &Unit);
858 };
859
860 /// Assign an abbreviation number to \p Abbrev
861 void assignAbbrev(DIEAbbrev &Abbrev);
862
863 /// Compute and emit debug ranges(.debug_aranges, .debug_ranges,
864 /// .debug_rnglists) for \p Unit, patch the attributes referencing it.
865 void generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
866 DebugDieValuePool &AddrPool) const;
867
868 /// Emit the accelerator entries for \p Unit.
869 void emitAcceleratorEntriesForUnit(CompileUnit &Unit);
870
871 /// Patch the frame info for an object file and emit it.
872 void patchFrameInfoForObject(LinkContext &Context);
873
874 /// FoldingSet that uniques the abbreviations.
875 FoldingSet<DIEAbbrev> AbbreviationsSet;
876
877 /// Storage for the unique Abbreviations.
878 /// This is passed to AsmPrinter::emitDwarfAbbrevs(), thus it cannot be
879 /// changed to a vector of unique_ptrs.
880 std::vector<std::unique_ptr<DIEAbbrev>> Abbreviations;
881
882 /// DIELoc objects that need to be destructed (but not freed!).
883 std::vector<DIELoc *> DIELocs;
884
885 /// DIEBlock objects that need to be destructed (but not freed!).
886 std::vector<DIEBlock *> DIEBlocks;
887
888 /// Allocator used for all the DIEValue objects.
889 BumpPtrAllocator DIEAlloc;
890 /// @}
891
892 std::unique_ptr<DwarfStreamer> TheDwarfEmitter;
893 std::vector<LinkContext> ObjectContexts;
894
895 /// The CIEs that have been emitted in the output section. The actual CIE
896 /// data serves a the key to this StringMap, this takes care of comparing the
897 /// semantics of CIEs defined in different object files.
898 StringMap<uint32_t> EmittedCIEs;
899
900 /// Offset of the last CIE that has been emitted in the output
901 /// .debug_frame section.
902 uint32_t LastCIEOffset = 0;
903
904 /// Apple accelerator tables.
905 DWARF5AccelTable DebugNames;
906 AccelTable<AppleAccelTableStaticOffsetData> AppleNames;
907 AccelTable<AppleAccelTableStaticOffsetData> AppleNamespaces;
908 AccelTable<AppleAccelTableStaticOffsetData> AppleObjc;
909 AccelTable<AppleAccelTableStaticTypeData> AppleTypes;
910
911 /// Mapping the PCM filename to the DwoId.
912 StringMap<uint64_t> ClangModules;
913
914 DwarfLinkerClient DwarfLinkerClientID;
915
916 std::function<StringRef(StringRef)> StringsTranslator = nullptr;
917
918 /// A unique ID that identifies each compile unit.
919 unsigned UniqueUnitID = 0;
920
921 // error handler
923
924 // warning handler
925 messageHandler WarningHandler = nullptr;
926
927 /// linking options
928 struct DWARFLinkerOptions {
929 /// DWARF version for the output.
930 uint16_t TargetDWARFVersion = 0;
931
932 /// Generate processing log to the standard output.
933 bool Verbose = false;
934
935 /// Print statistics.
936 bool Statistics = false;
937
938 /// Verify the input DWARF.
939 bool VerifyInputDWARF = false;
940
941 /// Do not unique types according to ODR
942 bool NoODR = false;
943
944 /// Update
945 bool Update = false;
946
947 /// Whether we want a static variable to force us to keep its enclosing
948 /// function.
949 bool KeepFunctionForStatic = false;
950
951 /// Number of threads.
952 unsigned Threads = 1;
953
954 /// The accelerator table kinds
955 SmallVector<AccelTableKind, 1> AccelTables;
956
957 /// Prepend path for the clang modules.
958 std::string PrependPath;
959
960 // input verification handler
961 inputVerificationHandler InputVerificationHandler = nullptr;
962
963 /// A list of all .swiftinterface files referenced by the debug
964 /// info, mapping Module name to path on disk. The entries need to
965 /// be uniqued and sorted and there are only few entries expected
966 /// per compile unit, which is why this is a std::map.
967 /// this is dsymutil specific fag.
968 swiftInterfacesMap *ParseableSwiftInterfaces = nullptr;
969
970 /// A list of remappings to apply to file paths.
971 objectPrefixMap *ObjectPrefixMap = nullptr;
972 } Options;
973};
974
975} // end namespace llvm
976
977#endif // LLVM_DWARFLINKER_DWARFLINKER_H
This file contains support for writing accelerator tables.
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
dxil DXContainer Global Emitter
This file defines the DenseMap class.
std::string Name
uint64_t Size
LLVMContext & Context
ppc ctr loops PowerPC CTR Loops Verify
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
Definition: AccelTable.h:194
The AddressRanges class helps normalize address range collections.
AddressesMap represents information about valid addresses used by debug information.
Definition: DWARFLinker.h:37
virtual std::optional< StringRef > getLibraryInstallName()=0
Returns the file name associated to the AddessesMap.
virtual bool applyValidRelocs(MutableArrayRef< char > Data, uint64_t BaseOffset, bool IsLittleEndian)=0
Apply the valid relocations to the buffer Data, taking into account that Data is at BaseOffset in the...
virtual void clear()=0
Erases all data.
virtual bool hasValidRelocs()=0
Checks that there are valid relocations against a .debug_info section.
virtual std::optional< int64_t > getExprOpAddressRelocAdjustment(DWARFUnit &U, const DWARFExpression::Operation &Op, uint64_t StartOffset, uint64_t EndOffset)=0
Checks that the specified DWARF expression operand Op references live code section and returns the re...
virtual std::optional< int64_t > getSubprogramRelocAdjustment(const DWARFDie &DIE)=0
Checks that the specified subprogram DIE references the live code section and returns the relocation ...
virtual ~AddressesMap()
virtual void updateAndSaveValidRelocs(bool IsDWARF5, uint64_t OriginalUnitOffset, int64_t LinkedOffset, uint64_t StartOffset, uint64_t EndOffset)=0
Update and save original relocations located in between StartOffset and EndOffset.
virtual void updateRelocationsWithUnitOffset(uint64_t OriginalUnitOffset, uint64_t OutputUnitOffset)=0
Update the valid relocations that used OriginalUnitOffset as the compile unit offset,...
virtual bool needToSaveValidRelocs()=0
Check if the linker needs to gather and save relocation info.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
Stores all information relating to a compile unit, be it in its original instance in the object file ...
A structured debug information entry.
Definition: DIE.h:819
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:48
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:42
This class represents an Operation in the Expression.
This class represents DWARF information for source file and its address map.
Definition: DWARFLinker.h:287
UnloadCallbackTy UnloadFunc
Callback to the module keeping object file to unload.
Definition: DWARFLinker.h:306
DWARFFile(StringRef Name, std::unique_ptr< DWARFContext > Dwarf, std::unique_ptr< AddressesMap > Addresses, UnloadCallbackTy UnloadFunc=nullptr)
Definition: DWARFLinker.h:290
void unload()
Unloads object file and corresponding AddressesMap and Dwarf Context.
Definition: DWARFLinker.h:309
std::unique_ptr< AddressesMap > Addresses
Helpful address information(list of valid address ranges, relocations).
Definition: DWARFLinker.h:303
std::function< void(StringRef FileName)> UnloadCallbackTy
Definition: DWARFLinker.h:289
StringRef FileName
The object file name.
Definition: DWARFLinker.h:297
std::unique_ptr< DWARFContext > Dwarf
The source DWARF information.
Definition: DWARFLinker.h:300
The core of the Dwarf linking logic.
Definition: DWARFLinker.h:337
void setVerbosity(bool Verbose)
A number of methods setting various linking options:
Definition: DWARFLinker.h:393
void setStatistics(bool Statistics)
Print statistics to standard output.
Definition: DWARFLinker.h:396
OutputFileType
Type of output file.
Definition: DWARFLinker.h:356
std::function< void(const DWARFFile &File, llvm::StringRef Output)> inputVerificationHandler
Definition: DWARFLinker.h:367
std::function< ErrorOr< DWARFFile & >(StringRef ContainerName, StringRef Path)> objFileLoader
Definition: DWARFLinker.h:370
std::function< void(const Twine &Warning, StringRef Context, const DWARFDie *DIE)> messageHandler
Definition: DWARFLinker.h:341
void setNumThreads(unsigned NumThreads)
Use specified number of threads for parallel files linking.
Definition: DWARFLinker.h:417
void setKeepFunctionForStatic(bool KeepFunctionForStatic)
Set whether to keep the enclosing function for a static variable.
Definition: DWARFLinker.h:412
Error link()
Link debug info for added objFiles. Object files are linked all together.
DwarfEmitter * getEmitter()
void setObjectPrefixMap(objectPrefixMap *Map)
Set prefix map for objects.
Definition: DWARFLinker.h:445
void setPrependPath(const std::string &Ppath)
Set prepend path for clang modules.
Definition: DWARFLinker.h:426
AccelTableKind
The kind of accelerator tables we should emit.
Definition: DWARFLinker.h:362
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
@ Pub
.debug_pubnames, .debug_pubtypes
void setAllowNonDeterministicOutput(bool)
Allow generating valid, but non-deterministic output.
Definition: DWARFLinker.h:408
void setUpdateIndexTablesOnly(bool Update)
Update index tables only(do not modify rest of DWARF).
Definition: DWARFLinker.h:405
void setEstimatedObjfilesAmount(unsigned ObjFilesNum)
Set estimated objects files amount, for preliminary data allocation.
Definition: DWARFLinker.h:429
DWARFLinker(messageHandler ErrorHandler, messageHandler WarningHandler, std::function< StringRef(StringRef)> StringsTranslator)
Definition: DWARFLinker.h:342
void addAccelTableKind(AccelTableKind Kind)
Add kind of accelerator tables to be generated.
Definition: DWARFLinker.h:420
void setSwiftInterfacesMap(swiftInterfacesMap *Map)
Set map for Swift interfaces.
Definition: DWARFLinker.h:440
void addObjectFile(DWARFFile &File, objFileLoader Loader=nullptr, CompileUnitHandler OnCUDieLoaded=[](const DWARFUnit &) {})
Add object file to be linked.
Error setTargetDWARFVersion(uint16_t TargetDWARFVersion)
Set target DWARF version.
Definition: DWARFLinker.h:450
Error createEmitter(const Triple &TheTriple, OutputFileType FileType, raw_pwrite_stream &OutFile)
void setNoODR(bool NoODR)
Do not unique types according to ODR.
Definition: DWARFLinker.h:402
void setVerifyInputDWARF(bool Verify)
Verify the input DWARF.
Definition: DWARFLinker.h:399
static std::unique_ptr< DWARFLinker > createLinker(messageHandler ErrorHandler, messageHandler WarningHandler, std::function< StringRef(StringRef)> StringsTranslator=nullptr)
Definition: DWARFLinker.h:348
void setInputVerificationHandler(inputVerificationHandler Handler)
Set verification handler which would be used to report verification errors.
Definition: DWARFLinker.h:435
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
DwarfEmitter presents interface to generate all debug info tables.
Definition: DWARFLinker.h:118
virtual void emitCIE(StringRef CIEBytes)=0
Emit a CIE.
virtual void emitPubNamesForUnit(const CompileUnit &Unit)=0
Emit the .debug_pubnames contribution for Unit.
virtual void emitDwarfDebugArangesTable(const CompileUnit &Unit, const AddressRanges &LinkedRanges)=0
Emit .debug_aranges entries for Unit.
virtual uint64_t getLineSectionSize() const =0
Returns size of generated .debug_line section.
virtual MCSymbol * emitDwarfDebugRangeListHeader(const CompileUnit &Unit)=0
Emit debug ranges (.debug_ranges, .debug_rnglists) header.
virtual void emitAppleNames(AccelTable< AppleAccelTableStaticOffsetData > &Table)=0
Emit Apple names accelerator table.
virtual void emitDwarfDebugAddrsFooter(const CompileUnit &Unit, MCSymbol *EndLabel)=0
Emit .debug_addr footer.
virtual void emitCompileUnitHeader(CompileUnit &Unit, unsigned DwarfVersion)=0
Emit the compilation unit header for Unit in the .debug_info section.
virtual MCSymbol * emitDwarfDebugAddrsHeader(const CompileUnit &Unit)=0
Emit .debug_addr header.
virtual uint64_t getRngListsSectionSize() const =0
Returns size of generated .debug_rnglists section.
virtual void emitStrings(const NonRelocatableStringpool &Pool)=0
Emit the string table described by Pool into .debug_str table.
virtual void emitPubTypesForUnit(const CompileUnit &Unit)=0
Emit the .debug_pubtypes contribution for Unit.
virtual void emitDebugNames(DWARF5AccelTable &Table)=0
Emit DWARF debug names.
virtual MCSymbol * emitDwarfDebugLocListHeader(const CompileUnit &Unit)=0
Emit debug locations (.debug_loc, .debug_loclists) header.
virtual void emitDwarfDebugLocListFragment(const CompileUnit &Unit, const DWARFLocationExpressionsVector &LinkedLocationExpression, PatchLocation Patch, DebugDieValuePool &AddrPool)=0
Emit debug locations (.debug_loc, .debug_loclists) fragment.
virtual void emitAppleNamespaces(AccelTable< AppleAccelTableStaticOffsetData > &Table)=0
Emit Apple namespaces accelerator table.
virtual void emitSwiftReflectionSection(llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind, StringRef Buffer, uint32_t Alignment, uint32_t Size)=0
Emit the swift reflection section stored in Buffer.
virtual uint64_t getDebugAddrSectionSize() const =0
Returns size of generated .debug_addr section.
virtual AsmPrinter & getAsmPrinter() const =0
Returns underlying AsmPrinter.
virtual void emitLineTableForUnit(const DWARFDebugLine::LineTable &LineTable, const CompileUnit &Unit, OffsetsStringPool &DebugStrPool, OffsetsStringPool &DebugLineStrPool)=0
Emit specified LineTable into .debug_line table.
virtual void emitMacroTables(DWARFContext *Context, const Offset2UnitMap &UnitMacroMap, OffsetsStringPool &StringPool)=0
Emit all available macro tables(DWARFv4 and DWARFv5).
virtual uint64_t getLocListsSectionSize() const =0
Returns size of generated .debug_loclists section.
virtual void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint64_t Address, StringRef Bytes)=0
Emit an FDE with data Bytes.
virtual uint64_t getRangesSectionSize() const =0
Returns size of generated .debug_ranges section.
virtual uint64_t getDebugInfoSectionSize() const =0
Returns size of generated .debug_info section.
virtual ~DwarfEmitter()
virtual void finish()=0
Dump the file to the disk.
virtual void emitStringOffsets(const SmallVector< uint64_t > &StringOffsets, uint16_t TargetDWARFVersion)=0
Emit the debug string offset table described by StringOffsets into the .debug_str_offsets table.
virtual uint64_t getDebugMacInfoSectionSize() const =0
Returns size of generated .debug_macinfo section.
virtual void emitAbbrevs(const std::vector< std::unique_ptr< DIEAbbrev > > &Abbrevs, unsigned DwarfVersion)=0
Emit the abbreviation table Abbrevs to the .debug_abbrev section.
virtual void emitDIE(DIE &Die)=0
Recursively emit the DIE tree rooted at Die.
virtual void emitAppleTypes(AccelTable< AppleAccelTableStaticTypeData > &Table)=0
Emit Apple type accelerator table.
virtual void emitDwarfDebugRangeListFragment(const CompileUnit &Unit, const AddressRanges &LinkedRanges, PatchLocation Patch, DebugDieValuePool &AddrPool)=0
Emit debug ranges (.debug_ranges, .debug_rnglists) fragment.
virtual void emitDwarfDebugAddrs(const SmallVector< uint64_t > &Addrs, uint8_t AddrSize)=0
Emit the addresses described by Addrs into the .debug_addr section.
virtual void emitLineStrings(const NonRelocatableStringpool &Pool)=0
Emit the string table described by Pool into .debug_line_str table.
virtual void emitDwarfDebugLocListFooter(const CompileUnit &Unit, MCSymbol *EndLabel)=0
Emit debug locations (.debug_loc, .debug_loclists) footer.
virtual void emitDwarfDebugRangeListFooter(const CompileUnit &Unit, MCSymbol *EndLabel)=0
Emit debug ranges (.debug_ranges, .debug_rnglists) footer.
virtual uint64_t getDebugMacroSectionSize() const =0
Returns size of generated .debug_macro section.
virtual void emitSectionContents(StringRef SecData, StringRef SecName)=0
Emit section named SecName with data SecData.
virtual void emitSwiftAST(StringRef Buffer)=0
Emit the swift_ast section stored in Buffer.
virtual uint64_t getFrameSectionSize() const =0
Returns size of generated .debug_frame section.
virtual void emitAppleObjc(AccelTable< AppleAccelTableStaticOffsetData > &Table)=0
Emit Apple Objective-C accelerator table.
The Dwarf streaming logic.
Definition: DWARFStreamer.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
A string table that doesn't need relocations.
size_t size() const
Definition: SmallVector.h:91
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Helper for making strong types.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
An efficient, type-erasing, non-owning reference to a callable.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:428
Swift5ReflectionSectionKind
Definition: Swift.h:14
DWARFAbbreviationDeclaration::AttributeSpec AttributeSpec
Definition: LVELFReader.h:31
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:53
function_ref< void(const ErrorInfoBase &, StringRef)> ErrorHandler
Definition: DIPrinter.h:68
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< std::unique_ptr< CompileUnit > > UnitListTy
Definition: DWARFLinker.h:283
function_ref< void(const DWARFUnit &Unit)> CompileUnitHandler
Definition: DWARFLinker.h:321
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1244
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
DwarfLinkerClient
Definition: DWARFLinker.h:31
@ Dwarf
DWARF v5 .debug_names.
StrongType< NonRelocatableStringpool, OffsetsTag > OffsetsStringPool
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition: Allocator.h:375
std::map< std::string, std::string > swiftInterfacesMap
Definition: DWARFLinker.h:318
@ Other
Any other memory.
DenseMap< uint64_t, CompileUnit * > Offset2UnitMap
Definition: DWARFLinker.h:96
std::map< std::string, std::string > objectPrefixMap
Definition: DWARFLinker.h:319
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1853
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1883
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
uint64_t getValueIndex(uint64_t Value)
Definition: DWARFLinker.h:102
SmallVector< uint64_t > DieValues
Definition: DWARFLinker.h:100
DenseMap< uint64_t, uint64_t > DieValueMap
Definition: DWARFLinker.h:99