Alexander Shaposhnikov | bd934ff | 2018-10-11 22:33:50 +0000 | [diff] [blame] | 1 | //===- CopyConfig.h -------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H |
| 11 | #define LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H |
| 12 | |
| 13 | #include "llvm/ADT/ArrayRef.h" |
| 14 | #include "llvm/ADT/Optional.h" |
| 15 | #include "llvm/ADT/SmallVector.h" |
| 16 | #include "llvm/ADT/StringMap.h" |
| 17 | #include "llvm/ADT/StringRef.h" |
| 18 | // Necessary for llvm::DebugCompressionType::None |
| 19 | #include "llvm/Target/TargetOptions.h" |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace llvm { |
| 24 | namespace objcopy { |
| 25 | |
| 26 | // This type keeps track of the machine info for various architectures. This |
| 27 | // lets us map architecture names to ELF types and the e_machine value of the |
| 28 | // ELF file. |
| 29 | struct MachineInfo { |
| 30 | uint16_t EMachine; |
| 31 | bool Is64Bit; |
| 32 | bool IsLittleEndian; |
| 33 | }; |
| 34 | |
| 35 | struct SectionRename { |
| 36 | StringRef OriginalName; |
| 37 | StringRef NewName; |
| 38 | Optional<uint64_t> NewFlags; |
| 39 | }; |
| 40 | |
| 41 | // Configuration for copying/stripping a single file. |
| 42 | struct CopyConfig { |
| 43 | // Main input/output options |
| 44 | StringRef InputFilename; |
| 45 | StringRef InputFormat; |
| 46 | StringRef OutputFilename; |
| 47 | StringRef OutputFormat; |
| 48 | |
Jordan Rupprecht | f570c1c | 2019-01-07 16:59:12 +0000 | [diff] [blame] | 49 | // Only applicable for --input-format=binary |
Alexander Shaposhnikov | bd934ff | 2018-10-11 22:33:50 +0000 | [diff] [blame] | 50 | MachineInfo BinaryArch; |
Jordan Rupprecht | f570c1c | 2019-01-07 16:59:12 +0000 | [diff] [blame] | 51 | // Only applicable when --output-format!=binary (e.g. elf64-x86-64). |
| 52 | Optional<MachineInfo> OutputArch; |
Alexander Shaposhnikov | bd934ff | 2018-10-11 22:33:50 +0000 | [diff] [blame] | 53 | |
| 54 | // Advanced options |
| 55 | StringRef AddGnuDebugLink; |
Jake Ehrlich | 14107a3 | 2018-12-03 19:49:23 +0000 | [diff] [blame] | 56 | StringRef BuildIdLinkDir; |
| 57 | Optional<StringRef> BuildIdLinkInput; |
| 58 | Optional<StringRef> BuildIdLinkOutput; |
Alexander Shaposhnikov | bd934ff | 2018-10-11 22:33:50 +0000 | [diff] [blame] | 59 | StringRef SplitDWO; |
| 60 | StringRef SymbolsPrefix; |
| 61 | |
| 62 | // Repeated options |
| 63 | std::vector<StringRef> AddSection; |
| 64 | std::vector<StringRef> DumpSection; |
Jordan Rupprecht | 65bac06 | 2018-11-13 19:32:27 +0000 | [diff] [blame] | 65 | std::vector<StringRef> KeepSection; |
Jake Ehrlich | beec7d49 | 2018-12-06 02:03:53 +0000 | [diff] [blame] | 66 | std::vector<StringRef> OnlySection; |
Alexander Shaposhnikov | bd934ff | 2018-10-11 22:33:50 +0000 | [diff] [blame] | 67 | std::vector<StringRef> SymbolsToGlobalize; |
| 68 | std::vector<StringRef> SymbolsToKeep; |
| 69 | std::vector<StringRef> SymbolsToLocalize; |
| 70 | std::vector<StringRef> SymbolsToRemove; |
| 71 | std::vector<StringRef> SymbolsToWeaken; |
| 72 | std::vector<StringRef> ToRemove; |
| 73 | std::vector<std::string> SymbolsToKeepGlobal; |
| 74 | |
| 75 | // Map options |
| 76 | StringMap<SectionRename> SectionsToRename; |
| 77 | StringMap<StringRef> SymbolsToRename; |
| 78 | |
| 79 | // Boolean options |
Jordan Rupprecht | 167fb18 | 2018-11-01 17:36:37 +0000 | [diff] [blame] | 80 | bool DeterministicArchives = true; |
Alexander Shaposhnikov | bd934ff | 2018-10-11 22:33:50 +0000 | [diff] [blame] | 81 | bool DiscardAll = false; |
| 82 | bool ExtractDWO = false; |
| 83 | bool KeepFileSymbols = false; |
| 84 | bool LocalizeHidden = false; |
| 85 | bool OnlyKeepDebug = false; |
| 86 | bool PreserveDates = false; |
| 87 | bool StripAll = false; |
| 88 | bool StripAllGNU = false; |
| 89 | bool StripDWO = false; |
| 90 | bool StripDebug = false; |
| 91 | bool StripNonAlloc = false; |
| 92 | bool StripSections = false; |
| 93 | bool StripUnneeded = false; |
| 94 | bool Weaken = false; |
| 95 | bool DecompressDebugSections = false; |
| 96 | DebugCompressionType CompressionType = DebugCompressionType::None; |
| 97 | }; |
| 98 | |
| 99 | // Configuration for the overall invocation of this tool. When invoked as |
| 100 | // objcopy, will always contain exactly one CopyConfig. When invoked as strip, |
| 101 | // will contain one or more CopyConfigs. |
| 102 | struct DriverConfig { |
| 103 | SmallVector<CopyConfig, 1> CopyConfigs; |
| 104 | }; |
| 105 | |
| 106 | // ParseObjcopyOptions returns the config and sets the input arguments. If a |
| 107 | // help flag is set then ParseObjcopyOptions will print the help messege and |
| 108 | // exit. |
| 109 | DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr); |
| 110 | |
| 111 | // ParseStripOptions returns the config and sets the input arguments. If a |
| 112 | // help flag is set then ParseStripOptions will print the help messege and |
| 113 | // exit. |
| 114 | DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr); |
| 115 | |
| 116 | } // namespace objcopy |
| 117 | } // namespace llvm |
| 118 | |
| 119 | #endif |