From 51ab5c8862466bbddcd5c4369779c472978ed309 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Tue, 6 Jun 2006 00:00:42 +0000 Subject: [PATCH] Add the -Xlinker option to bugpoint which allows an option to be passed through to gcc when its being used as a linker. This allows -L and -l (and any other) options to be added so that non-complete bytecode files can be processed with bugpoint. The -Xlinker option can be added as many times as needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28692 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ToolRunner.h | 11 ++++++-- lib/Support/ToolRunner.cpp | 40 +++++++++++++++++++++++------- tools/bugpoint/ExecutionDriver.cpp | 21 +++++++++++++--- tools/bugpoint/ToolRunner.cpp | 40 +++++++++++++++++++++++------- tools/bugpoint/ToolRunner.h | 11 ++++++-- 5 files changed, 98 insertions(+), 25 deletions(-) diff --git a/include/llvm/Support/ToolRunner.h b/include/llvm/Support/ToolRunner.h index addeda62926..d232cd2e97d 100644 --- a/include/llvm/Support/ToolRunner.h +++ b/include/llvm/Support/ToolRunner.h @@ -63,8 +63,9 @@ public: FileType fileType, const std::string &InputFile, const std::string &OutputFile, - const std::vector &SharedLibs = - std::vector(), unsigned Timeout = 0); + const std::vector &GCCArgs = + std::vector(), + unsigned Timeout = 0); /// MakeSharedObject - This compiles the specified file (which is either a .c /// file or a .s file) into a shared object. @@ -110,6 +111,8 @@ public: const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0) = 0; @@ -140,6 +143,8 @@ public: const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0); @@ -177,6 +182,8 @@ public: const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0); diff --git a/lib/Support/ToolRunner.cpp b/lib/Support/ToolRunner.cpp index a967e3e8377..b6d2a4dec41 100644 --- a/lib/Support/ToolRunner.cpp +++ b/lib/Support/ToolRunner.cpp @@ -88,6 +88,7 @@ namespace { const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs, const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0); @@ -98,12 +99,16 @@ int LLI::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs, const std::vector &SharedLibs, unsigned Timeout) { if (!SharedLibs.empty()) throw ToolExecutionError("LLI currently does not support " "loading shared libraries."); + if (!GCCArgs.empty()) + throw ToolExecutionError("LLI currently does not support " + "GCC Arguments."); std::vector LLIArgs; LLIArgs.push_back(LLIPath.c_str()); LLIArgs.push_back("-force-interpreter=true"); @@ -184,6 +189,7 @@ int LLC::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &ArgsForGCC, const std::vector &SharedLibs, unsigned Timeout) { @@ -191,9 +197,12 @@ int LLC::ExecuteProgram(const std::string &Bytecode, OutputAsm(Bytecode, OutputAsmFile); FileRemover OutFileRemover(OutputAsmFile); + std::vector GCCArgs(ArgsForGCC); + GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); + // Assuming LLC worked, compile the result with GCC and run it. return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile, - InputFile, OutputFile, SharedLibs, Timeout); + InputFile, OutputFile, GCCArgs, Timeout); } /// createLLC - Try to find the LLC executable @@ -234,8 +243,11 @@ namespace { const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = - std::vector(), unsigned Timeout =0); + std::vector(), + unsigned Timeout =0 ); }; } @@ -243,8 +255,11 @@ int JIT::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs, const std::vector &SharedLibs, unsigned Timeout) { + if (!GCCArgs.empty()) + throw ToolExecutionError("JIT does not support GCC Arguments."); // Construct a vector of parameters, incorporating those from the command-line std::vector JITArgs; JITArgs.push_back(LLIPath.c_str()); @@ -329,6 +344,7 @@ int CBE::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &ArgsForGCC, const std::vector &SharedLibs, unsigned Timeout) { sys::Path OutputCFile; @@ -336,8 +352,10 @@ int CBE::ExecuteProgram(const std::string &Bytecode, FileRemover CFileRemove(OutputCFile); + std::vector GCCArgs(ArgsForGCC); + GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile, - InputFile, OutputFile, SharedLibs, Timeout); + InputFile, OutputFile, GCCArgs, Timeout); } /// createCBE - Try to find the 'llc' executable @@ -369,16 +387,12 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, FileType fileType, const std::string &InputFile, const std::string &OutputFile, - const std::vector &SharedLibs, - unsigned Timeout) { + const std::vector &ArgsForGCC, + unsigned Timeout ) { std::vector GCCArgs; GCCArgs.push_back(GCCPath.c_str()); - // Specify the shared libraries to link in... - for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) - GCCArgs.push_back(SharedLibs[i].c_str()); - // Specify -x explicitly in case the extension is wonky GCCArgs.push_back("-x"); if (fileType == CFile) { @@ -395,6 +409,14 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, sys::Path OutputBinary (ProgramFile+".gcc.exe"); OutputBinary.makeUnique(); GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file... + + // Add any arguments intended for GCC. We locate them here because this is + // most likely -L and -l options that need to come before other libraries but + // after the source. Other options won't be sensitive to placement on the + // command line, so this should be safe. + for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i) + GCCArgs.push_back(ArgsForGCC[i].c_str()); + GCCArgs.push_back("-lm"); // Hard-code the math library... GCCArgs.push_back("-O2"); // Optimize the program a bit... #if defined (HAVE_LINK_R) diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp index 79a8ef8360f..481d1d1fed4 100644 --- a/tools/bugpoint/ExecutionDriver.cpp +++ b/tools/bugpoint/ExecutionDriver.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/SystemUtils.h" #include #include + using namespace llvm; namespace { @@ -66,6 +67,10 @@ namespace { 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")); + + cl::list + AdditionalLinkerArgs("Xlinker", + cl::desc("Additional arguments to pass to the linker")); } namespace llvm { @@ -218,9 +223,19 @@ std::string BugDriver::executeProgram(std::string OutputFile, if (!SharedObj.empty()) SharedObjs.push_back(SharedObj); - // Actually execute the program! - int RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile, - OutputFile, SharedObjs, TimeoutValue); + + // If this is an LLC or CBE run, then the GCC compiler might get run to + // compile the program. If so, we should pass the user's -Xlinker options + // as the GCCArgs. + int RetVal = 0; + if (InterpreterSel == RunLLC || InterpreterSel == RunCBE) + RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile, + OutputFile, AdditionalLinkerArgs, SharedObjs, + TimeoutValue); + else + RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile, + OutputFile, std::vector(), + SharedObjs, TimeoutValue); if (RetVal == -1) { std::cerr << ""; diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index a967e3e8377..b6d2a4dec41 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -88,6 +88,7 @@ namespace { const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs, const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0); @@ -98,12 +99,16 @@ int LLI::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs, const std::vector &SharedLibs, unsigned Timeout) { if (!SharedLibs.empty()) throw ToolExecutionError("LLI currently does not support " "loading shared libraries."); + if (!GCCArgs.empty()) + throw ToolExecutionError("LLI currently does not support " + "GCC Arguments."); std::vector LLIArgs; LLIArgs.push_back(LLIPath.c_str()); LLIArgs.push_back("-force-interpreter=true"); @@ -184,6 +189,7 @@ int LLC::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &ArgsForGCC, const std::vector &SharedLibs, unsigned Timeout) { @@ -191,9 +197,12 @@ int LLC::ExecuteProgram(const std::string &Bytecode, OutputAsm(Bytecode, OutputAsmFile); FileRemover OutFileRemover(OutputAsmFile); + std::vector GCCArgs(ArgsForGCC); + GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); + // Assuming LLC worked, compile the result with GCC and run it. return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile, - InputFile, OutputFile, SharedLibs, Timeout); + InputFile, OutputFile, GCCArgs, Timeout); } /// createLLC - Try to find the LLC executable @@ -234,8 +243,11 @@ namespace { const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = - std::vector(), unsigned Timeout =0); + std::vector(), + unsigned Timeout =0 ); }; } @@ -243,8 +255,11 @@ int JIT::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs, const std::vector &SharedLibs, unsigned Timeout) { + if (!GCCArgs.empty()) + throw ToolExecutionError("JIT does not support GCC Arguments."); // Construct a vector of parameters, incorporating those from the command-line std::vector JITArgs; JITArgs.push_back(LLIPath.c_str()); @@ -329,6 +344,7 @@ int CBE::ExecuteProgram(const std::string &Bytecode, const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &ArgsForGCC, const std::vector &SharedLibs, unsigned Timeout) { sys::Path OutputCFile; @@ -336,8 +352,10 @@ int CBE::ExecuteProgram(const std::string &Bytecode, FileRemover CFileRemove(OutputCFile); + std::vector GCCArgs(ArgsForGCC); + GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile, - InputFile, OutputFile, SharedLibs, Timeout); + InputFile, OutputFile, GCCArgs, Timeout); } /// createCBE - Try to find the 'llc' executable @@ -369,16 +387,12 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, FileType fileType, const std::string &InputFile, const std::string &OutputFile, - const std::vector &SharedLibs, - unsigned Timeout) { + const std::vector &ArgsForGCC, + unsigned Timeout ) { std::vector GCCArgs; GCCArgs.push_back(GCCPath.c_str()); - // Specify the shared libraries to link in... - for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) - GCCArgs.push_back(SharedLibs[i].c_str()); - // Specify -x explicitly in case the extension is wonky GCCArgs.push_back("-x"); if (fileType == CFile) { @@ -395,6 +409,14 @@ int GCC::ExecuteProgram(const std::string &ProgramFile, sys::Path OutputBinary (ProgramFile+".gcc.exe"); OutputBinary.makeUnique(); GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file... + + // Add any arguments intended for GCC. We locate them here because this is + // most likely -L and -l options that need to come before other libraries but + // after the source. Other options won't be sensitive to placement on the + // command line, so this should be safe. + for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i) + GCCArgs.push_back(ArgsForGCC[i].c_str()); + GCCArgs.push_back("-lm"); // Hard-code the math library... GCCArgs.push_back("-O2"); // Optimize the program a bit... #if defined (HAVE_LINK_R) diff --git a/tools/bugpoint/ToolRunner.h b/tools/bugpoint/ToolRunner.h index addeda62926..d232cd2e97d 100644 --- a/tools/bugpoint/ToolRunner.h +++ b/tools/bugpoint/ToolRunner.h @@ -63,8 +63,9 @@ public: FileType fileType, const std::string &InputFile, const std::string &OutputFile, - const std::vector &SharedLibs = - std::vector(), unsigned Timeout = 0); + const std::vector &GCCArgs = + std::vector(), + unsigned Timeout = 0); /// MakeSharedObject - This compiles the specified file (which is either a .c /// file or a .s file) into a shared object. @@ -110,6 +111,8 @@ public: const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0) = 0; @@ -140,6 +143,8 @@ public: const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0); @@ -177,6 +182,8 @@ public: const std::vector &Args, const std::string &InputFile, const std::string &OutputFile, + const std::vector &GCCArgs = + std::vector(), const std::vector &SharedLibs = std::vector(), unsigned Timeout = 0); -- 2.34.1