blob: ce6ead80b7c5e08eec3197211b14f6383973a505 [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;
Jake Ehrlich8ad77792018-12-03 19:49:23 +000054 StringRef BuildIdLinkDir;
55 Optional<StringRef> BuildIdLinkInput;
56 Optional<StringRef> BuildIdLinkOutput;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000057 StringRef SplitDWO;
58 StringRef SymbolsPrefix;
59
60 // Repeated options
61 std::vector<StringRef> AddSection;
62 std::vector<StringRef> DumpSection;
Jordan Rupprechtc5bae782018-11-13 19:32:27 +000063 std::vector<StringRef> KeepSection;
Jake Ehrlich85985ed2018-12-06 02:03:53 +000064 std::vector<StringRef> OnlySection;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000065 std::vector<StringRef> SymbolsToGlobalize;
66 std::vector<StringRef> SymbolsToKeep;
67 std::vector<StringRef> SymbolsToLocalize;
68 std::vector<StringRef> SymbolsToRemove;
69 std::vector<StringRef> SymbolsToWeaken;
70 std::vector<StringRef> ToRemove;
71 std::vector<std::string> SymbolsToKeepGlobal;
72
73 // Map options
74 StringMap<SectionRename> SectionsToRename;
75 StringMap<StringRef> SymbolsToRename;
76
77 // Boolean options
Jordan Rupprechtfc780bb2018-11-01 17:36:37 +000078 bool DeterministicArchives = true;
Alexander Shaposhnikov8d0b74c2018-10-11 22:33:50 +000079 bool DiscardAll = false;
80 bool ExtractDWO = false;
81 bool KeepFileSymbols = false;
82 bool LocalizeHidden = false;
83 bool OnlyKeepDebug = false;
84 bool PreserveDates = false;
85 bool StripAll = false;
86 bool StripAllGNU = false;
87 bool StripDWO = false;
88 bool StripDebug = false;
89 bool StripNonAlloc = false;
90 bool StripSections = false;
91 bool StripUnneeded = false;
92 bool Weaken = false;
93 bool DecompressDebugSections = false;
94 DebugCompressionType CompressionType = DebugCompressionType::None;
95};
96
97// Configuration for the overall invocation of this tool. When invoked as
98// objcopy, will always contain exactly one CopyConfig. When invoked as strip,
99// will contain one or more CopyConfigs.
100struct DriverConfig {
101 SmallVector<CopyConfig, 1> CopyConfigs;
102};
103
104// ParseObjcopyOptions returns the config and sets the input arguments. If a
105// help flag is set then ParseObjcopyOptions will print the help messege and
106// exit.
107DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr);
108
109// ParseStripOptions returns the config and sets the input arguments. If a
110// help flag is set then ParseStripOptions will print the help messege and
111// exit.
112DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr);
113
114} // namespace objcopy
115} // namespace llvm
116
117#endif