diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-02-16 19:11:07 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-02-16 19:11:07 +0000 |
commit | 9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f (patch) | |
tree | a4d2b47d47b30c9f7416757f798b092bf1ea6909 /tools/bugpoint | |
parent | bdf44b929f6bd0983b0f0df0d2ae66610e81e149 (diff) | |
download | external_llvm-9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f.zip external_llvm-9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f.tar.gz external_llvm-9ba8a76f8baaa1092d60ccfbc04e7efdc207c98f.tar.bz2 |
Add possibility to set memory limit for binaries run via libSystem. This
is especially needed for bugpoint. This partly implements PR688
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34349 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/bugpoint')
-rw-r--r-- | tools/bugpoint/BugDriver.cpp | 4 | ||||
-rw-r--r-- | tools/bugpoint/BugDriver.h | 3 | ||||
-rw-r--r-- | tools/bugpoint/ExecutionDriver.cpp | 4 | ||||
-rw-r--r-- | tools/bugpoint/OptimizerDriver.cpp | 3 | ||||
-rw-r--r-- | tools/bugpoint/ToolRunner.cpp | 39 | ||||
-rw-r--r-- | tools/bugpoint/ToolRunner.h | 12 | ||||
-rw-r--r-- | tools/bugpoint/bugpoint.cpp | 6 |
7 files changed, 46 insertions, 25 deletions
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp index 2b4d35d..b2a8f03 100644 --- a/tools/bugpoint/BugDriver.cpp +++ b/tools/bugpoint/BugDriver.cpp @@ -64,10 +64,10 @@ std::string llvm::getPassesString(const std::vector<const PassInfo*> &Passes) { } BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs, - unsigned timeout) + unsigned timeout, unsigned memlimit) : ToolName(toolname), ReferenceOutputFile(OutputFile), Program(0), Interpreter(0), cbe(0), gcc(0), run_as_child(as_child), - run_find_bugs(find_bugs), Timeout(timeout) {} + run_find_bugs(find_bugs), Timeout(timeout), MemoryLimit(memlimit) {} /// ParseInputFile - Given a bytecode or assembly input filename, parse and diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index 3de7b05..ef8118c 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -50,6 +50,7 @@ class BugDriver { bool run_as_child; bool run_find_bugs; unsigned Timeout; + unsigned MemoryLimit; // FIXME: sort out public/private distinctions... friend class ReducePassList; @@ -57,7 +58,7 @@ class BugDriver { public: BugDriver(const char *toolname, bool as_child, bool find_bugs, - unsigned timeout); + unsigned timeout, unsigned memlimit); const std::string &getToolName() const { return ToolName; } diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp index 92e7737..f4a072b 100644 --- a/tools/bugpoint/ExecutionDriver.cpp +++ b/tools/bugpoint/ExecutionDriver.cpp @@ -263,11 +263,11 @@ std::string BugDriver::executeProgram(std::string OutputFile, InterpreterSel == CBE_bug) RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile, OutputFile, AdditionalLinkerArgs, SharedObjs, - Timeout); + Timeout, MemoryLimit); else RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile, OutputFile, std::vector<std::string>(), - SharedObjs, Timeout); + SharedObjs, Timeout, MemoryLimit); if (RetVal == -1) { std::cerr << "<timeout>"; diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 374de26..210f348 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -194,7 +194,8 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, prog = sys::Program::FindProgramByName("valgrind"); else prog = tool; - int result = sys::Program::ExecuteAndWait(prog,args,0,0,Timeout,&ErrMsg); + int result = sys::Program::ExecuteAndWait(prog, args, 0, 0, + Timeout, MemoryLimit, &ErrMsg); // If we are supposed to delete the bytecode file or if the passes crashed, // remove it now. This may fail if the file was never created, but that's ok. diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index 35f27db..150155f 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -32,7 +32,8 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath, const sys::Path &StdInFile, const sys::Path &StdOutFile, const sys::Path &StdErrFile, - unsigned NumSeconds = 0) { + unsigned NumSeconds = 0, + unsigned MemoryLimit = 0) { const sys::Path* redirects[3]; redirects[0] = &StdInFile; redirects[1] = &StdOutFile; @@ -46,7 +47,8 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath, } return - sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds); + sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects, + NumSeconds, MemoryLimit); } @@ -102,7 +104,8 @@ namespace { const std::vector<std::string> &GCCArgs, const std::vector<std::string> &SharedLibs = std::vector<std::string>(), - unsigned Timeout = 0); + unsigned Timeout = 0, + unsigned MemoryLimit = 0); }; } @@ -112,7 +115,8 @@ int LLI::ExecuteProgram(const std::string &Bytecode, const std::string &OutputFile, const std::vector<std::string> &GCCArgs, const std::vector<std::string> &SharedLibs, - unsigned Timeout) { + unsigned Timeout, + unsigned MemoryLimit) { if (!SharedLibs.empty()) throw ToolExecutionError("LLI currently does not support " "loading shared libraries."); @@ -142,7 +146,7 @@ int LLI::ExecuteProgram(const std::string &Bytecode, ); return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0], sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), - Timeout); + Timeout, MemoryLimit); } // LLI create method - Try to find the LLI executable @@ -209,7 +213,8 @@ int LLC::ExecuteProgram(const std::string &Bytecode, const std::string &OutputFile, const std::vector<std::string> &ArgsForGCC, const std::vector<std::string> &SharedLibs, - unsigned Timeout) { + unsigned Timeout, + unsigned MemoryLimit) { sys::Path OutputAsmFile; OutputCode(Bytecode, OutputAsmFile); @@ -220,7 +225,8 @@ int LLC::ExecuteProgram(const std::string &Bytecode, // Assuming LLC worked, compile the result with GCC and run it. return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile, - InputFile, OutputFile, GCCArgs, Timeout); + InputFile, OutputFile, GCCArgs, + Timeout, MemoryLimit); } /// createLLC - Try to find the LLC executable @@ -265,7 +271,8 @@ namespace { std::vector<std::string>(), const std::vector<std::string> &SharedLibs = std::vector<std::string>(), - unsigned Timeout =0 ); + unsigned Timeout =0, + unsigned MemoryLimit =0); }; } @@ -275,7 +282,8 @@ int JIT::ExecuteProgram(const std::string &Bytecode, const std::string &OutputFile, const std::vector<std::string> &GCCArgs, const std::vector<std::string> &SharedLibs, - unsigned Timeout) { + unsigned Timeout, + unsigned MemoryLimit) { if (!GCCArgs.empty()) throw ToolExecutionError("JIT does not support GCC Arguments."); // Construct a vector of parameters, incorporating those from the command-line @@ -306,7 +314,7 @@ int JIT::ExecuteProgram(const std::string &Bytecode, DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n"); return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0], sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), - Timeout); + Timeout, MemoryLimit); } /// createJIT - Try to find the LLI executable @@ -370,7 +378,8 @@ int CBE::ExecuteProgram(const std::string &Bytecode, const std::string &OutputFile, const std::vector<std::string> &ArgsForGCC, const std::vector<std::string> &SharedLibs, - unsigned Timeout) { + unsigned Timeout, + unsigned MemoryLimit) { sys::Path OutputCFile; OutputCode(Bytecode, OutputCFile); @@ -379,7 +388,8 @@ int CBE::ExecuteProgram(const std::string &Bytecode, std::vector<std::string> GCCArgs(ArgsForGCC); GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile, - InputFile, OutputFile, GCCArgs, Timeout); + InputFile, OutputFile, GCCArgs, + Timeout, MemoryLimit); } /// createCBE - Try to find the 'llc' executable @@ -412,7 +422,8 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, const std::string &InputFile, const std::string &OutputFile, const std::vector<std::string> &ArgsForGCC, - unsigned Timeout ) { + unsigned Timeout, + unsigned MemoryLimit) { std::vector<const char*> GCCArgs; GCCArgs.push_back(GCCPath.c_str()); @@ -488,7 +499,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, FileRemover OutputBinaryRemover(OutputBinary); return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), - Timeout); + Timeout, MemoryLimit); } int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType, diff --git a/tools/bugpoint/ToolRunner.h b/tools/bugpoint/ToolRunner.h index e64d005..1ebccd8 100644 --- a/tools/bugpoint/ToolRunner.h +++ b/tools/bugpoint/ToolRunner.h @@ -64,7 +64,8 @@ public: const std::string &OutputFile, const std::vector<std::string> &GCCArgs = std::vector<std::string>(), - unsigned Timeout = 0); + unsigned Timeout = 0, + unsigned MemoryLimit = 0); /// MakeSharedObject - This compiles the specified file (which is either a .c /// file or a .s file) into a shared object. @@ -124,7 +125,8 @@ public: std::vector<std::string>(), const std::vector<std::string> &SharedLibs = std::vector<std::string>(), - unsigned Timeout = 0) = 0; + unsigned Timeout = 0, + unsigned MemoryLimit = 0) = 0; }; //===---------------------------------------------------------------------===// @@ -156,7 +158,8 @@ public: std::vector<std::string>(), const std::vector<std::string> &SharedLibs = std::vector<std::string>(), - unsigned Timeout = 0); + unsigned Timeout = 0, + unsigned MemoryLimit = 0); /// OutputCode - Compile the specified program from bytecode to code /// understood by the GCC driver (either C or asm). If the code generator @@ -196,7 +199,8 @@ public: std::vector<std::string>(), const std::vector<std::string> &SharedLibs = std::vector<std::string>(), - unsigned Timeout = 0); + unsigned Timeout = 0, + unsigned MemoryLimit = 0); virtual GCC::FileType OutputCode(const std::string &Bytecode, sys::Path &OutFile); diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp index 0cdbfd4..c345143 100644 --- a/tools/bugpoint/bugpoint.cpp +++ b/tools/bugpoint/bugpoint.cpp @@ -46,6 +46,10 @@ TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"), cl::desc("Number of seconds program is allowed to run before it " "is killed (default is 300s), 0 disables timeout")); +static cl::opt<unsigned> +MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"), + cl::desc("Maximum amount of memory to use. 0 disables check.")); + // The AnalysesList is automatically populated with registered Passes by the // PassNameParser. // @@ -68,7 +72,7 @@ int main(int argc, char **argv) { sys::PrintStackTraceOnErrorSignal(); sys::SetInterruptFunction(BugpointInterruptFunction); - BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue); + BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit); if (D.addSources(InputFilenames)) return 1; D.addPasses(PassList.begin(), PassList.end()); |