1 //===- CopyConfig.h -------------------------------------------------------===//
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
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"
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
35 struct SectionRename
{
36 StringRef OriginalName
;
38 Optional
<uint64_t> NewFlags
;
41 struct SectionFlagsUpdate
{
46 enum class DiscardType
{
48 All
, // --discard-all (-x)
49 Locals
, // --discard-locals (-X)
54 // Regex is shared between multiple CopyConfig instances.
55 std::shared_ptr
<Regex
> R
;
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.
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
;
77 StringRef AddGnuDebugLink
;
78 StringRef BuildIdLinkDir
;
79 Optional
<StringRef
> BuildIdLinkInput
;
80 Optional
<StringRef
> BuildIdLinkOutput
;
82 StringRef SymbolsPrefix
;
83 DiscardType DiscardMode
= DiscardType::None
;
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
;
100 StringMap
<SectionRename
> SectionsToRename
;
101 StringMap
<SectionFlagsUpdate
> SetSectionFlags
;
102 StringMap
<StringRef
> SymbolsToRename
;
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;
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
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
139 DriverConfig
parseStripOptions(ArrayRef
<const char *> ArgsArr
);
141 } // namespace objcopy