blob: c9af3734e8dbb3c1335d398d939e3423d5cc46f6 [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
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000045// Configuration for copying/stripping a single file.
46struct CopyConfig {
47 // Main input/output options
48 StringRef InputFilename;
49 StringRef InputFormat;
50 StringRef OutputFilename;
51 StringRef OutputFormat;
52
Jordan Rupprecht70038e02019-01-07 16:59:12 +000053 // Only applicable for --input-format=binary
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000054 MachineInfo BinaryArch;
Jordan Rupprecht70038e02019-01-07 16:59:12 +000055 // Only applicable when --output-format!=binary (e.g. elf64-x86-64).
56 Optional<MachineInfo> OutputArch;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000057
58 // Advanced options
59 StringRef AddGnuDebugLink;
Jake Ehrlich8ad77792018-12-03 19:49:23 +000060 StringRef BuildIdLinkDir;
61 Optional<StringRef> BuildIdLinkInput;
62 Optional<StringRef> BuildIdLinkOutput;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000063 StringRef SplitDWO;
64 StringRef SymbolsPrefix;
65
66 // Repeated options
67 std::vector<StringRef> AddSection;
68 std::vector<StringRef> DumpSection;
Jordan Rupprechtc5bae782018-11-13 19:32:27 +000069 std::vector<StringRef> KeepSection;
Jake Ehrlich85985ed2018-12-06 02:03:53 +000070 std::vector<StringRef> OnlySection;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000071 std::vector<StringRef> SymbolsToGlobalize;
72 std::vector<StringRef> SymbolsToKeep;
73 std::vector<StringRef> SymbolsToLocalize;
74 std::vector<StringRef> SymbolsToRemove;
75 std::vector<StringRef> SymbolsToWeaken;
76 std::vector<StringRef> ToRemove;
77 std::vector<std::string> SymbolsToKeepGlobal;
78
79 // Map options
80 StringMap<SectionRename> SectionsToRename;
Jordan Rupprechtc8927412019-01-29 15:05:38 +000081 StringMap<SectionFlagsUpdate> SetSectionFlags;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000082 StringMap<StringRef> SymbolsToRename;
83
84 // Boolean options
Jordan Rupprechtfc780bb2018-11-01 17:36:37 +000085 bool DeterministicArchives = true;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000086 bool DiscardAll = false;
87 bool ExtractDWO = false;
88 bool KeepFileSymbols = false;
89 bool LocalizeHidden = false;
90 bool OnlyKeepDebug = false;
91 bool PreserveDates = false;
92 bool StripAll = false;
93 bool StripAllGNU = false;
94 bool StripDWO = false;
95 bool StripDebug = false;
96 bool StripNonAlloc = false;
97 bool StripSections = false;
98 bool StripUnneeded = false;
99 bool Weaken = false;
100 bool DecompressDebugSections = false;
101 DebugCompressionType CompressionType = DebugCompressionType::None;
102};
103
104// Configuration for the overall invocation of this tool. When invoked as
105// objcopy, will always contain exactly one CopyConfig. When invoked as strip,
106// will contain one or more CopyConfigs.
107struct DriverConfig {
108 SmallVector<CopyConfig, 1> CopyConfigs;
109};
110
111// ParseObjcopyOptions returns the config and sets the input arguments. If a
112// help flag is set then ParseObjcopyOptions will print the help messege and
113// exit.
114DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr);
115
116// ParseStripOptions returns the config and sets the input arguments. If a
117// help flag is set then ParseStripOptions will print the help messege and
118// exit.
119DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr);
120
121} // namespace objcopy
122} // namespace llvm
123
124#endif