[PATCH] D13148: ELF2: Support reponse files.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 15:34:00 PDT 2015
ruiu created this revision.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
Replace command line arguments starting with '@' with their file contents.
http://reviews.llvm.org/D13148
Files:
ELF/Driver.h
ELF/DriverUtils.cpp
test/elf2/basic.s
Index: test/elf2/basic.s
===================================================================
--- test/elf2/basic.s
+++ test/elf2/basic.s
@@ -176,6 +176,11 @@
# CHECK-NEXT: }
# CHECK-NEXT: ]
+# RUN: echo " -o %t2" > %t.responsefile
+# RUN: lld -flavor gnu2 %t @%t.responsefile
+# RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \
+# RUN: | FileCheck %s
+
# RUN: not lld -flavor gnu2 %t 2>&1 | FileCheck --check-prefix=NO_O %s
# NO_O: -o must be specified.
Index: ELF/DriverUtils.cpp
===================================================================
--- ELF/DriverUtils.cpp
+++ ELF/DriverUtils.cpp
@@ -16,6 +16,8 @@
#include "Driver.h"
#include "Error.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/StringSaver.h"
using namespace llvm;
@@ -53,7 +55,8 @@
unsigned MissingIndex;
unsigned MissingCount;
- opt::InputArgList Args = Table.ParseArgs(Argv, MissingIndex, MissingCount);
+ std::vector<const char *> ArgvVec = replaceResponseFiles(Argv);
+ opt::InputArgList Args = Table.ParseArgs(ArgvVec, MissingIndex, MissingCount);
if (MissingCount)
error(Twine("missing arg value for \"") + Args.getArgString(MissingIndex) +
"\", expected " + Twine(MissingCount) +
@@ -67,3 +70,13 @@
return Args;
}
+
+// Creates a new command line by replacing options starting with '@'
+// character. '@<filename>' is replaced by the file's contents.
+std::vector<const char *>
+ArgParser::replaceResponseFiles(ArrayRef<const char *> Argv) {
+ SmallVector<const char *, 256> Tokens(Argv.data(), Argv.data() + Argv.size());
+ StringSaver S(Alloc);
+ llvm::cl::ExpandResponseFiles(S, llvm::cl::TokenizeGNUCommandLine, Tokens);
+ return std::vector<const char *>(Tokens.begin(), Tokens.end());
+}
Index: ELF/Driver.h
===================================================================
--- ELF/Driver.h
+++ ELF/Driver.h
@@ -28,6 +28,10 @@
public:
// Parses command line options.
llvm::opt::InputArgList parse(ArrayRef<const char *> Args);
+
+private:
+ std::vector<const char *> replaceResponseFiles(ArrayRef<const char *> Args);
+ llvm::BumpPtrAllocator Alloc;
};
class LinkerDriver {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13148.35680.patch
Type: text/x-patch
Size: 2209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150924/0a309537/attachment.bin>
More information about the llvm-commits
mailing list