2011-01-01 01:31:54 +08:00
|
|
|
//===--- Job.cpp - Command to Execute -------------------------------------===//
|
2009-03-14 07:36:33 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-07-17 11:35:54 +08:00
|
|
|
#include "InputInfo.h"
|
2014-02-19 05:42:51 +08:00
|
|
|
#include "clang/Driver/Driver.h"
|
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
2009-03-14 07:36:33 +08:00
|
|
|
#include "clang/Driver/Job.h"
|
2014-02-19 05:42:51 +08:00
|
|
|
#include "clang/Driver/Tool.h"
|
|
|
|
#include "clang/Driver/ToolChain.h"
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2011-08-03 01:58:04 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-09-13 02:23:34 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2013-09-13 02:23:34 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2013-09-13 02:35:08 +08:00
|
|
|
#include "llvm/Support/Program.h"
|
2013-09-13 02:23:34 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-03-14 07:36:33 +08:00
|
|
|
#include <cassert>
|
|
|
|
using namespace clang::driver;
|
2013-09-13 02:23:34 +08:00
|
|
|
using llvm::raw_ostream;
|
|
|
|
using llvm::StringRef;
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
using llvm::ArrayRef;
|
2009-03-14 07:36:33 +08:00
|
|
|
|
2015-07-03 06:52:04 +08:00
|
|
|
Command::Command(const Action &Source, const Tool &Creator,
|
2015-07-17 11:35:54 +08:00
|
|
|
const char *Executable, const ArgStringList &Arguments,
|
|
|
|
ArrayRef<InputInfo> Inputs)
|
2015-07-03 06:52:08 +08:00
|
|
|
: Source(Source), Creator(Creator), Executable(Executable),
|
2015-07-17 11:35:54 +08:00
|
|
|
Arguments(Arguments), ResponseFile(nullptr) {
|
|
|
|
for (const auto &II : Inputs)
|
|
|
|
if (II.isFilename())
|
|
|
|
InputFilenames.push_back(II.getFilename());
|
|
|
|
}
|
2009-03-14 07:36:33 +08:00
|
|
|
|
2015-03-12 08:52:56 +08:00
|
|
|
static int skipArgs(const char *Flag, bool HaveCrashVFS) {
|
2013-09-13 02:23:34 +08:00
|
|
|
// These flags are all of the form -Flag <Arg> and are treated as two
|
|
|
|
// arguments. Therefore, we need to skip the flag and the next argument.
|
|
|
|
bool Res = llvm::StringSwitch<bool>(Flag)
|
|
|
|
.Cases("-I", "-MF", "-MT", "-MQ", true)
|
|
|
|
.Cases("-o", "-coverage-file", "-dependency-file", true)
|
|
|
|
.Cases("-fdebug-compilation-dir", "-idirafter", true)
|
|
|
|
.Cases("-include", "-include-pch", "-internal-isystem", true)
|
|
|
|
.Cases("-internal-externc-isystem", "-iprefix", "-iwithprefix", true)
|
2015-03-12 08:52:56 +08:00
|
|
|
.Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
|
2013-09-13 02:23:34 +08:00
|
|
|
.Cases("-resource-dir", "-serialize-diagnostic-file", true)
|
2014-06-23 04:35:10 +08:00
|
|
|
.Cases("-dwarf-debug-flags", "-ivfsoverlay", true)
|
2015-03-12 08:52:56 +08:00
|
|
|
// Some include flags shouldn't be skipped if we have a crash VFS
|
|
|
|
.Case("-isysroot", !HaveCrashVFS)
|
2013-09-13 02:23:34 +08:00
|
|
|
.Default(false);
|
|
|
|
|
|
|
|
// Match found.
|
|
|
|
if (Res)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
// The remaining flags are treated as a single argument.
|
|
|
|
|
|
|
|
// These flags are all of the form -Flag and have no second argument.
|
|
|
|
Res = llvm::StringSwitch<bool>(Flag)
|
|
|
|
.Cases("-M", "-MM", "-MG", "-MP", "-MD", true)
|
|
|
|
.Case("-MMD", true)
|
|
|
|
.Default(false);
|
|
|
|
|
|
|
|
// Match found.
|
|
|
|
if (Res)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// These flags are treated as a single argument (e.g., -F<Dir>).
|
|
|
|
StringRef FlagRef(Flag);
|
2014-04-23 05:30:17 +08:00
|
|
|
if (FlagRef.startswith("-F") || FlagRef.startswith("-I") ||
|
|
|
|
FlagRef.startswith("-fmodules-cache-path="))
|
2013-09-13 02:23:34 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-09 14:58:31 +08:00
|
|
|
void Command::printArg(raw_ostream &OS, const char *Arg, bool Quote) {
|
2013-09-13 02:23:34 +08:00
|
|
|
const bool Escape = std::strpbrk(Arg, "\"\\$");
|
|
|
|
|
|
|
|
if (!Quote && !Escape) {
|
|
|
|
OS << Arg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Quote and escape. This isn't really complete, but good enough.
|
|
|
|
OS << '"';
|
|
|
|
while (const char c = *Arg++) {
|
|
|
|
if (c == '"' || c == '\\' || c == '$')
|
|
|
|
OS << '\\';
|
|
|
|
OS << c;
|
|
|
|
}
|
|
|
|
OS << '"';
|
|
|
|
}
|
|
|
|
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
void Command::writeResponseFile(raw_ostream &OS) const {
|
|
|
|
// In a file list, we only write the set of inputs to the response file
|
|
|
|
if (Creator.getResponseFilesSupport() == Tool::RF_FileList) {
|
|
|
|
for (const char *Arg : InputFileList) {
|
|
|
|
OS << Arg << '\n';
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-16 06:42:37 +08:00
|
|
|
// In regular response files, we send all arguments to the response file.
|
|
|
|
// Wrapping all arguments in double quotes ensures that both Unix tools and
|
|
|
|
// Windows tools understand the response file.
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
for (const char *Arg : Arguments) {
|
|
|
|
OS << '"';
|
|
|
|
|
|
|
|
for (; *Arg != '\0'; Arg++) {
|
|
|
|
if (*Arg == '\"' || *Arg == '\\') {
|
|
|
|
OS << '\\';
|
|
|
|
}
|
|
|
|
OS << *Arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\" ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::buildArgvForResponseFile(
|
|
|
|
llvm::SmallVectorImpl<const char *> &Out) const {
|
|
|
|
// When not a file list, all arguments are sent to the response file.
|
|
|
|
// This leaves us to set the argv to a single parameter, requesting the tool
|
|
|
|
// to read the response file.
|
|
|
|
if (Creator.getResponseFilesSupport() != Tool::RF_FileList) {
|
|
|
|
Out.push_back(Executable);
|
|
|
|
Out.push_back(ResponseFileFlag.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::StringSet<> Inputs;
|
|
|
|
for (const char *InputName : InputFileList)
|
|
|
|
Inputs.insert(InputName);
|
|
|
|
Out.push_back(Executable);
|
|
|
|
// In a file list, build args vector ignoring parameters that will go in the
|
|
|
|
// response file (elements of the InputFileList vector)
|
|
|
|
bool FirstInput = true;
|
|
|
|
for (const char *Arg : Arguments) {
|
|
|
|
if (Inputs.count(Arg) == 0) {
|
|
|
|
Out.push_back(Arg);
|
|
|
|
} else if (FirstInput) {
|
|
|
|
FirstInput = false;
|
|
|
|
Out.push_back(Creator.getResponseFileFlag());
|
|
|
|
Out.push_back(ResponseFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 02:23:34 +08:00
|
|
|
void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
|
2014-10-22 01:24:44 +08:00
|
|
|
CrashReportInfo *CrashInfo) const {
|
2014-08-06 04:49:12 +08:00
|
|
|
// Always quote the exe.
|
2014-08-07 08:05:00 +08:00
|
|
|
OS << ' ';
|
2015-07-09 14:58:31 +08:00
|
|
|
printArg(OS, Executable, /*Quote=*/true);
|
2013-09-13 02:23:34 +08:00
|
|
|
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
llvm::ArrayRef<const char *> Args = Arguments;
|
|
|
|
llvm::SmallVector<const char *, 128> ArgsRespFile;
|
|
|
|
if (ResponseFile != nullptr) {
|
|
|
|
buildArgvForResponseFile(ArgsRespFile);
|
|
|
|
Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name
|
|
|
|
}
|
|
|
|
|
2015-03-12 08:52:56 +08:00
|
|
|
bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty();
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
for (size_t i = 0, e = Args.size(); i < e; ++i) {
|
|
|
|
const char *const Arg = Args[i];
|
2013-09-13 02:23:34 +08:00
|
|
|
|
2014-10-22 01:24:44 +08:00
|
|
|
if (CrashInfo) {
|
2015-03-12 08:52:56 +08:00
|
|
|
if (int Skip = skipArgs(Arg, HaveCrashVFS)) {
|
2013-09-13 02:23:34 +08:00
|
|
|
i += Skip - 1;
|
|
|
|
continue;
|
2015-07-17 11:35:54 +08:00
|
|
|
}
|
|
|
|
auto Found = std::find_if(InputFilenames.begin(), InputFilenames.end(),
|
|
|
|
[&Arg](StringRef IF) { return IF == Arg; });
|
|
|
|
if (Found != InputFilenames.end() &&
|
|
|
|
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
|
2014-10-22 01:24:44 +08:00
|
|
|
// Replace the input file name with the crashinfo's file name.
|
|
|
|
OS << ' ';
|
|
|
|
StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
|
2015-07-09 14:58:31 +08:00
|
|
|
printArg(OS, ShortName.str().c_str(), Quote);
|
2014-10-22 01:24:44 +08:00
|
|
|
continue;
|
2013-09-13 02:23:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << ' ';
|
2015-07-09 14:58:31 +08:00
|
|
|
printArg(OS, Arg, Quote);
|
2013-09-13 02:23:34 +08:00
|
|
|
}
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
|
2015-03-12 08:52:56 +08:00
|
|
|
if (CrashInfo && HaveCrashVFS) {
|
2014-10-22 01:24:44 +08:00
|
|
|
OS << ' ';
|
2015-07-09 14:58:31 +08:00
|
|
|
printArg(OS, "-ivfsoverlay", Quote);
|
2014-10-22 01:24:44 +08:00
|
|
|
OS << ' ';
|
2015-07-09 14:58:31 +08:00
|
|
|
printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
|
2014-10-22 01:24:44 +08:00
|
|
|
}
|
|
|
|
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
if (ResponseFile != nullptr) {
|
|
|
|
OS << "\n Arguments passed via response file:\n";
|
|
|
|
writeResponseFile(OS);
|
|
|
|
// Avoiding duplicated newline terminator, since FileLists are
|
|
|
|
// newline-separated.
|
|
|
|
if (Creator.getResponseFilesSupport() != Tool::RF_FileList)
|
|
|
|
OS << "\n";
|
|
|
|
OS << " (end of response file)";
|
|
|
|
}
|
|
|
|
|
2013-09-13 02:23:34 +08:00
|
|
|
OS << Terminator;
|
|
|
|
}
|
|
|
|
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
void Command::setResponseFile(const char *FileName) {
|
|
|
|
ResponseFile = FileName;
|
|
|
|
ResponseFileFlag = Creator.getResponseFileFlag();
|
|
|
|
ResponseFileFlag += FileName;
|
|
|
|
}
|
|
|
|
|
2013-09-18 08:41:15 +08:00
|
|
|
int Command::Execute(const StringRef **Redirects, std::string *ErrMsg,
|
2013-09-13 02:35:08 +08:00
|
|
|
bool *ExecutionFailed) const {
|
|
|
|
SmallVector<const char*, 128> Argv;
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
|
|
|
|
if (ResponseFile == nullptr) {
|
|
|
|
Argv.push_back(Executable);
|
2015-02-18 00:48:30 +08:00
|
|
|
Argv.append(Arguments.begin(), Arguments.end());
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
Argv.push_back(nullptr);
|
|
|
|
|
|
|
|
return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/ nullptr,
|
|
|
|
Redirects, /*secondsToWait*/ 0,
|
|
|
|
/*memoryLimit*/ 0, ErrMsg,
|
|
|
|
ExecutionFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to put arguments in a response file (command is too large)
|
|
|
|
// Open stream to store the response file contents
|
|
|
|
std::string RespContents;
|
|
|
|
llvm::raw_string_ostream SS(RespContents);
|
|
|
|
|
|
|
|
// Write file contents and build the Argv vector
|
|
|
|
writeResponseFile(SS);
|
|
|
|
buildArgvForResponseFile(Argv);
|
2014-05-18 00:56:41 +08:00
|
|
|
Argv.push_back(nullptr);
|
Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!
This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.
I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.
I designed it to support different kinds of tools and
internationalisation needs:
- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )
With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.
Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.
In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.
Reviewers: asl, rafael, silvas
Reviewed By: silvas
Subscribers: silvas, rnk, thakis, cfe-commits
Differential Revision: http://reviews.llvm.org/D4897
llvm-svn: 217792
2014-09-16 01:45:39 +08:00
|
|
|
SS.flush();
|
|
|
|
|
|
|
|
// Save the response file in the appropriate encoding
|
|
|
|
if (std::error_code EC = writeFileWithEncoding(
|
|
|
|
ResponseFile, RespContents, Creator.getResponseFileEncoding())) {
|
|
|
|
if (ErrMsg)
|
|
|
|
*ErrMsg = EC.message();
|
|
|
|
if (ExecutionFailed)
|
|
|
|
*ExecutionFailed = true;
|
|
|
|
return -1;
|
|
|
|
}
|
2013-09-13 02:35:08 +08:00
|
|
|
|
2014-05-18 00:56:41 +08:00
|
|
|
return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/ nullptr,
|
2013-09-13 02:35:08 +08:00
|
|
|
Redirects, /*secondsToWait*/ 0,
|
|
|
|
/*memoryLimit*/ 0, ErrMsg, ExecutionFailed);
|
|
|
|
}
|
|
|
|
|
2013-09-20 04:32:16 +08:00
|
|
|
FallbackCommand::FallbackCommand(const Action &Source_, const Tool &Creator_,
|
|
|
|
const char *Executable_,
|
|
|
|
const ArgStringList &Arguments_,
|
2015-07-17 11:35:54 +08:00
|
|
|
ArrayRef<InputInfo> Inputs,
|
2014-09-05 00:04:28 +08:00
|
|
|
std::unique_ptr<Command> Fallback_)
|
2015-07-17 11:35:54 +08:00
|
|
|
: Command(Source_, Creator_, Executable_, Arguments_, Inputs),
|
2014-09-05 00:04:28 +08:00
|
|
|
Fallback(std::move(Fallback_)) {}
|
2013-09-20 04:32:16 +08:00
|
|
|
|
|
|
|
void FallbackCommand::Print(raw_ostream &OS, const char *Terminator,
|
2014-10-22 01:24:44 +08:00
|
|
|
bool Quote, CrashReportInfo *CrashInfo) const {
|
|
|
|
Command::Print(OS, "", Quote, CrashInfo);
|
2013-09-20 04:32:16 +08:00
|
|
|
OS << " ||";
|
2014-10-22 01:24:44 +08:00
|
|
|
Fallback->Print(OS, Terminator, Quote, CrashInfo);
|
2013-09-20 04:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool ShouldFallback(int ExitCode) {
|
|
|
|
// FIXME: We really just want to fall back for internal errors, such
|
|
|
|
// as when some symbol cannot be mangled, when we should be able to
|
|
|
|
// parse something but can't, etc.
|
|
|
|
return ExitCode != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FallbackCommand::Execute(const StringRef **Redirects, std::string *ErrMsg,
|
|
|
|
bool *ExecutionFailed) const {
|
|
|
|
int PrimaryStatus = Command::Execute(Redirects, ErrMsg, ExecutionFailed);
|
|
|
|
if (!ShouldFallback(PrimaryStatus))
|
|
|
|
return PrimaryStatus;
|
|
|
|
|
|
|
|
// Clear ExecutionFailed and ErrMsg before falling back.
|
|
|
|
if (ErrMsg)
|
|
|
|
ErrMsg->clear();
|
|
|
|
if (ExecutionFailed)
|
|
|
|
*ExecutionFailed = false;
|
|
|
|
|
2014-02-19 05:42:51 +08:00
|
|
|
const Driver &D = getCreator().getToolChain().getDriver();
|
2014-02-19 10:10:19 +08:00
|
|
|
D.Diag(diag::warn_drv_invoking_fallback) << Fallback->getExecutable();
|
2014-02-19 05:42:51 +08:00
|
|
|
|
2013-09-20 04:32:16 +08:00
|
|
|
int SecondaryStatus = Fallback->Execute(Redirects, ErrMsg, ExecutionFailed);
|
|
|
|
return SecondaryStatus;
|
|
|
|
}
|
|
|
|
|
2013-09-13 02:23:34 +08:00
|
|
|
void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
|
2014-10-22 01:24:44 +08:00
|
|
|
CrashReportInfo *CrashInfo) const {
|
2014-10-03 09:04:53 +08:00
|
|
|
for (const auto &Job : *this)
|
2014-10-22 01:24:44 +08:00
|
|
|
Job.Print(OS, Terminator, Quote, CrashInfo);
|
2013-09-13 02:23:34 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 00:04:28 +08:00
|
|
|
void JobList::clear() { Jobs.clear(); }
|