llvm.org GIT mirror llvm / 78308f7
[llvm-objcopy] Add support for response files in llvm-strip and llvm-objcopy Summary: Addresses https://bugs.llvm.org/show_bug.cgi?id=42671 Reviewers: jhenderson, espindola, alexshap, rupprecht Reviewed By: jhenderson Subscribers: seiya, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65372 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371911 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Pozulp a month ago
6 changed file(s) with 66 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
127127 .. option:: --version, -V
128128
129129 Display the version of this program.
130
131 .. option:: @
132
133 Read command-line options and commands from response file ``.
130134
131135 COFF-SPECIFIC OPTIONS
132136 ---------------------
103103
104104 Display the version of this program.
105105
106 .. option:: @
107
108 Read command-line options and commands from response file ``.
109
106110 COFF-SPECIFIC OPTIONS
107111 ---------------------
108112
1313
1414
1515 # OBJCOPY-USAGE: USAGE: llvm-objcopy
16 # OBJCOPY-USAGE: @FILE
17
1618 # STRIP-USAGE: USAGE: llvm-strip
19 # STRIP-USAGE: @FILE
20
1721 # UNKNOWN-ARG: unknown argument '{{-+}}abcabc'
1822 # NO-INPUT-FILES: no input file specified
0 ## Check that we support response files.
1 # RUN: yaml2obj %s -o %t.o
2 # RUN: echo "--strip-debug %t.o" > %t-response
3 # RUN: llvm-objcopy @%t-response %t2.o
4 # RUN: llvm-strip @%t-response
5
6 # RUN: llvm-readobj -S %t.o | FileCheck %s
7 # RUN: cmp %t.o %t2.o
8
9 # CHECK-NOT: .debug_foo
10
11 --- !ELF
12 FileHeader:
13 Class: ELFCLASS64
14 Data: ELFDATA2LSB
15 Type: ET_EXEC
16 Machine: EM_X86_64
17 Sections:
18 - Name: .debug_foo
19 Type: SHT_PROGBITS
409409 return Result;
410410 }
411411
412 static void printHelp(const opt::OptTable &OptTable, raw_ostream &OS,
413 StringRef ToolName) {
414 OptTable.PrintHelp(OS, (ToolName + " input [output]").str().c_str(),
415 (ToolName + " tool").str().c_str());
416 // TODO: Replace this with libOption call once it adds extrahelp support.
417 // The CommandLine library has a cl::extrahelp class to support this,
418 // but libOption does not have that yet.
419 OS << "\nPass @FILE as argument to read options from FILE.\n";
420 }
421
412422 // ParseObjcopyOptions returns the config and sets the input arguments. If a
413423 // help flag is set then ParseObjcopyOptions will print the help messege and
414424 // exit.
420430 T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
421431
422432 if (InputArgs.size() == 0) {
423 T.PrintHelp(errs(), "llvm-objcopy input [output]", "objcopy tool");
433 printHelp(T, errs(), "llvm-objcopy");
424434 exit(1);
425435 }
426436
427437 if (InputArgs.hasArg(OBJCOPY_help)) {
428 T.PrintHelp(outs(), "llvm-objcopy input [output]", "objcopy tool");
438 printHelp(T, outs(), "llvm-objcopy");
429439 exit(0);
430440 }
431441
789799 T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
790800
791801 if (InputArgs.size() == 0) {
792 T.PrintHelp(errs(), "llvm-strip [options] file...", "strip tool");
802 printHelp(T, errs(), "llvm-strip");
793803 exit(1);
794804 }
795805
796806 if (InputArgs.hasArg(STRIP_help)) {
797 T.PrintHelp(outs(), "llvm-strip [options] file...", "strip tool");
807 printHelp(T, outs(), "llvm-strip");
798808 exit(0);
799809 }
800810
2828 #include "llvm/Option/ArgList.h"
2929 #include "llvm/Option/Option.h"
3030 #include "llvm/Support/Casting.h"
31 #include "llvm/Support/CommandLine.h"
3132 #include "llvm/Support/Error.h"
3233 #include "llvm/Support/ErrorHandling.h"
3334 #include "llvm/Support/ErrorOr.h"
3536 #include "llvm/Support/Memory.h"
3637 #include "llvm/Support/Path.h"
3738 #include "llvm/Support/Process.h"
39 #include "llvm/Support/StringSaver.h"
3840 #include "llvm/Support/WithColor.h"
3941 #include "llvm/Support/raw_ostream.h"
4042 #include
309311 InitLLVM X(argc, argv);
310312 ToolName = argv[0];
311313 bool IsStrip = sys::path::stem(ToolName).contains("strip");
314
315 // Expand response files.
316 // TODO: Move these lines, which are copied from lib/Support/CommandLine.cpp,
317 // into a separate function in the CommandLine library and call that function
318 // here. This is duplicated code.
319 SmallVector NewArgv(argv, argv + argc);
320 BumpPtrAllocator A;
321 StringSaver Saver(A);
322 cl::ExpandResponseFiles(Saver,
323 Triple(sys::getProcessTriple()).isOSWindows()
324 ? cl::TokenizeWindowsCommandLine
325 : cl::TokenizeGNUCommandLine,
326 NewArgv);
327
328 auto Args = makeArrayRef(NewArgv).drop_front();
329
312330 Expected DriverConfig =
313 IsStrip ? parseStripOptions(makeArrayRef(argv + 1, argc), reportWarning)
314 : parseObjcopyOptions(makeArrayRef(argv + 1, argc));
331 IsStrip ? parseStripOptions(Args, reportWarning)
332 : parseObjcopyOptions(Args);
315333 if (!DriverConfig) {
316334 logAllUnhandledErrors(DriverConfig.takeError(),
317335 WithColor::error(errs(), ToolName));