1//===- DWARFLinkerBase.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_DWARFLINKERBASE_H
10#define LLVM_DWARFLINKER_DWARFLINKERBASE_H
11#include "AddressesMap.h"
12#include "DWARFFile.h"
13#include "llvm/ADT/AddressRanges.h"
14#include "llvm/ADT/DenseMap.h"
15#include "llvm/DebugInfo/DWARF/DWARFContext.h"
16#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
17#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
18#include "llvm/DebugInfo/DWARF/DWARFDie.h"
19#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
20#include <map>
21namespace llvm {
22class DWARFUnit;
23
24namespace dwarf_linker {
25
26/// List of tracked debug tables.
27enum class DebugSectionKind : uint8_t {
28 DebugInfo = 0,
29 DebugLine,
30 DebugFrame,
31 DebugRange,
32 DebugRngLists,
33 DebugLoc,
34 DebugLocLists,
35 DebugARanges,
36 DebugAbbrev,
37 DebugMacinfo,
38 DebugMacro,
39 DebugAddr,
40 DebugStr,
41 DebugLineStr,
42 DebugStrOffsets,
43 DebugPubNames,
44 DebugPubTypes,
45 DebugNames,
46 AppleNames,
47 AppleNamespaces,
48 AppleObjC,
49 AppleTypes,
50 NumberOfEnumEntries // must be last
51};
52
53static constexpr size_t SectionKindsNum =
54 static_cast<size_t>(DebugSectionKind::NumberOfEnumEntries);
55
56static constexpr StringLiteral SectionNames[SectionKindsNum] = {
57 "debug_info", "debug_line", "debug_frame", "debug_ranges",
58 "debug_rnglists", "debug_loc", "debug_loclists", "debug_aranges",
59 "debug_abbrev", "debug_macinfo", "debug_macro", "debug_addr",
60 "debug_str", "debug_line_str", "debug_str_offsets", "debug_pubnames",
61 "debug_pubtypes", "debug_names", "apple_names", "apple_namespac",
62 "apple_objc", "apple_types"};
63
64/// Return the name of the section.
65static constexpr const StringLiteral &
66getSectionName(DebugSectionKind SectionKind) {
67 return SectionNames[static_cast<uint8_t>(SectionKind)];
68}
69
70/// Recognise the table name and match it with the DebugSectionKind.
71std::optional<DebugSectionKind> parseDebugTableName(StringRef Name);
72
73/// The base interface for DWARFLinker implementations.
74class DWARFLinkerBase {
75public:
76 virtual ~DWARFLinkerBase() = default;
77 using MessageHandlerTy = std::function<void(
78 const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
79 using ObjFileLoaderTy = std::function<ErrorOr<DWARFFile &>(
80 StringRef ContainerName, StringRef Path)>;
81 using InputVerificationHandlerTy =
82 std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
83 using ObjectPrefixMapTy = std::map<std::string, std::string>;
84 using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
85 using SwiftInterfacesMapTy = std::map<std::string, std::string>;
86 /// Type of output file.
87 enum class OutputFileType : uint8_t {
88 Object,
89 Assembly,
90 };
91 /// The kind of accelerator tables to be emitted.
92 enum class AccelTableKind : uint8_t {
93 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
94 Pub, ///< .debug_pubnames, .debug_pubtypes
95 DebugNames ///< .debug_names.
96 };
97 /// Add an object file to be linked. Pre-load compile unit die. Call
98 /// \p OnCUDieLoaded for each compile unit die. If \p File has reference to
99 /// a Clang module and UpdateIndexTablesOnly == false then the module is be
100 /// pre-loaded by \p Loader.
101 ///
102 /// \pre a call to setNoODR(true) and/or setUpdateIndexTablesOnly(bool Update)
103 /// must be made when required.
104 virtual void addObjectFile(
105 DWARFFile &File, ObjFileLoaderTy Loader = nullptr,
106 CompileUnitHandlerTy OnCUDieLoaded = [](const DWARFUnit &) {}) = 0;
107 /// Link the debug info for all object files added through calls to
108 /// addObjectFile.
109 virtual Error link() = 0;
110 /// A number of methods setting various linking options:
111 /// Enable logging to standard output.
112 virtual void setVerbosity(bool Verbose) = 0;
113 /// Print statistics to standard output.
114 virtual void setStatistics(bool Statistics) = 0;
115 /// Verify the input DWARF.
116 virtual void setVerifyInputDWARF(bool Verify) = 0;
117 /// Do not unique types according to ODR.
118 virtual void setNoODR(bool NoODR) = 0;
119 /// Update index tables only (do not modify rest of DWARF).
120 virtual void setUpdateIndexTablesOnly(bool Update) = 0;
121 /// Allows generating non-deterministic output in exchange for more
122 /// parallelism.
123 virtual void setAllowNonDeterministicOutput(bool) = 0;
124 /// Set whether to keep the enclosing function for a static variable.
125 virtual void setKeepFunctionForStatic(bool KeepFunctionForStatic) = 0;
126 /// Use specified number of threads for parallel files linking.
127 virtual void setNumThreads(unsigned NumThreads) = 0;
128 /// Add kind of accelerator tables to be generated.
129 virtual void addAccelTableKind(AccelTableKind Kind) = 0;
130 /// Set prepend path for clang modules.
131 virtual void setPrependPath(StringRef Ppath) = 0;
132 /// Set estimated objects files amount, for preliminary data allocation.
133 virtual void setEstimatedObjfilesAmount(unsigned ObjFilesNum) = 0;
134 /// Set verification handler used to report verification errors.
135 virtual void
136 setInputVerificationHandler(InputVerificationHandlerTy Handler) = 0;
137 /// Set map for Swift interfaces.
138 virtual void setSwiftInterfacesMap(SwiftInterfacesMapTy *Map) = 0;
139 /// Set prefix map for objects.
140 virtual void setObjectPrefixMap(ObjectPrefixMapTy *Map) = 0;
141 /// Set target DWARF version.
142 virtual Error setTargetDWARFVersion(uint16_t TargetDWARFVersion) = 0;
143};
144} // end namespace dwarf_linker
145} // end namespace llvm
146#endif // LLVM_DWARFLINKER_DWARFLINKERBASE_H
147

source code of llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h