xref: /netbsd-src/external/apache2/llvm/dist/llvm/tools/dsymutil/LinkUtils.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
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 struct LinkOptions {
27   /// Verbosity
28   bool Verbose = false;
29 
30   /// Statistics
31   bool Statistics = false;
32 
33   /// Skip emitting output
34   bool NoOutput = false;
35 
36   /// Do not unique types according to ODR
37   bool NoODR = false;
38 
39   /// Update
40   bool Update = false;
41 
42   /// Do not check swiftmodule timestamp
43   bool NoTimestamp = false;
44 
45   /// Whether we want a static variable to force us to keep its enclosing
46   /// function.
47   bool KeepFunctionForStatic = false;
48 
49   /// Number of threads.
50   unsigned Threads = 1;
51 
52   // Output file type.
53   OutputFileType FileType = OutputFileType::Object;
54 
55   /// The accelerator table kind
56   AccelTableKind TheAccelTableKind;
57 
58   /// -oso-prepend-path
59   std::string PrependPath;
60 
61   /// The -object-prefix-map.
62   std::map<std::string, std::string> ObjectPrefixMap;
63 
64   /// The Resources directory in the .dSYM bundle.
65   Optional<std::string> ResourceDir;
66 
67   /// Symbol map translator.
68   SymbolMapTranslator Translator;
69 
70   /// Virtual File System.
71   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
72       vfs::getRealFileSystem();
73 
74   /// Fields used for linking and placing remarks into the .dSYM bundle.
75   /// @{
76 
77   /// Number of debug maps processed in total.
78   unsigned NumDebugMaps = 0;
79 
80   /// -remarks-prepend-path: prepend a path to all the external remark file
81   /// paths found in remark metadata.
82   std::string RemarksPrependPath;
83 
84   /// The output format of the remarks.
85   remarks::Format RemarksFormat = remarks::Format::Bitstream;
86 
87   /// @}
88 
89   LinkOptions() = default;
90 };
91 
92 inline void warn(Twine Warning, Twine Context = {}) {
93   WithColor::warning() << Warning + "\n";
94   if (!Context.isTriviallyEmpty())
95     WithColor::note() << Twine("while processing ") + Context + "\n";
96 }
97 
98 inline bool error(Twine Error, Twine Context = {}) {
99   WithColor::error() << Error + "\n";
100   if (!Context.isTriviallyEmpty())
101     WithColor::note() << Twine("while processing ") + Context + "\n";
102   return false;
103 }
104 
105 } // end namespace dsymutil
106 } // end namespace llvm
107 
108 #endif // LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
109