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 // All configs. 36 CommonConfig Common; 37 ELFConfig ELF; 38 COFFConfig COFF; 39 MachOConfig MachO; 40 WasmConfig Wasm; 41 }; 42 43 // Configuration for the overall invocation of this tool. When invoked as 44 // objcopy, will always contain exactly one CopyConfig. When invoked as strip, 45 // will contain one or more CopyConfigs. 46 struct DriverConfig { 47 SmallVector<ConfigManager, 1> CopyConfigs; 48 BumpPtrAllocator Alloc; 49 }; 50 51 // ParseObjcopyOptions returns the config and sets the input arguments. If a 52 // help flag is set then ParseObjcopyOptions will print the help messege and 53 // exit. ErrorCallback is used to handle recoverable errors. An Error returned 54 // by the callback aborts the parsing and is then returned by this function. 55 Expected<DriverConfig> 56 parseObjcopyOptions(ArrayRef<const char *> ArgsArr, 57 llvm::function_ref<Error(Error)> ErrorCallback); 58 59 // ParseInstallNameToolOptions returns the config and sets the input arguments. 60 // If a help flag is set then ParseInstallNameToolOptions will print the help 61 // messege and exit. 62 Expected<DriverConfig> 63 parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr); 64 65 // ParseBitcodeStripOptions returns the config and sets the input arguments. 66 // If a help flag is set then ParseBitcodeStripOptions will print the help 67 // messege and exit. 68 Expected<DriverConfig> parseBitcodeStripOptions(ArrayRef<const char *> ArgsArr); 69 70 // ParseStripOptions returns the config and sets the input arguments. If a 71 // help flag is set then ParseStripOptions will print the help messege and 72 // exit. ErrorCallback is used to handle recoverable errors. An Error returned 73 // by the callback aborts the parsing and is then returned by this function. 74 Expected<DriverConfig> 75 parseStripOptions(ArrayRef<const char *> ArgsArr, 76 llvm::function_ref<Error(Error)> ErrorCallback); 77 } // namespace objcopy 78 } // namespace llvm 79 80 #endif // LLVM_TOOLS_LLVM_OBJCOPY_CONFIGMANAGER_H 81