xref: /netbsd-src/external/apache2/llvm/dist/llvm/tools/llvm-objcopy/ConfigManager.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 //===- ConfigManager.h ----------------------------------------------------===//
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_LLVM_OBJCOPY_CONFIGMANAGER_H
10 #define LLVM_TOOLS_LLVM_OBJCOPY_CONFIGMANAGER_H
11 
12 #include "COFF/COFFConfig.h"
13 #include "CommonConfig.h"
14 #include "ELF/ELFConfig.h"
15 #include "MachO/MachOConfig.h"
16 #include "MultiFormatConfig.h"
17 #include "wasm/WasmConfig.h"
18 #include "llvm/Support/Allocator.h"
19 #include <vector>
20 
21 namespace llvm {
22 namespace objcopy {
23 
24 // ConfigManager keeps all configurations and prepare
25 // format-specific options.
26 struct ConfigManager : public MultiFormatConfig {
~ConfigManagerConfigManager27   virtual ~ConfigManager() {}
28 
getCommonConfigConfigManager29   const CommonConfig &getCommonConfig() const override { return Common; }
30   Expected<const ELFConfig &> getELFConfig() const override;
31   Expected<const COFFConfig &> getCOFFConfig() const override;
32   Expected<const MachOConfig &> getMachOConfig() const override;
33   Expected<const WasmConfig &> getWasmConfig() const override;
34 
35   // String representation for lazy ELF options.
36   std::vector<StringRef> SymbolsToAdd;
37   Optional<StringRef> NewSymbolVisibility;
38 
39   // All configs.
40   CommonConfig Common;
41   mutable Optional<ELFConfig> ELF;
42   COFFConfig COFF;
43   MachOConfig MachO;
44   WasmConfig Wasm;
45 };
46 
47 // Configuration for the overall invocation of this tool. When invoked as
48 // objcopy, will always contain exactly one CopyConfig. When invoked as strip,
49 // will contain one or more CopyConfigs.
50 struct DriverConfig {
51   SmallVector<ConfigManager, 1> CopyConfigs;
52   BumpPtrAllocator Alloc;
53 };
54 
55 // ParseObjcopyOptions returns the config and sets the input arguments. If a
56 // help flag is set then ParseObjcopyOptions will print the help messege and
57 // exit. ErrorCallback is used to handle recoverable errors. An Error returned
58 // by the callback aborts the parsing and is then returned by this function.
59 Expected<DriverConfig>
60 parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
61                     llvm::function_ref<Error(Error)> ErrorCallback);
62 
63 // ParseInstallNameToolOptions returns the config and sets the input arguments.
64 // If a help flag is set then ParseInstallNameToolOptions will print the help
65 // messege and exit.
66 Expected<DriverConfig>
67 parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr);
68 
69 // ParseBitcodeStripOptions returns the config and sets the input arguments.
70 // If a help flag is set then ParseBitcodeStripOptions will print the help
71 // messege and exit.
72 Expected<DriverConfig> parseBitcodeStripOptions(ArrayRef<const char *> ArgsArr);
73 
74 // ParseStripOptions returns the config and sets the input arguments. If a
75 // help flag is set then ParseStripOptions will print the help messege and
76 // exit. ErrorCallback is used to handle recoverable errors. An Error returned
77 // by the callback aborts the parsing and is then returned by this function.
78 Expected<DriverConfig>
79 parseStripOptions(ArrayRef<const char *> ArgsArr,
80                   llvm::function_ref<Error(Error)> ErrorCallback);
81 } // namespace objcopy
82 } // namespace llvm
83 
84 #endif // LLVM_TOOLS_LLVM_OBJCOPY_CONFIGMANAGER_H
85