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