1//===- DWARFLinkerGlobalData.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_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H
11
12#include "ModulePool.h"
13#include "TypePool.h"
14#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
15#include "llvm/DWARFLinker/StringPool.h"
16#include "llvm/Support/PerThreadBumpPtrAllocator.h"
17
18namespace llvm {
19
20class DWARFDie;
21
22namespace dwarf_linker {
23namespace parallel {
24
25using MessageHandlerTy = std::function<void(
26 const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
27
28/// linking options
29struct DWARFLinkerOptions {
30 /// DWARF version for the output.
31 uint16_t TargetDWARFVersion = 0;
32
33 /// Generate processing log to the standard output.
34 bool Verbose = false;
35
36 /// Print statistics.
37 bool Statistics = false;
38
39 /// Verify the input DWARF.
40 bool VerifyInputDWARF = false;
41
42 /// Do not unique types according to ODR
43 bool NoODR = false;
44
45 /// Update index tables.
46 bool UpdateIndexTablesOnly = false;
47
48 /// Whether we want a static variable to force us to keep its enclosing
49 /// function.
50 bool KeepFunctionForStatic = false;
51
52 /// Number of threads.
53 unsigned Threads = 1;
54
55 /// The accelerator table kinds
56 SmallVector<DWARFLinkerBase::AccelTableKind, 1> AccelTables;
57
58 /// Prepend path for the clang modules.
59 std::string PrependPath;
60
61 /// input verification handler(it might be called asynchronously).
62 DWARFLinkerBase::InputVerificationHandlerTy InputVerificationHandler =
63 nullptr;
64
65 /// A list of all .swiftinterface files referenced by the debug
66 /// info, mapping Module name to path on disk. The entries need to
67 /// be uniqued and sorted and there are only few entries expected
68 /// per compile unit, which is why this is a std::map.
69 /// this is dsymutil specific fag.
70 ///
71 /// (it might be called asynchronously).
72 DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces = nullptr;
73
74 /// A list of remappings to apply to file paths.
75 ///
76 /// (it might be called asynchronously).
77 DWARFLinkerBase::ObjectPrefixMapTy *ObjectPrefixMap = nullptr;
78};
79
80class DWARFLinkerImpl;
81
82/// This class keeps data and services common for the whole linking process.
83class LinkingGlobalData {
84 friend DWARFLinkerImpl;
85
86public:
87 /// Returns global per-thread allocator.
88 llvm::parallel::PerThreadBumpPtrAllocator &getAllocator() {
89 return Allocator;
90 }
91
92 /// Returns global string pool.
93 StringPool &getStringPool() { return Strings; }
94
95 ModulePool &getModulePool() { return Modules; }
96
97 /// Returns linking options.
98 const DWARFLinkerOptions &getOptions() const { return Options; }
99
100 /// Set warning handler.
101 void setWarningHandler(MessageHandlerTy Handler) { WarningHandler = Handler; }
102
103 /// Set error handler.
104 void setErrorHandler(MessageHandlerTy Handler) { ErrorHandler = Handler; }
105
106 /// Report warning.
107 void warn(const Twine &Warning, StringRef Context,
108 const DWARFDie *DIE = nullptr) {
109 if (WarningHandler)
110 (WarningHandler)(Warning, Context, DIE);
111 }
112
113 /// Report warning.
114 void warn(Error Warning, StringRef Context, const DWARFDie *DIE = nullptr) {
115 handleAllErrors(E: std::move(Warning), Handlers: [&](ErrorInfoBase &Info) {
116 warn(Warning: Info.message(), Context, DIE);
117 });
118 }
119
120 /// Report error.
121 void error(const Twine &Err, StringRef Context,
122 const DWARFDie *DIE = nullptr) {
123 if (ErrorHandler)
124 (ErrorHandler)(Err, Context, DIE);
125 }
126
127 /// Report error.
128 void error(Error Err, StringRef Context, const DWARFDie *DIE = nullptr) {
129 handleAllErrors(E: std::move(Err), Handlers: [&](ErrorInfoBase &Info) {
130 error(Err: Info.message(), Context, DIE);
131 });
132 }
133
134 /// Set target triple.
135 void setTargetTriple(const Triple &TargetTriple) {
136 this->TargetTriple = TargetTriple;
137 }
138
139 /// Optionally return target triple.
140 std::optional<std::reference_wrapper<const Triple>> getTargetTriple() {
141 if (TargetTriple)
142 return std::cref(t: *TargetTriple);
143
144 return std::nullopt;
145 }
146
147protected:
148 llvm::parallel::PerThreadBumpPtrAllocator Allocator;
149 StringPool Strings;
150 ModulePool Modules;
151 DWARFLinkerOptions Options;
152 MessageHandlerTy WarningHandler;
153 MessageHandlerTy ErrorHandler;
154
155 /// Triple for output data. May be not set if generation of output
156 /// data is not requested.
157 std::optional<Triple> TargetTriple;
158};
159
160} // end of namespace parallel
161} // end of namespace dwarf_linker
162} // end of namespace llvm
163
164#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H
165