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   /// Verify the input DWARF.
34   bool VerifyInputDWARF = false;
35 
36   /// Skip emitting output
37   bool NoOutput = false;
38 
39   /// Do not unique types according to ODR
40   bool NoODR = false;
41 
42   /// Update
43   bool Update = false;
44 
45   /// Do not check swiftmodule timestamp
46   bool NoTimestamp = 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   // Output file type.
56   OutputFileType FileType = OutputFileType::Object;
57 
58   /// The accelerator table kind
59   DwarfLinkerAccelTableKind TheAccelTableKind;
60 
61   /// -oso-prepend-path
62   std::string PrependPath;
63 
64   /// The -object-prefix-map.
65   std::map<std::string, std::string> ObjectPrefixMap;
66 
67   /// The Resources directory in the .dSYM bundle.
68   Optional<std::string> ResourceDir;
69 
70   /// Symbol map translator.
71   SymbolMapTranslator Translator;
72 
73   /// Virtual File System.
74   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
75       vfs::getRealFileSystem();
76 
77   /// Fields used for linking and placing remarks into the .dSYM bundle.
78   /// @{
79 
80   /// Number of debug maps processed in total.
81   unsigned NumDebugMaps = 0;
82 
83   /// -remarks-prepend-path: prepend a path to all the external remark file
84   /// paths found in remark metadata.
85   std::string RemarksPrependPath;
86 
87   /// The output format of the remarks.
88   remarks::Format RemarksFormat = remarks::Format::Bitstream;
89 
90   /// @}
91 
92   LinkOptions() = default;
93 };
94 
95 inline void warn(Twine Warning, Twine Context = {}) {
96   WithColor::warning() << Warning + "\n";
97   if (!Context.isTriviallyEmpty())
98     WithColor::note() << Twine("while processing ") + Context + "\n";
99 }
100 
101 inline bool error(Twine Error, Twine Context = {}) {
102   WithColor::error() << Error + "\n";
103   if (!Context.isTriviallyEmpty())
104     WithColor::note() << Twine("while processing ") + Context + "\n";
105   return false;
106 }
107 
108 } // end namespace dsymutil
109 } // end namespace llvm
110 
111 #endif // LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
112