blob: cb0aaf0817d0c12651b650ddc880f9a00a60fe4c [file] [log] [blame]
Eugene Zelenko0ad18f82017-11-01 21:16:06 +00001//===- llvm-objcopy.cpp ---------------------------------------------------===//
Petr Hosek05a04cb2017-08-01 00:33:58 +00002//
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//===----------------------------------------------------------------------===//
Eugene Zelenko0ad18f82017-11-01 21:16:06 +00009
Petr Hosek05a04cb2017-08-01 00:33:58 +000010#include "llvm-objcopy.h"
11#include "Object.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000012#include "llvm/ADT/STLExtras.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Twine.h"
15#include "llvm/BinaryFormat/ELF.h"
16#include "llvm/Object/Binary.h"
17#include "llvm/Object/ELFObjectFile.h"
18#include "llvm/Object/ELFTypes.h"
19#include "llvm/Object/Error.h"
Jake Ehrlichcafa1122018-04-11 23:37:03 +000020#include "llvm/Option/Arg.h"
21#include "llvm/Option/ArgList.h"
22#include "llvm/Option/Option.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000023#include "llvm/Support/Casting.h"
Petr Hosek05a04cb2017-08-01 00:33:58 +000024#include "llvm/Support/CommandLine.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000025#include "llvm/Support/Compiler.h"
26#include "llvm/Support/Error.h"
27#include "llvm/Support/ErrorHandling.h"
28#include "llvm/Support/ErrorOr.h"
Petr Hosek05a04cb2017-08-01 00:33:58 +000029#include "llvm/Support/FileOutputBuffer.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000030#include "llvm/Support/ManagedStatic.h"
Petr Hosek05a04cb2017-08-01 00:33:58 +000031#include "llvm/Support/PrettyStackTrace.h"
32#include "llvm/Support/Signals.h"
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000033#include "llvm/Support/raw_ostream.h"
34#include <algorithm>
35#include <cassert>
36#include <cstdlib>
37#include <functional>
38#include <iterator>
Petr Hosek05a04cb2017-08-01 00:33:58 +000039#include <memory>
40#include <string>
41#include <system_error>
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000042#include <utility>
Petr Hosek05a04cb2017-08-01 00:33:58 +000043
44using namespace llvm;
45using namespace object;
46using namespace ELF;
47
Jake Ehrlichcafa1122018-04-11 23:37:03 +000048namespace {
49
50enum ID {
51 OBJCOPY_INVALID = 0, // This is not an option ID.
52#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
53 HELPTEXT, METAVAR, VALUES) \
54 OBJCOPY_##ID,
55#include "Opts.inc"
56#undef OPTION
57};
58
59#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
60#include "Opts.inc"
61#undef PREFIX
62
63static constexpr opt::OptTable::Info ObjcopyInfoTable[] = {
64#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
65 HELPTEXT, METAVAR, VALUES) \
66 {PREFIX, NAME, HELPTEXT, \
67 METAVAR, OBJCOPY_##ID, opt::Option::KIND##Class, \
68 PARAM, FLAGS, OBJCOPY_##GROUP, \
69 OBJCOPY_##ALIAS, ALIASARGS, VALUES},
70#include "Opts.inc"
71#undef OPTION
72};
73
74class ObjcopyOptTable : public opt::OptTable {
75public:
76 ObjcopyOptTable() : OptTable(ObjcopyInfoTable, true) {}
77};
78
79} // namespace
80
Petr Hosek05a04cb2017-08-01 00:33:58 +000081// The name this program was invoked as.
82static StringRef ToolName;
83
84namespace llvm {
85
Zachary Turner41a9ee92017-10-11 23:54:34 +000086LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
Petr Hosek05a04cb2017-08-01 00:33:58 +000087 errs() << ToolName << ": " << Message << ".\n";
88 errs().flush();
89 exit(1);
90}
91
92LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, std::error_code EC) {
93 assert(EC);
94 errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
95 exit(1);
96}
97
Eugene Zelenko0ad18f82017-11-01 21:16:06 +000098LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
Petr Hosek05a04cb2017-08-01 00:33:58 +000099 assert(E);
100 std::string Buf;
101 raw_string_ostream OS(Buf);
102 logAllUnhandledErrors(std::move(E), OS, "");
103 OS.flush();
104 errs() << ToolName << ": '" << File << "': " << Buf;
105 exit(1);
106}
Petr Hosek05a04cb2017-08-01 00:33:58 +0000107
Eugene Zelenko0ad18f82017-11-01 21:16:06 +0000108} // end namespace llvm
109
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000110struct CopyConfig {
111 StringRef OutputFilename;
112 StringRef InputFilename;
113 StringRef OutputFormat;
114 StringRef InputFormat;
115 StringRef BinaryArch;
Alexander Shaposhnikovfedb0162018-02-09 23:33:31 +0000116
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000117 StringRef SplitDWO;
118 StringRef AddGnuDebugLink;
119 std::vector<StringRef> ToRemove;
120 std::vector<StringRef> Keep;
121 std::vector<StringRef> OnlyKeep;
122 std::vector<StringRef> AddSection;
123 bool StripAll;
124 bool StripAllGNU;
125 bool StripDebug;
126 bool StripSections;
127 bool StripNonAlloc;
128 bool StripDWO;
129 bool ExtractDWO;
130 bool LocalizeHidden;
131};
Jake Ehrlichf03384d2017-10-11 18:09:18 +0000132
Eugene Zelenko0ad18f82017-11-01 21:16:06 +0000133using SectionPred = std::function<bool(const SectionBase &Sec)>;
Petr Hosek05a04cb2017-08-01 00:33:58 +0000134
Jake Ehrlich777fb002017-12-15 20:17:55 +0000135bool IsDWOSection(const SectionBase &Sec) { return Sec.Name.endswith(".dwo"); }
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000136
Jake Ehrlich76e91102018-01-25 22:46:17 +0000137bool OnlyKeepDWOPred(const Object &Obj, const SectionBase &Sec) {
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000138 // We can't remove the section header string table.
Jake Ehrlich76e91102018-01-25 22:46:17 +0000139 if (&Sec == Obj.SectionNames)
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000140 return false;
141 // Short of keeping the string table we want to keep everything that is a DWO
142 // section and remove everything else.
143 return !IsDWOSection(Sec);
144}
145
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000146std::unique_ptr<Writer> CreateWriter(const CopyConfig &Config, Object &Obj,
147 StringRef File, ElfType OutputElfType) {
148 if (Config.OutputFormat == "binary") {
149 return llvm::make_unique<BinaryWriter>(File, Obj);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000150 }
151 // Depending on the initial ELFT and OutputFormat we need a different Writer.
152 switch (OutputElfType) {
153 case ELFT_ELF32LE:
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000154 return llvm::make_unique<ELFWriter<ELF32LE>>(File, Obj,
155 !Config.StripSections);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000156 case ELFT_ELF64LE:
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000157 return llvm::make_unique<ELFWriter<ELF64LE>>(File, Obj,
158 !Config.StripSections);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000159 case ELFT_ELF32BE:
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000160 return llvm::make_unique<ELFWriter<ELF32BE>>(File, Obj,
161 !Config.StripSections);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000162 case ELFT_ELF64BE:
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000163 return llvm::make_unique<ELFWriter<ELF64BE>>(File, Obj,
164 !Config.StripSections);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000165 }
166 llvm_unreachable("Invalid output format");
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000167}
168
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000169void SplitDWOToFile(const CopyConfig &Config, const Reader &Reader,
170 StringRef File, ElfType OutputElfType) {
Jake Ehrlich76e91102018-01-25 22:46:17 +0000171 auto DWOFile = Reader.create();
172 DWOFile->removeSections(
173 [&](const SectionBase &Sec) { return OnlyKeepDWOPred(*DWOFile, Sec); });
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000174 auto Writer = CreateWriter(Config, *DWOFile, File, OutputElfType);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000175 Writer->finalize();
176 Writer->write();
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000177}
178
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000179// This function handles the high level operations of GNU objcopy including
180// handling command line options. It's important to outline certain properties
181// we expect to hold of the command line operations. Any operation that "keeps"
182// should keep regardless of a remove. Additionally any removal should respect
183// any previous removals. Lastly whether or not something is removed shouldn't
184// depend a) on the order the options occur in or b) on some opaque priority
185// system. The only priority is that keeps/copies overrule removes.
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000186void HandleArgs(const CopyConfig &Config, Object &Obj, const Reader &Reader,
187 ElfType OutputElfType) {
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000188
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000189 if (!Config.SplitDWO.empty()) {
190 SplitDWOToFile(Config, Reader, Config.SplitDWO, OutputElfType);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000191 }
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000192
Jake Ehrlich27a29b02018-01-05 19:19:09 +0000193 // Localize:
194
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000195 if (Config.LocalizeHidden) {
Jake Ehrlich76e91102018-01-25 22:46:17 +0000196 Obj.SymbolTable->localize([](const Symbol &Sym) {
Jake Ehrlich27a29b02018-01-05 19:19:09 +0000197 return Sym.Visibility == STV_HIDDEN || Sym.Visibility == STV_INTERNAL;
198 });
199 }
200
Jake Ehrlichf03384d2017-10-11 18:09:18 +0000201 SectionPred RemovePred = [](const SectionBase &) { return false; };
202
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000203 // Removes:
204
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000205 if (!Config.ToRemove.empty()) {
206 RemovePred = [&Config](const SectionBase &Sec) {
207 return std::find(std::begin(Config.ToRemove), std::end(Config.ToRemove),
208 Sec.Name) != std::end(Config.ToRemove);
Jake Ehrlichf03384d2017-10-11 18:09:18 +0000209 };
Jake Ehrlich36a2eb32017-10-10 18:47:09 +0000210 }
Jake Ehrlichf03384d2017-10-11 18:09:18 +0000211
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000212 if (Config.StripDWO || !Config.SplitDWO.empty())
David Blaikie998ff812017-11-03 20:57:09 +0000213 RemovePred = [RemovePred](const SectionBase &Sec) {
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000214 return IsDWOSection(Sec) || RemovePred(Sec);
215 };
216
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000217 if (Config.ExtractDWO)
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000218 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
Jake Ehrlich76e91102018-01-25 22:46:17 +0000219 return OnlyKeepDWOPred(Obj, Sec) || RemovePred(Sec);
Jake Ehrlich5de70d92017-11-03 18:58:41 +0000220 };
221
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000222 if (Config.StripAllGNU)
Jake Ehrlichfabddf12017-11-13 22:02:07 +0000223 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
224 if (RemovePred(Sec))
225 return true;
226 if ((Sec.Flags & SHF_ALLOC) != 0)
227 return false;
Jake Ehrlich76e91102018-01-25 22:46:17 +0000228 if (&Sec == Obj.SectionNames)
Jake Ehrlichfabddf12017-11-13 22:02:07 +0000229 return false;
Jake Ehrlich777fb002017-12-15 20:17:55 +0000230 switch (Sec.Type) {
Jake Ehrlichfabddf12017-11-13 22:02:07 +0000231 case SHT_SYMTAB:
232 case SHT_REL:
233 case SHT_RELA:
234 case SHT_STRTAB:
235 return true;
236 }
237 return Sec.Name.startswith(".debug");
238 };
239
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000240 if (Config.StripSections) {
Jake Ehrlichf03384d2017-10-11 18:09:18 +0000241 RemovePred = [RemovePred](const SectionBase &Sec) {
242 return RemovePred(Sec) || (Sec.Flags & SHF_ALLOC) == 0;
243 };
Jake Ehrlichf03384d2017-10-11 18:09:18 +0000244 }
245
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000246 if (Config.StripDebug) {
Jake Ehrlich1bfefc12017-11-13 22:13:08 +0000247 RemovePred = [RemovePred](const SectionBase &Sec) {
248 return RemovePred(Sec) || Sec.Name.startswith(".debug");
249 };
250 }
251
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000252 if (Config.StripNonAlloc)
Jake Ehrlichd56725a2017-11-14 18:50:24 +0000253 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
254 if (RemovePred(Sec))
255 return true;
Jake Ehrlich76e91102018-01-25 22:46:17 +0000256 if (&Sec == Obj.SectionNames)
Jake Ehrlichd56725a2017-11-14 18:50:24 +0000257 return false;
258 return (Sec.Flags & SHF_ALLOC) == 0;
259 };
260
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000261 if (Config.StripAll)
Jake Ehrlich6ad72d02017-11-27 18:56:01 +0000262 RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
263 if (RemovePred(Sec))
264 return true;
Jake Ehrlich76e91102018-01-25 22:46:17 +0000265 if (&Sec == Obj.SectionNames)
Jake Ehrlich6ad72d02017-11-27 18:56:01 +0000266 return false;
267 if (Sec.Name.startswith(".gnu.warning"))
268 return false;
269 return (Sec.Flags & SHF_ALLOC) == 0;
270 };
271
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000272 // Explicit copies:
273
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000274 if (!Config.OnlyKeep.empty()) {
275 RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) {
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000276 // Explicitly keep these sections regardless of previous removes.
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000277 if (std::find(std::begin(Config.OnlyKeep), std::end(Config.OnlyKeep),
278 Sec.Name) != std::end(Config.OnlyKeep))
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000279 return false;
280
281 // Allow all implicit removes.
Jake Ehrlich76e91102018-01-25 22:46:17 +0000282 if (RemovePred(Sec))
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000283 return true;
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000284
285 // Keep special sections.
Jake Ehrlich76e91102018-01-25 22:46:17 +0000286 if (Obj.SectionNames == &Sec)
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000287 return false;
Jake Ehrlich76e91102018-01-25 22:46:17 +0000288 if (Obj.SymbolTable == &Sec || Obj.SymbolTable->getStrTab() == &Sec)
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000289 return false;
Jake Ehrlich76e91102018-01-25 22:46:17 +0000290
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000291 // Remove everything else.
292 return true;
293 };
294 }
295
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000296 if (!Config.Keep.empty()) {
297 RemovePred = [Config, RemovePred](const SectionBase &Sec) {
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000298 // Explicitly keep these sections regardless of previous removes.
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000299 if (std::find(std::begin(Config.Keep), std::end(Config.Keep), Sec.Name) !=
300 std::end(Config.Keep))
Jake Ehrlichef3b80c2017-11-30 20:14:53 +0000301 return false;
302 // Otherwise defer to RemovePred.
303 return RemovePred(Sec);
304 };
305 }
306
Jake Ehrlich76e91102018-01-25 22:46:17 +0000307 Obj.removeSections(RemovePred);
Jake Ehrliche8437de2017-12-19 00:47:30 +0000308
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000309 if (!Config.AddSection.empty()) {
310 for (const auto &Flag : Config.AddSection) {
311 auto SecPair = Flag.split("=");
Jake Ehrliche8437de2017-12-19 00:47:30 +0000312 auto SecName = SecPair.first;
313 auto File = SecPair.second;
314 auto BufOrErr = MemoryBuffer::getFile(File);
315 if (!BufOrErr)
316 reportError(File, BufOrErr.getError());
317 auto Buf = std::move(*BufOrErr);
318 auto BufPtr = reinterpret_cast<const uint8_t *>(Buf->getBufferStart());
319 auto BufSize = Buf->getBufferSize();
Jake Ehrlich76e91102018-01-25 22:46:17 +0000320 Obj.addSection<OwnedDataSection>(SecName,
321 ArrayRef<uint8_t>(BufPtr, BufSize));
Jake Ehrliche8437de2017-12-19 00:47:30 +0000322 }
323 }
324
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000325 if (!Config.AddGnuDebugLink.empty()) {
326 Obj.addSection<GnuDebugLinkSection>(Config.AddGnuDebugLink);
Jake Ehrlichea07d3c2018-01-25 22:15:14 +0000327 }
Jake Ehrlich76e91102018-01-25 22:46:17 +0000328}
Jake Ehrlichea07d3c2018-01-25 22:15:14 +0000329
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000330std::unique_ptr<Reader> CreateReader(StringRef InputFilename,
331 ElfType &OutputElfType) {
Jake Ehrlich76e91102018-01-25 22:46:17 +0000332 // Right now we can only read ELF files so there's only one reader;
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000333 auto Out = llvm::make_unique<ELFReader>(InputFilename);
Jake Ehrlich76e91102018-01-25 22:46:17 +0000334 // We need to set the default ElfType for output.
335 OutputElfType = Out->getElfType();
336 return std::move(Out);
Petr Hosek05a04cb2017-08-01 00:33:58 +0000337}
338
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000339void ExecuteElfObjcopy(const CopyConfig &Config) {
340 ElfType OutputElfType;
341 auto Reader = CreateReader(Config.InputFilename, OutputElfType);
342 auto Obj = Reader->create();
343 auto Writer =
344 CreateWriter(Config, *Obj, Config.OutputFilename, OutputElfType);
345 HandleArgs(Config, *Obj, *Reader, OutputElfType);
346 Writer->finalize();
347 Writer->write();
348}
349
350// ParseObjcopyOptions returns the config and sets the input arguments. If a
351// help flag is set then ParseObjcopyOptions will print the help messege and
352// exit.
353CopyConfig ParseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
354 ObjcopyOptTable T;
355 unsigned MissingArgumentIndex, MissingArgumentCount;
356 llvm::opt::InputArgList InputArgs =
357 T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
358
359 if (InputArgs.size() == 0 || InputArgs.hasArg(OBJCOPY_help)) {
360 T.PrintHelp(outs(), "llvm-objcopy <input> [ <output> ]", "objcopy tool");
361 exit(0);
362 }
363
364 SmallVector<const char *, 2> Positional;
365
366 for (auto Arg : InputArgs.filtered(OBJCOPY_UNKNOWN))
367 error("unknown argument '" + Arg->getAsString(InputArgs) + "'");
368
369 for (auto Arg : InputArgs.filtered(OBJCOPY_INPUT))
370 Positional.push_back(Arg->getValue());
371
372 if (Positional.empty())
373 error("No input file specified");
374
375 if (Positional.size() > 2)
376 error("Too many positional arguments");
377
378 CopyConfig Config;
379 Config.InputFilename = Positional[0];
380 Config.OutputFilename = Positional[Positional.size() == 1 ? 0 : 1];
381 Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_input_target);
382 Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_output_target);
383 Config.BinaryArch = InputArgs.getLastArgValue(OBJCOPY_binary_architecture);
384
385 Config.SplitDWO = InputArgs.getLastArgValue(OBJCOPY_split_dwo);
386 Config.AddGnuDebugLink = InputArgs.getLastArgValue(OBJCOPY_add_gnu_debuglink);
387 for (auto Arg : InputArgs.filtered(OBJCOPY_remove_section))
388 Config.ToRemove.push_back(Arg->getValue());
389 for (auto Arg : InputArgs.filtered(OBJCOPY_keep))
390 Config.Keep.push_back(Arg->getValue());
391 for (auto Arg : InputArgs.filtered(OBJCOPY_only_keep))
392 Config.OnlyKeep.push_back(Arg->getValue());
393 for (auto Arg : InputArgs.filtered(OBJCOPY_add_section))
394 Config.AddSection.push_back(Arg->getValue());
395 Config.StripAll = InputArgs.hasArg(OBJCOPY_strip_all);
396 Config.StripAllGNU = InputArgs.hasArg(OBJCOPY_strip_all_gnu);
397 Config.StripDebug = InputArgs.hasArg(OBJCOPY_strip_debug);
398 Config.StripDWO = InputArgs.hasArg(OBJCOPY_strip_dwo);
399 Config.StripSections = InputArgs.hasArg(OBJCOPY_strip_sections);
400 Config.StripNonAlloc = InputArgs.hasArg(OBJCOPY_strip_non_alloc);
401 Config.ExtractDWO = InputArgs.hasArg(OBJCOPY_extract_dwo);
402 Config.LocalizeHidden = InputArgs.hasArg(OBJCOPY_localize_hidden);
403
404 return Config;
405}
406
Petr Hosek05a04cb2017-08-01 00:33:58 +0000407int main(int argc, char **argv) {
408 // Print a stack trace if we signal out.
409 sys::PrintStackTraceOnErrorSignal(argv[0]);
410 PrettyStackTraceProgram X(argc, argv);
411 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
Petr Hosek05a04cb2017-08-01 00:33:58 +0000412 ToolName = argv[0];
Jake Ehrlich76e91102018-01-25 22:46:17 +0000413
Jake Ehrlichcafa1122018-04-11 23:37:03 +0000414 CopyConfig Config = ParseObjcopyOptions(makeArrayRef(argv + 1, argc));
415 ExecuteElfObjcopy(Config);
Petr Hosek05a04cb2017-08-01 00:33:58 +0000416}