blob: 7ebe2a072bb4b3ca12590338cb22050e91ec6f20 [file] [log] [blame]
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +00001//===- CopyConfig.h -------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H
11#define LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H
12
13#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/Optional.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/StringRef.h"
18// Necessary for llvm::DebugCompressionType::None
19#include "llvm/Target/TargetOptions.h"
20#include <string>
21#include <vector>
22
23namespace llvm {
24namespace objcopy {
25
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.
29struct MachineInfo {
30 uint16_t EMachine;
31 bool Is64Bit;
32 bool IsLittleEndian;
33};
34
35struct SectionRename {
36 StringRef OriginalName;
37 StringRef NewName;
38 Optional<uint64_t> NewFlags;
39};
40
41// Configuration for copying/stripping a single file.
42struct CopyConfig {
43 // Main input/output options
44 StringRef InputFilename;
45 StringRef InputFormat;
46 StringRef OutputFilename;
47 StringRef OutputFormat;
48
49 // Only applicable for --input-format=Binary
50 MachineInfo BinaryArch;
51
52 // Advanced options
53 StringRef AddGnuDebugLink;
54 StringRef SplitDWO;
55 StringRef SymbolsPrefix;
56
57 // Repeated options
58 std::vector<StringRef> AddSection;
59 std::vector<StringRef> DumpSection;
60 std::vector<StringRef> Keep;
61 std::vector<StringRef> OnlyKeep;
62 std::vector<StringRef> SymbolsToGlobalize;
63 std::vector<StringRef> SymbolsToKeep;
64 std::vector<StringRef> SymbolsToLocalize;
65 std::vector<StringRef> SymbolsToRemove;
66 std::vector<StringRef> SymbolsToWeaken;
67 std::vector<StringRef> ToRemove;
68 std::vector<std::string> SymbolsToKeepGlobal;
69
70 // Map options
71 StringMap<SectionRename> SectionsToRename;
72 StringMap<StringRef> SymbolsToRename;
73
74 // Boolean options
Jordan Rupprechtfc780bb2018-11-01 17:36:37 +000075 bool DeterministicArchives = true;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000076 bool DiscardAll = false;
77 bool ExtractDWO = false;
78 bool KeepFileSymbols = false;
79 bool LocalizeHidden = false;
80 bool OnlyKeepDebug = false;
81 bool PreserveDates = false;
82 bool StripAll = false;
83 bool StripAllGNU = false;
84 bool StripDWO = false;
85 bool StripDebug = false;
86 bool StripNonAlloc = false;
87 bool StripSections = false;
88 bool StripUnneeded = false;
89 bool Weaken = false;
90 bool DecompressDebugSections = false;
91 DebugCompressionType CompressionType = DebugCompressionType::None;
92};
93
94// Configuration for the overall invocation of this tool. When invoked as
95// objcopy, will always contain exactly one CopyConfig. When invoked as strip,
96// will contain one or more CopyConfigs.
97struct DriverConfig {
98 SmallVector<CopyConfig, 1> CopyConfigs;
99};
100
101// ParseObjcopyOptions returns the config and sets the input arguments. If a
102// help flag is set then ParseObjcopyOptions will print the help messege and
103// exit.
104DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr);
105
106// ParseStripOptions returns the config and sets the input arguments. If a
107// help flag is set then ParseStripOptions will print the help messege and
108// exit.
109DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr);
110
111} // namespace objcopy
112} // namespace llvm
113
114#endif