1//===- tools/dsymutil/LinkUtils.h - Dwarf linker utilities ------*- 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_TOOLS_DSYMUTIL_LINKOPTIONS_H
10#define LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
11
12#include "llvm/ADT/StringMap.h"
13#include "llvm/ADT/Twine.h"
14#include "llvm/Remarks/RemarkFormat.h"
15#include "llvm/Support/VirtualFileSystem.h"
16#include "llvm/Support/WithColor.h"
17
18#include "llvm/DWARFLinker/Classic/DWARFLinker.h"
19#include "llvm/DWARFLinker/Classic/DWARFStreamer.h"
20#include <string>
21
22namespace llvm {
23namespace dsymutil {
24
25enum class DsymutilAccelTableKind : uint8_t {
26 None,
27 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
28 Dwarf, ///< DWARF v5 .debug_names.
29 Default, ///< Dwarf for DWARF5 or later, Apple otherwise.
30 Pub, ///< .debug_pubnames, .debug_pubtypes
31};
32
33enum class DsymutilDWARFLinkerType : uint8_t {
34 Classic, /// Classic implementation of DWARFLinker.
35 Parallel /// Implementation of DWARFLinker heavily using parallel execution.
36};
37
38struct LinkOptions {
39 /// Verbosity
40 bool Verbose = false;
41
42 /// Quiet
43 bool Quiet = false;
44
45 /// Statistics
46 bool Statistics = false;
47
48 /// Verify the input DWARF.
49 bool VerifyInputDWARF = false;
50
51 /// Skip emitting output
52 bool NoOutput = false;
53
54 /// Do not unique types according to ODR
55 bool NoODR = false;
56
57 /// Update
58 bool Update = false;
59
60 /// Do not check swiftmodule timestamp
61 bool NoTimestamp = false;
62
63 /// Whether we want a static variable to force us to keep its enclosing
64 /// function.
65 bool KeepFunctionForStatic = false;
66
67 /// Type of DWARFLinker to use.
68 DsymutilDWARFLinkerType DWARFLinkerType = DsymutilDWARFLinkerType::Parallel;
69
70 /// Use a 64-bit header when emitting universal binaries.
71 bool Fat64 = false;
72
73 /// Number of threads.
74 unsigned Threads = 1;
75
76 // Output file type.
77 dwarf_linker::DWARFLinkerBase::OutputFileType FileType =
78 dwarf_linker::DWARFLinkerBase::OutputFileType::Object;
79
80 /// The accelerator table kind
81 DsymutilAccelTableKind TheAccelTableKind;
82
83 /// -oso-prepend-path
84 std::string PrependPath;
85
86 /// The -object-prefix-map.
87 std::map<std::string, std::string> ObjectPrefixMap;
88
89 /// The Resources directory in the .dSYM bundle.
90 std::optional<std::string> ResourceDir;
91
92 /// Resources to embed in the dSYM bundle's Contents/Resources/ directory.
93 StringMap<std::string> EmbedResources;
94
95 /// Virtual File System.
96 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
97 vfs::getRealFileSystem();
98
99 /// -build-variant-suffix.
100 std::string BuildVariantSuffix;
101
102 /// Paths where to search for the .dSYM files of merged libraries.
103 std::vector<std::string> DSYMSearchPaths;
104
105 /// Fields used for linking and placing remarks into the .dSYM bundle.
106 /// @{
107
108 /// Number of debug maps processed in total.
109 unsigned NumDebugMaps = 0;
110
111 /// -remarks-prepend-path: prepend a path to all the external remark file
112 /// paths found in remark metadata.
113 std::string RemarksPrependPath;
114
115 /// The output format of the remarks.
116 remarks::Format RemarksFormat = remarks::Format::Bitstream;
117
118 /// Whether all remarks should be kept or only remarks with valid debug
119 /// locations.
120 bool RemarksKeepAll = true;
121
122 /// Whether or not to copy binary swiftmodules built from textual
123 /// .swiftinterface files into the dSYM bundle. These typically come only
124 /// from the SDK (since textual interfaces require library evolution) and
125 /// thus are a waste of space to copy into the bundle. Turn this on if the
126 /// swiftmodules are different from those in the SDK.
127 bool IncludeSwiftModulesFromInterface = false;
128 /// @}
129
130 /// Whether to allow emitting Mach-O where, within a single slice, section
131 /// header offsets (section.offset, 32-bit) exceed 4GB (non-standard).
132 bool AllowSectionHeaderOffsetOverflow = false;
133
134 LinkOptions() = default;
135};
136
137inline void warn(Twine Warning, Twine Context = {}) {
138 WithColor::warning() << Warning + "\n";
139 if (!Context.isTriviallyEmpty())
140 WithColor::note() << Twine("while processing ") + Context + "\n";
141}
142
143inline bool error(Twine Error, Twine Context = {}) {
144 WithColor::error() << Error + "\n";
145 if (!Context.isTriviallyEmpty())
146 WithColor::note() << Twine("while processing ") + Context + "\n";
147 return false;
148}
149
150} // end namespace dsymutil
151} // end namespace llvm
152
153#endif // LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
154