blob: 9a9a0981bc81fc295afb07144cc9f8daa4ecf0fa [file] [log] [blame]
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +00001//===- CopyConfig.h -------------------------------------------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Shaposhnikov8d0b74c2018-10-11 22:33:50 +00006//
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
22namespace llvm {
23namespace 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.
28struct MachineInfo {
29 uint16_t EMachine;
30 bool Is64Bit;
31 bool IsLittleEndian;
32};
33
34struct SectionRename {
35 StringRef OriginalName;
36 StringRef NewName;
37 Optional<uint64_t> NewFlags;
38};
39
Jordan Rupprechtc8927412019-01-29 15:05:38 +000040struct SectionFlagsUpdate {
41 StringRef Name;
42 uint64_t NewFlags;
43};
44
Jordan Rupprechtd0f7bcf2019-01-30 14:58:13 +000045enum class DiscardType {
46 None, // Default
47 All, // --discard-all (-x)
48 Locals, // --discard-locals (-X)
49};
50
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000051// Configuration for copying/stripping a single file.
52struct CopyConfig {
53 // Main input/output options
54 StringRef InputFilename;
55 StringRef InputFormat;
56 StringRef OutputFilename;
57 StringRef OutputFormat;
58
Jordan Rupprecht70038e02019-01-07 16:59:12 +000059 // Only applicable for --input-format=binary
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000060 MachineInfo BinaryArch;
Jordan Rupprecht70038e02019-01-07 16:59:12 +000061 // Only applicable when --output-format!=binary (e.g. elf64-x86-64).
62 Optional<MachineInfo> OutputArch;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000063
64 // Advanced options
65 StringRef AddGnuDebugLink;
Jake Ehrlich8ad77792018-12-03 19:49:23 +000066 StringRef BuildIdLinkDir;
67 Optional<StringRef> BuildIdLinkInput;
68 Optional<StringRef> BuildIdLinkOutput;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000069 StringRef SplitDWO;
70 StringRef SymbolsPrefix;
Jordan Rupprechtd0f7bcf2019-01-30 14:58:13 +000071 DiscardType DiscardMode = DiscardType::None;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000072
73 // Repeated options
74 std::vector<StringRef> AddSection;
75 std::vector<StringRef> DumpSection;
Jordan Rupprechtc5bae782018-11-13 19:32:27 +000076 std::vector<StringRef> KeepSection;
Jake Ehrlich85985ed2018-12-06 02:03:53 +000077 std::vector<StringRef> OnlySection;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000078 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 Rupprechtc8927412019-01-29 15:05:38 +000088 StringMap<SectionFlagsUpdate> SetSectionFlags;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000089 StringMap<StringRef> SymbolsToRename;
90
91 // Boolean options
Jordan Rupprechtfc780bb2018-11-01 17:36:37 +000092 bool DeterministicArchives = true;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000093 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.
113struct 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.
120DriverConfig 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.
125DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr);
126
127} // namespace objcopy
128} // namespace llvm
129
130#endif