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