xref: /openbsd-src/gnu/llvm/llvm/tools/dsymutil/LinkUtils.h (revision d415bd752c734aee168c4ee86ff32e8cc249eb16)
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 "SymbolMap.h"
13 
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Remarks/RemarkFormat.h"
16 #include "llvm/Support/VirtualFileSystem.h"
17 #include "llvm/Support/WithColor.h"
18 
19 #include "llvm/DWARFLinker/DWARFLinker.h"
20 #include "llvm/DWARFLinker/DWARFStreamer.h"
21 #include <string>
22 
23 namespace llvm {
24 namespace dsymutil {
25 
26 enum class DsymutilAccelTableKind : uint8_t {
27   None,
28   Apple,   ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
29   Dwarf,   ///< DWARF v5 .debug_names.
30   Default, ///< Dwarf for DWARF5 or later, Apple otherwise.
31   Pub,     ///< .debug_pubnames, .debug_pubtypes
32 };
33 
34 struct LinkOptions {
35   /// Verbosity
36   bool Verbose = false;
37 
38   /// Statistics
39   bool Statistics = false;
40 
41   /// Verify the input DWARF.
42   bool VerifyInputDWARF = false;
43 
44   /// Skip emitting output
45   bool NoOutput = false;
46 
47   /// Do not unique types according to ODR
48   bool NoODR = false;
49 
50   /// Update
51   bool Update = false;
52 
53   /// Do not check swiftmodule timestamp
54   bool NoTimestamp = false;
55 
56   /// Whether we want a static variable to force us to keep its enclosing
57   /// function.
58   bool KeepFunctionForStatic = false;
59 
60   /// Number of threads.
61   unsigned Threads = 1;
62 
63   // Output file type.
64   OutputFileType FileType = OutputFileType::Object;
65 
66   /// The accelerator table kind
67   DsymutilAccelTableKind TheAccelTableKind;
68 
69   /// -oso-prepend-path
70   std::string PrependPath;
71 
72   /// The -object-prefix-map.
73   std::map<std::string, std::string> ObjectPrefixMap;
74 
75   /// The Resources directory in the .dSYM bundle.
76   std::optional<std::string> ResourceDir;
77 
78   /// Symbol map translator.
79   SymbolMapTranslator Translator;
80 
81   /// Virtual File System.
82   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
83       vfs::getRealFileSystem();
84 
85   /// Fields used for linking and placing remarks into the .dSYM bundle.
86   /// @{
87 
88   /// Number of debug maps processed in total.
89   unsigned NumDebugMaps = 0;
90 
91   /// -remarks-prepend-path: prepend a path to all the external remark file
92   /// paths found in remark metadata.
93   std::string RemarksPrependPath;
94 
95   /// The output format of the remarks.
96   remarks::Format RemarksFormat = remarks::Format::Bitstream;
97 
98   /// @}
99 
100   LinkOptions() = default;
101 };
102 
103 inline void warn(Twine Warning, Twine Context = {}) {
104   WithColor::warning() << Warning + "\n";
105   if (!Context.isTriviallyEmpty())
106     WithColor::note() << Twine("while processing ") + Context + "\n";
107 }
108 
109 inline bool error(Twine Error, Twine Context = {}) {
110   WithColor::error() << Error + "\n";
111   if (!Context.isTriviallyEmpty())
112     WithColor::note() << Twine("while processing ") + Context + "\n";
113   return false;
114 }
115 
116 } // end namespace dsymutil
117 } // end namespace llvm
118 
119 #endif // LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
120