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 // Necessary for llvm::DebugCompressionType::None
18 #include "llvm/Target/TargetOptions.h"
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
34 struct SectionRename
{
35 StringRef OriginalName
;
37 Optional
<uint64_t> NewFlags
;
40 struct SectionFlagsUpdate
{
45 enum class DiscardType
{
47 All
, // --discard-all (-x)
48 Locals
, // --discard-locals (-X)
51 // Configuration for copying/stripping a single file.
53 // Main input/output options
54 StringRef InputFilename
;
55 StringRef InputFormat
;
56 StringRef OutputFilename
;
57 StringRef OutputFormat
;
59 // Only applicable for --input-format=binary
60 MachineInfo BinaryArch
;
61 // Only applicable when --output-format!=binary (e.g. elf64-x86-64).
62 Optional
<MachineInfo
> OutputArch
;
65 StringRef AddGnuDebugLink
;
66 StringRef BuildIdLinkDir
;
67 Optional
<StringRef
> BuildIdLinkInput
;
68 Optional
<StringRef
> BuildIdLinkOutput
;
70 StringRef SymbolsPrefix
;
71 DiscardType DiscardMode
= DiscardType::None
;
74 std::vector
<StringRef
> AddSection
;
75 std::vector
<StringRef
> DumpSection
;
76 std::vector
<StringRef
> KeepSection
;
77 std::vector
<StringRef
> OnlySection
;
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
;
87 StringMap
<SectionRename
> SectionsToRename
;
88 StringMap
<SectionFlagsUpdate
> SetSectionFlags
;
89 StringMap
<StringRef
> SymbolsToRename
;
92 bool DeterministicArchives
= true;
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;
106 bool DecompressDebugSections
= false;
107 DebugCompressionType CompressionType
= DebugCompressionType::None
;
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
;
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
120 DriverConfig
parseObjcopyOptions(ArrayRef
<const char *> ArgsArr
);
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
125 DriverConfig
parseStripOptions(ArrayRef
<const char *> ArgsArr
);
127 } // namespace objcopy