Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / tools / llvm-objcopy / CopyConfig.h
blobf1d5cf2c10cbf011a28827d7eab5b1c3711d4388
1 //===- CopyConfig.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H
10 #define LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H
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 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/Regex.h"
19 // Necessary for llvm::DebugCompressionType::None
20 #include "llvm/Target/TargetOptions.h"
21 #include <vector>
23 namespace llvm {
24 namespace objcopy {
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;
35 struct SectionRename {
36 StringRef OriginalName;
37 StringRef NewName;
38 Optional<uint64_t> NewFlags;
41 struct SectionFlagsUpdate {
42 StringRef Name;
43 uint64_t NewFlags;
46 enum class DiscardType {
47 None, // Default
48 All, // --discard-all (-x)
49 Locals, // --discard-locals (-X)
52 class NameOrRegex {
53 StringRef Name;
54 // Regex is shared between multiple CopyConfig instances.
55 std::shared_ptr<Regex> R;
57 public:
58 NameOrRegex(StringRef Pattern, bool IsRegex);
59 bool operator==(StringRef S) const { return R ? R->match(S) : Name == S; }
60 bool operator!=(StringRef S) const { return !operator==(S); }
63 // Configuration for copying/stripping a single file.
64 struct CopyConfig {
65 // Main input/output options
66 StringRef InputFilename;
67 StringRef InputFormat;
68 StringRef OutputFilename;
69 StringRef OutputFormat;
71 // Only applicable for --input-format=binary
72 MachineInfo BinaryArch;
73 // Only applicable when --output-format!=binary (e.g. elf64-x86-64).
74 Optional<MachineInfo> OutputArch;
76 // Advanced options
77 StringRef AddGnuDebugLink;
78 StringRef BuildIdLinkDir;
79 Optional<StringRef> BuildIdLinkInput;
80 Optional<StringRef> BuildIdLinkOutput;
81 StringRef SplitDWO;
82 StringRef SymbolsPrefix;
83 DiscardType DiscardMode = DiscardType::None;
85 // Repeated options
86 std::vector<StringRef> AddSection;
87 std::vector<StringRef> DumpSection;
88 std::vector<NameOrRegex> KeepSection;
89 std::vector<NameOrRegex> OnlySection;
90 std::vector<NameOrRegex> SymbolsToGlobalize;
91 std::vector<NameOrRegex> SymbolsToKeep;
92 std::vector<NameOrRegex> SymbolsToLocalize;
93 std::vector<NameOrRegex> SymbolsToRemove;
94 std::vector<NameOrRegex> UnneededSymbolsToRemove;
95 std::vector<NameOrRegex> SymbolsToWeaken;
96 std::vector<NameOrRegex> ToRemove;
97 std::vector<NameOrRegex> SymbolsToKeepGlobal;
99 // Map options
100 StringMap<SectionRename> SectionsToRename;
101 StringMap<SectionFlagsUpdate> SetSectionFlags;
102 StringMap<StringRef> SymbolsToRename;
104 // Boolean options
105 bool DeterministicArchives = true;
106 bool ExtractDWO = false;
107 bool KeepFileSymbols = false;
108 bool LocalizeHidden = false;
109 bool OnlyKeepDebug = false;
110 bool PreserveDates = false;
111 bool StripAll = false;
112 bool StripAllGNU = false;
113 bool StripDWO = false;
114 bool StripDebug = false;
115 bool StripNonAlloc = false;
116 bool StripSections = false;
117 bool StripUnneeded = false;
118 bool Weaken = false;
119 bool DecompressDebugSections = false;
120 DebugCompressionType CompressionType = DebugCompressionType::None;
123 // Configuration for the overall invocation of this tool. When invoked as
124 // objcopy, will always contain exactly one CopyConfig. When invoked as strip,
125 // will contain one or more CopyConfigs.
126 struct DriverConfig {
127 SmallVector<CopyConfig, 1> CopyConfigs;
128 BumpPtrAllocator Alloc;
131 // ParseObjcopyOptions returns the config and sets the input arguments. If a
132 // help flag is set then ParseObjcopyOptions will print the help messege and
133 // exit.
134 DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr);
136 // ParseStripOptions returns the config and sets the input arguments. If a
137 // help flag is set then ParseStripOptions will print the help messege and
138 // exit.
139 DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr);
141 } // namespace objcopy
142 } // namespace llvm
144 #endif