Skip to content

Commit

Permalink
Add the -Xlinker option to bugpoint which allows an option to be passed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Reid Spencer committed Jun 6, 2006
1 parent 4b02367 commit 51ab5c8
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 25 deletions.
11 changes: 9 additions & 2 deletions include/llvm/Support/ToolRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class GCC {
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(), unsigned Timeout = 0);
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
unsigned Timeout = 0);

/// MakeSharedObject - This compiles the specified file (which is either a .c
/// file or a .s file) into a shared object.
Expand Down Expand Up @@ -110,6 +111,8 @@ class AbstractInterpreter {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0) = 0;
Expand Down Expand Up @@ -140,6 +143,8 @@ class CBE : public AbstractInterpreter {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
Expand Down Expand Up @@ -177,6 +182,8 @@ class LLC : public AbstractInterpreter {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
Expand Down
40 changes: 31 additions & 9 deletions lib/Support/ToolRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
Expand All @@ -98,12 +99,16 @@ int LLI::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &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<const char*> LLIArgs;
LLIArgs.push_back(LLIPath.c_str());
LLIArgs.push_back("-force-interpreter=true");
Expand Down Expand Up @@ -184,16 +189,20 @@ int LLC::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {

sys::Path OutputAsmFile;
OutputAsm(Bytecode, OutputAsmFile);
FileRemover OutFileRemover(OutputAsmFile);

std::vector<std::string> 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
Expand Down Expand Up @@ -234,17 +243,23 @@ namespace {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(), unsigned Timeout =0);
std::vector<std::string>(),
unsigned Timeout =0 );
};
}

int JIT::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &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<const char*> JITArgs;
JITArgs.push_back(LLIPath.c_str());
Expand Down Expand Up @@ -329,15 +344,18 @@ int CBE::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
sys::Path OutputCFile;
OutputC(Bytecode, OutputCFile);

FileRemover CFileRemove(OutputCFile);

std::vector<std::string> 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
Expand Down Expand Up @@ -369,16 +387,12 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
const std::vector<std::string> &ArgsForGCC,
unsigned Timeout ) {
std::vector<const char*> 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) {
Expand All @@ -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)
Expand Down
21 changes: 18 additions & 3 deletions tools/bugpoint/ExecutionDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "llvm/Support/SystemUtils.h"
#include <fstream>
#include <iostream>

using namespace llvm;

namespace {
Expand Down Expand Up @@ -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<std::string>
AdditionalLinkerArgs("Xlinker",
cl::desc("Additional arguments to pass to the linker"));
}

namespace llvm {
Expand Down Expand Up @@ -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<std::string>(),
SharedObjs, TimeoutValue);

if (RetVal == -1) {
std::cerr << "<timeout>";
Expand Down
40 changes: 31 additions & 9 deletions tools/bugpoint/ToolRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
Expand All @@ -98,12 +99,16 @@ int LLI::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &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<const char*> LLIArgs;
LLIArgs.push_back(LLIPath.c_str());
LLIArgs.push_back("-force-interpreter=true");
Expand Down Expand Up @@ -184,16 +189,20 @@ int LLC::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {

sys::Path OutputAsmFile;
OutputAsm(Bytecode, OutputAsmFile);
FileRemover OutFileRemover(OutputAsmFile);

std::vector<std::string> 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
Expand Down Expand Up @@ -234,17 +243,23 @@ namespace {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(), unsigned Timeout =0);
std::vector<std::string>(),
unsigned Timeout =0 );
};
}

int JIT::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs,
const std::vector<std::string> &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<const char*> JITArgs;
JITArgs.push_back(LLIPath.c_str());
Expand Down Expand Up @@ -329,15 +344,18 @@ int CBE::ExecuteProgram(const std::string &Bytecode,
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &ArgsForGCC,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
sys::Path OutputCFile;
OutputC(Bytecode, OutputCFile);

FileRemover CFileRemove(OutputCFile);

std::vector<std::string> 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
Expand Down Expand Up @@ -369,16 +387,12 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
const std::vector<std::string> &ArgsForGCC,
unsigned Timeout ) {
std::vector<const char*> 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) {
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions tools/bugpoint/ToolRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class GCC {
FileType fileType,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(), unsigned Timeout = 0);
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
unsigned Timeout = 0);

/// MakeSharedObject - This compiles the specified file (which is either a .c
/// file or a .s file) into a shared object.
Expand Down Expand Up @@ -110,6 +111,8 @@ class AbstractInterpreter {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0) = 0;
Expand Down Expand Up @@ -140,6 +143,8 @@ class CBE : public AbstractInterpreter {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
Expand Down Expand Up @@ -177,6 +182,8 @@ class LLC : public AbstractInterpreter {
const std::vector<std::string> &Args,
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &GCCArgs =
std::vector<std::string>(),
const std::vector<std::string> &SharedLibs =
std::vector<std::string>(),
unsigned Timeout = 0);
Expand Down

0 comments on commit 51ab5c8

Please sign in to comment.