[llvm] r371911 - [llvm-objcopy] Add support for response files in llvm-strip and llvm-objcopy
Michael Pozulp via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 18:14:43 PDT 2019
Author: pozulp
Date: Fri Sep 13 18:14:43 2019
New Revision: 371911
URL: http://llvm.org/viewvc/llvm-project?rev=371911&view=rev
Log:
[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
Added:
llvm/trunk/test/tools/llvm-objcopy/ELF/response-file.test
Modified:
llvm/trunk/docs/CommandGuide/llvm-objcopy.rst
llvm/trunk/docs/CommandGuide/llvm-strip.rst
llvm/trunk/test/tools/llvm-objcopy/ELF/help-message.test
llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
Modified: llvm/trunk/docs/CommandGuide/llvm-objcopy.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-objcopy.rst?rev=371911&r1=371910&r2=371911&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-objcopy.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-objcopy.rst Fri Sep 13 18:14:43 2019
@@ -129,6 +129,10 @@ multiple file formats.
Display the version of this program.
+.. option:: @<FILE>
+
+ Read command-line options and commands from response file `<FILE>`.
+
COFF-SPECIFIC OPTIONS
---------------------
Modified: llvm/trunk/docs/CommandGuide/llvm-strip.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-strip.rst?rev=371911&r1=371910&r2=371911&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-strip.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-strip.rst Fri Sep 13 18:14:43 2019
@@ -104,6 +104,10 @@ multiple file formats.
Display the version of this program.
+.. option:: @<FILE>
+
+ Read command-line options and commands from response file `<FILE>`.
+
COFF-SPECIFIC OPTIONS
---------------------
Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/help-message.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/help-message.test?rev=371911&r1=371910&r2=371911&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/help-message.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/help-message.test Fri Sep 13 18:14:43 2019
@@ -14,6 +14,10 @@
# OBJCOPY-USAGE: USAGE: llvm-objcopy
+# OBJCOPY-USAGE: @FILE
+
# STRIP-USAGE: USAGE: llvm-strip
+# STRIP-USAGE: @FILE
+
# UNKNOWN-ARG: unknown argument '{{-+}}abcabc'
# NO-INPUT-FILES: no input file specified
Added: llvm/trunk/test/tools/llvm-objcopy/ELF/response-file.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/response-file.test?rev=371911&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/response-file.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/response-file.test Fri Sep 13 18:14:43 2019
@@ -0,0 +1,20 @@
+## Check that we support response files.
+# RUN: yaml2obj %s -o %t.o
+# RUN: echo "--strip-debug %t.o" > %t-response
+# RUN: llvm-objcopy @%t-response %t2.o
+# RUN: llvm-strip @%t-response
+
+# RUN: llvm-readobj -S %t.o | FileCheck %s
+# RUN: cmp %t.o %t2.o
+
+# CHECK-NOT: .debug_foo
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .debug_foo
+ Type: SHT_PROGBITS
Modified: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp?rev=371911&r1=371910&r2=371911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp Fri Sep 13 18:14:43 2019
@@ -410,6 +410,16 @@ template <class T> static ErrorOr<T> get
return Result;
}
+static void printHelp(const opt::OptTable &OptTable, raw_ostream &OS,
+ StringRef ToolName) {
+ OptTable.PrintHelp(OS, (ToolName + " input [output]").str().c_str(),
+ (ToolName + " tool").str().c_str());
+ // TODO: Replace this with libOption call once it adds extrahelp support.
+ // The CommandLine library has a cl::extrahelp class to support this,
+ // but libOption does not have that yet.
+ OS << "\nPass @FILE as argument to read options from FILE.\n";
+}
+
// ParseObjcopyOptions returns the config and sets the input arguments. If a
// help flag is set then ParseObjcopyOptions will print the help messege and
// exit.
@@ -421,12 +431,12 @@ Expected<DriverConfig> parseObjcopyOptio
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
if (InputArgs.size() == 0) {
- T.PrintHelp(errs(), "llvm-objcopy input [output]", "objcopy tool");
+ printHelp(T, errs(), "llvm-objcopy");
exit(1);
}
if (InputArgs.hasArg(OBJCOPY_help)) {
- T.PrintHelp(outs(), "llvm-objcopy input [output]", "objcopy tool");
+ printHelp(T, outs(), "llvm-objcopy");
exit(0);
}
@@ -790,12 +800,12 @@ parseStripOptions(ArrayRef<const char *>
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
if (InputArgs.size() == 0) {
- T.PrintHelp(errs(), "llvm-strip [options] file...", "strip tool");
+ printHelp(T, errs(), "llvm-strip");
exit(1);
}
if (InputArgs.hasArg(STRIP_help)) {
- T.PrintHelp(outs(), "llvm-strip [options] file...", "strip tool");
+ printHelp(T, outs(), "llvm-strip");
exit(0);
}
Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=371911&r1=371910&r2=371911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Fri Sep 13 18:14:43 2019
@@ -29,6 +29,7 @@
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
@@ -36,6 +37,7 @@
#include "llvm/Support/Memory.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -310,9 +312,25 @@ int main(int argc, char **argv) {
InitLLVM X(argc, argv);
ToolName = argv[0];
bool IsStrip = sys::path::stem(ToolName).contains("strip");
+
+ // Expand response files.
+ // TODO: Move these lines, which are copied from lib/Support/CommandLine.cpp,
+ // into a separate function in the CommandLine library and call that function
+ // here. This is duplicated code.
+ SmallVector<const char *, 20> NewArgv(argv, argv + argc);
+ BumpPtrAllocator A;
+ StringSaver Saver(A);
+ cl::ExpandResponseFiles(Saver,
+ Triple(sys::getProcessTriple()).isOSWindows()
+ ? cl::TokenizeWindowsCommandLine
+ : cl::TokenizeGNUCommandLine,
+ NewArgv);
+
+ auto Args = makeArrayRef(NewArgv).drop_front();
+
Expected<DriverConfig> DriverConfig =
- IsStrip ? parseStripOptions(makeArrayRef(argv + 1, argc), reportWarning)
- : parseObjcopyOptions(makeArrayRef(argv + 1, argc));
+ IsStrip ? parseStripOptions(Args, reportWarning)
+ : parseObjcopyOptions(Args);
if (!DriverConfig) {
logAllUnhandledErrors(DriverConfig.takeError(),
WithColor::error(errs(), ToolName));
More information about the llvm-commits
mailing list