1 //===-- ToolRunner.cpp ----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the interfaces described in the ToolRunner.h file.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "toolrunner"
15 #include "ToolRunner.h"
16 #include "llvm/Config/config.h" // for HAVE_LINK_R
17 #include "llvm/System/Program.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/FileUtilities.h"
29 cl::desc("Remote execution (rsh) host"));
33 cl::desc("Remote execution (rsh) user id"));
36 ToolExecutionError::~ToolExecutionError() throw() { }
38 /// RunProgramWithTimeout - This function provides an alternate interface to the
39 /// sys::Program::ExecuteAndWait interface.
40 /// @see sys:Program::ExecuteAndWait
41 static int RunProgramWithTimeout(const sys::Path &ProgramPath,
43 const sys::Path &StdInFile,
44 const sys::Path &StdOutFile,
45 const sys::Path &StdErrFile,
46 unsigned NumSeconds = 0,
47 unsigned MemoryLimit = 0) {
48 const sys::Path* redirects[3];
49 redirects[0] = &StdInFile;
50 redirects[1] = &StdOutFile;
51 redirects[2] = &StdErrFile;
55 for (unsigned i = 0; Args[i]; ++i)
56 std::cerr << " " << Args[i];
61 sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects,
62 NumSeconds, MemoryLimit);
67 static void ProcessFailure(sys::Path ProgPath, const char** Args) {
68 std::ostringstream OS;
69 OS << "\nError running tool:\n ";
70 for (const char **Arg = Args; *Arg; ++Arg)
74 // Rerun the compiler, capturing any error messages to print them.
75 sys::Path ErrorFilename("error_messages");
77 if (ErrorFilename.makeUnique(true, &ErrMsg)) {
78 std::cerr << "Error making unique filename: " << ErrMsg << "\n";
81 RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename,
82 ErrorFilename); // FIXME: check return code ?
84 // Print out the error messages generated by GCC if possible...
85 std::ifstream ErrorFile(ErrorFilename.c_str());
87 std::copy(std::istreambuf_iterator<char>(ErrorFile),
88 std::istreambuf_iterator<char>(),
89 std::ostreambuf_iterator<char>(OS));
93 ErrorFilename.eraseFromDisk();
94 throw ToolExecutionError(OS.str());
97 //===---------------------------------------------------------------------===//
98 // LLI Implementation of AbstractIntepreter interface
101 class LLI : public AbstractInterpreter {
102 std::string LLIPath; // The path to the LLI executable
103 std::vector<std::string> ToolArgs; // Args to pass to LLI
105 LLI(const std::string &Path, const std::vector<std::string> *Args)
108 if (Args) { ToolArgs = *Args; }
111 virtual int ExecuteProgram(const std::string &Bitcode,
112 const std::vector<std::string> &Args,
113 const std::string &InputFile,
114 const std::string &OutputFile,
115 const std::vector<std::string> &GCCArgs,
116 const std::vector<std::string> &SharedLibs =
117 std::vector<std::string>(),
118 unsigned Timeout = 0,
119 unsigned MemoryLimit = 0);
123 int LLI::ExecuteProgram(const std::string &Bitcode,
124 const std::vector<std::string> &Args,
125 const std::string &InputFile,
126 const std::string &OutputFile,
127 const std::vector<std::string> &GCCArgs,
128 const std::vector<std::string> &SharedLibs,
130 unsigned MemoryLimit) {
131 if (!SharedLibs.empty())
132 throw ToolExecutionError("LLI currently does not support "
133 "loading shared libraries.");
135 if (!GCCArgs.empty())
136 throw ToolExecutionError("LLI currently does not support "
138 std::vector<const char*> LLIArgs;
139 LLIArgs.push_back(LLIPath.c_str());
140 LLIArgs.push_back("-force-interpreter=true");
142 // Add any extra LLI args.
143 for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
144 LLIArgs.push_back(ToolArgs[i].c_str());
146 LLIArgs.push_back(Bitcode.c_str());
147 // Add optional parameters to the running program from Argv
148 for (unsigned i=0, e = Args.size(); i != e; ++i)
149 LLIArgs.push_back(Args[i].c_str());
150 LLIArgs.push_back(0);
152 std::cout << "<lli>" << std::flush;
153 DEBUG(std::cerr << "\nAbout to run:\t";
154 for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i)
155 std::cerr << " " << LLIArgs[i];
158 return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0],
159 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
160 Timeout, MemoryLimit);
163 // LLI create method - Try to find the LLI executable
164 AbstractInterpreter *AbstractInterpreter::createLLI(const std::string &ProgPath,
165 std::string &Message,
166 const std::vector<std::string> *ToolArgs) {
167 std::string LLIPath = FindExecutable("lli", ProgPath).toString();
168 if (!LLIPath.empty()) {
169 Message = "Found lli: " + LLIPath + "\n";
170 return new LLI(LLIPath, ToolArgs);
173 Message = "Cannot find `lli' in executable directory or PATH!\n";
177 //===---------------------------------------------------------------------===//
178 // Custom execution command implementation of AbstractIntepreter interface
180 // Allows using a custom command for executing the bitcode, thus allows,
181 // for example, to invoke a cross compiler for code generation followed by
182 // a simulator that executes the generated binary.
184 class CustomExecutor : public AbstractInterpreter {
185 std::string ExecutionCommand;
186 std::vector<std::string> ExecutorArgs;
189 const std::string &ExecutionCmd, std::vector<std::string> ExecArgs) :
190 ExecutionCommand(ExecutionCmd), ExecutorArgs(ExecArgs) {}
192 virtual int ExecuteProgram(const std::string &Bitcode,
193 const std::vector<std::string> &Args,
194 const std::string &InputFile,
195 const std::string &OutputFile,
196 const std::vector<std::string> &GCCArgs,
197 const std::vector<std::string> &SharedLibs =
198 std::vector<std::string>(),
199 unsigned Timeout = 0,
200 unsigned MemoryLimit = 0);
204 int CustomExecutor::ExecuteProgram(const std::string &Bitcode,
205 const std::vector<std::string> &Args,
206 const std::string &InputFile,
207 const std::string &OutputFile,
208 const std::vector<std::string> &GCCArgs,
209 const std::vector<std::string> &SharedLibs,
211 unsigned MemoryLimit) {
213 std::vector<const char*> ProgramArgs;
214 ProgramArgs.push_back(ExecutionCommand.c_str());
216 for (std::size_t i = 0; i < ExecutorArgs.size(); ++i)
217 ProgramArgs.push_back(ExecutorArgs.at(i).c_str());
218 ProgramArgs.push_back(Bitcode.c_str());
219 ProgramArgs.push_back(0);
221 // Add optional parameters to the running program from Argv
222 for (unsigned i=0, e = Args.size(); i != e; ++i)
223 ProgramArgs.push_back(Args[i].c_str());
225 return RunProgramWithTimeout(
226 sys::Path(ExecutionCommand),
227 &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
228 sys::Path(OutputFile), Timeout, MemoryLimit);
231 // Custom execution environment create method, takes the execution command
233 AbstractInterpreter *AbstractInterpreter::createCustom(
234 const std::string &ProgramPath,
235 std::string &Message,
236 const std::string &ExecCommandLine) {
238 std::string Command = "";
239 std::vector<std::string> Args;
240 std::string delimiters = " ";
242 // Tokenize the ExecCommandLine to the command and the args to allow
243 // defining a full command line as the command instead of just the
244 // executed program. We cannot just pass the whole string after the command
245 // as a single argument because then program sees only a single
246 // command line argument (with spaces in it: "foo bar" instead
247 // of "foo" and "bar").
249 // code borrowed from:
250 // http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
251 std::string::size_type lastPos =
252 ExecCommandLine.find_first_not_of(delimiters, 0);
253 std::string::size_type pos =
254 ExecCommandLine.find_first_of(delimiters, lastPos);
256 while (std::string::npos != pos || std::string::npos != lastPos) {
257 std::string token = ExecCommandLine.substr(lastPos, pos - lastPos);
261 Args.push_back(token);
262 // Skip delimiters. Note the "not_of"
263 lastPos = ExecCommandLine.find_first_not_of(delimiters, pos);
264 // Find next "non-delimiter"
265 pos = ExecCommandLine.find_first_of(delimiters, lastPos);
268 std::string CmdPath = FindExecutable(Command, ProgramPath).toString();
269 if (CmdPath.empty()) {
271 std::string("Cannot find '") + Command +
272 "' in executable directory or PATH!\n";
276 Message = "Found command in: " + CmdPath + "\n";
278 return new CustomExecutor(CmdPath, Args);
281 //===----------------------------------------------------------------------===//
282 // LLC Implementation of AbstractIntepreter interface
284 GCC::FileType LLC::OutputCode(const std::string &Bitcode,
285 sys::Path &OutputAsmFile) {
286 sys::Path uniqueFile(Bitcode+".llc.s");
288 if (uniqueFile.makeUnique(true, &ErrMsg)) {
289 std::cerr << "Error making unique filename: " << ErrMsg << "\n";
292 OutputAsmFile = uniqueFile;
293 std::vector<const char *> LLCArgs;
294 LLCArgs.push_back (LLCPath.c_str());
296 // Add any extra LLC args.
297 for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
298 LLCArgs.push_back(ToolArgs[i].c_str());
300 LLCArgs.push_back ("-o");
301 LLCArgs.push_back (OutputAsmFile.c_str()); // Output to the Asm file
302 LLCArgs.push_back ("-f"); // Overwrite as necessary...
303 LLCArgs.push_back (Bitcode.c_str()); // This is the input bitcode
304 LLCArgs.push_back (0);
306 std::cout << "<llc>" << std::flush;
307 DEBUG(std::cerr << "\nAbout to run:\t";
308 for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
309 std::cerr << " " << LLCArgs[i];
312 if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
313 sys::Path(), sys::Path(), sys::Path()))
314 ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
319 void LLC::compileProgram(const std::string &Bitcode) {
320 sys::Path OutputAsmFile;
321 OutputCode(Bitcode, OutputAsmFile);
322 OutputAsmFile.eraseFromDisk();
325 int LLC::ExecuteProgram(const std::string &Bitcode,
326 const std::vector<std::string> &Args,
327 const std::string &InputFile,
328 const std::string &OutputFile,
329 const std::vector<std::string> &ArgsForGCC,
330 const std::vector<std::string> &SharedLibs,
332 unsigned MemoryLimit) {
334 sys::Path OutputAsmFile;
335 OutputCode(Bitcode, OutputAsmFile);
336 FileRemover OutFileRemover(OutputAsmFile);
338 std::vector<std::string> GCCArgs(ArgsForGCC);
339 GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
341 // Assuming LLC worked, compile the result with GCC and run it.
342 return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
343 InputFile, OutputFile, GCCArgs,
344 Timeout, MemoryLimit);
347 /// createLLC - Try to find the LLC executable
349 LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
350 std::string &Message,
351 const std::vector<std::string> *Args) {
352 std::string LLCPath = FindExecutable("llc", ProgramPath).toString();
353 if (LLCPath.empty()) {
354 Message = "Cannot find `llc' in executable directory or PATH!\n";
358 Message = "Found llc: " + LLCPath + "\n";
359 GCC *gcc = GCC::create(ProgramPath, Message);
361 std::cerr << Message << "\n";
364 return new LLC(LLCPath, gcc, Args);
367 //===---------------------------------------------------------------------===//
368 // JIT Implementation of AbstractIntepreter interface
371 class JIT : public AbstractInterpreter {
372 std::string LLIPath; // The path to the LLI executable
373 std::vector<std::string> ToolArgs; // Args to pass to LLI
375 JIT(const std::string &Path, const std::vector<std::string> *Args)
378 if (Args) { ToolArgs = *Args; }
381 virtual int ExecuteProgram(const std::string &Bitcode,
382 const std::vector<std::string> &Args,
383 const std::string &InputFile,
384 const std::string &OutputFile,
385 const std::vector<std::string> &GCCArgs =
386 std::vector<std::string>(),
387 const std::vector<std::string> &SharedLibs =
388 std::vector<std::string>(),
390 unsigned MemoryLimit =0);
394 int JIT::ExecuteProgram(const std::string &Bitcode,
395 const std::vector<std::string> &Args,
396 const std::string &InputFile,
397 const std::string &OutputFile,
398 const std::vector<std::string> &GCCArgs,
399 const std::vector<std::string> &SharedLibs,
401 unsigned MemoryLimit) {
402 if (!GCCArgs.empty())
403 throw ToolExecutionError("JIT does not support GCC Arguments.");
404 // Construct a vector of parameters, incorporating those from the command-line
405 std::vector<const char*> JITArgs;
406 JITArgs.push_back(LLIPath.c_str());
407 JITArgs.push_back("-force-interpreter=false");
409 // Add any extra LLI args.
410 for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
411 JITArgs.push_back(ToolArgs[i].c_str());
413 for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
414 JITArgs.push_back("-load");
415 JITArgs.push_back(SharedLibs[i].c_str());
417 JITArgs.push_back(Bitcode.c_str());
418 // Add optional parameters to the running program from Argv
419 for (unsigned i=0, e = Args.size(); i != e; ++i)
420 JITArgs.push_back(Args[i].c_str());
421 JITArgs.push_back(0);
423 std::cout << "<jit>" << std::flush;
424 DEBUG(std::cerr << "\nAbout to run:\t";
425 for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i)
426 std::cerr << " " << JITArgs[i];
429 DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n");
430 return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0],
431 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
432 Timeout, MemoryLimit);
435 /// createJIT - Try to find the LLI executable
437 AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath,
438 std::string &Message, const std::vector<std::string> *Args) {
439 std::string LLIPath = FindExecutable("lli", ProgPath).toString();
440 if (!LLIPath.empty()) {
441 Message = "Found lli: " + LLIPath + "\n";
442 return new JIT(LLIPath, Args);
445 Message = "Cannot find `lli' in executable directory or PATH!\n";
449 GCC::FileType CBE::OutputCode(const std::string &Bitcode,
450 sys::Path &OutputCFile) {
451 sys::Path uniqueFile(Bitcode+".cbe.c");
453 if (uniqueFile.makeUnique(true, &ErrMsg)) {
454 std::cerr << "Error making unique filename: " << ErrMsg << "\n";
457 OutputCFile = uniqueFile;
458 std::vector<const char *> LLCArgs;
459 LLCArgs.push_back (LLCPath.c_str());
461 // Add any extra LLC args.
462 for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
463 LLCArgs.push_back(ToolArgs[i].c_str());
465 LLCArgs.push_back ("-o");
466 LLCArgs.push_back (OutputCFile.c_str()); // Output to the C file
467 LLCArgs.push_back ("-march=c"); // Output C language
468 LLCArgs.push_back ("-f"); // Overwrite as necessary...
469 LLCArgs.push_back (Bitcode.c_str()); // This is the input bitcode
470 LLCArgs.push_back (0);
472 std::cout << "<cbe>" << std::flush;
473 DEBUG(std::cerr << "\nAbout to run:\t";
474 for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
475 std::cerr << " " << LLCArgs[i];
478 if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
480 ProcessFailure(LLCPath, &LLCArgs[0]);
484 void CBE::compileProgram(const std::string &Bitcode) {
485 sys::Path OutputCFile;
486 OutputCode(Bitcode, OutputCFile);
487 OutputCFile.eraseFromDisk();
490 int CBE::ExecuteProgram(const std::string &Bitcode,
491 const std::vector<std::string> &Args,
492 const std::string &InputFile,
493 const std::string &OutputFile,
494 const std::vector<std::string> &ArgsForGCC,
495 const std::vector<std::string> &SharedLibs,
497 unsigned MemoryLimit) {
498 sys::Path OutputCFile;
499 OutputCode(Bitcode, OutputCFile);
501 FileRemover CFileRemove(OutputCFile);
503 std::vector<std::string> GCCArgs(ArgsForGCC);
504 GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
505 return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
506 InputFile, OutputFile, GCCArgs,
507 Timeout, MemoryLimit);
510 /// createCBE - Try to find the 'llc' executable
512 CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
513 std::string &Message,
514 const std::vector<std::string> *Args) {
515 sys::Path LLCPath = FindExecutable("llc", ProgramPath);
516 if (LLCPath.isEmpty()) {
518 "Cannot find `llc' in executable directory or PATH!\n";
522 Message = "Found llc: " + LLCPath.toString() + "\n";
523 GCC *gcc = GCC::create(ProgramPath, Message);
525 std::cerr << Message << "\n";
528 return new CBE(LLCPath, gcc, Args);
531 //===---------------------------------------------------------------------===//
534 int GCC::ExecuteProgram(const std::string &ProgramFile,
535 const std::vector<std::string> &Args,
537 const std::string &InputFile,
538 const std::string &OutputFile,
539 const std::vector<std::string> &ArgsForGCC,
541 unsigned MemoryLimit) {
542 std::vector<const char*> GCCArgs;
544 GCCArgs.push_back(GCCPath.c_str());
546 // Specify -x explicitly in case the extension is wonky
547 GCCArgs.push_back("-x");
548 if (fileType == CFile) {
549 GCCArgs.push_back("c");
550 GCCArgs.push_back("-fno-strict-aliasing");
552 GCCArgs.push_back("assembler");
554 GCCArgs.push_back("-force_cpusubtype_ALL");
557 GCCArgs.push_back(ProgramFile.c_str()); // Specify the input filename...
558 GCCArgs.push_back("-x");
559 GCCArgs.push_back("none");
560 GCCArgs.push_back("-o");
561 sys::Path OutputBinary (ProgramFile+".gcc.exe");
563 if (OutputBinary.makeUnique(true, &ErrMsg)) {
564 std::cerr << "Error making unique filename: " << ErrMsg << "\n";
567 GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
569 // Add any arguments intended for GCC. We locate them here because this is
570 // most likely -L and -l options that need to come before other libraries but
571 // after the source. Other options won't be sensitive to placement on the
572 // command line, so this should be safe.
573 for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i)
574 GCCArgs.push_back(ArgsForGCC[i].c_str());
576 GCCArgs.push_back("-lm"); // Hard-code the math library...
577 GCCArgs.push_back("-O2"); // Optimize the program a bit...
578 #if defined (HAVE_LINK_R)
579 GCCArgs.push_back("-Wl,-R."); // Search this dir for .so files
582 GCCArgs.push_back("-mcpu=v9");
584 GCCArgs.push_back(0); // NULL terminator
586 std::cout << "<gcc>" << std::flush;
587 DEBUG(std::cerr << "\nAbout to run:\t";
588 for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i)
589 std::cerr << " " << GCCArgs[i];
592 if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
594 ProcessFailure(GCCPath, &GCCArgs[0]);
598 std::vector<const char*> ProgramArgs;
600 if (RSHPath.isEmpty())
601 ProgramArgs.push_back(OutputBinary.c_str());
603 ProgramArgs.push_back(RSHPath.c_str());
604 ProgramArgs.push_back(RSHHost.c_str());
605 ProgramArgs.push_back("-l");
606 ProgramArgs.push_back(RSHUser.c_str());
608 char* env_pwd = getenv("PWD");
609 std::string Exec = "cd ";
612 Exec += OutputBinary.c_str();
613 ProgramArgs.push_back(Exec.c_str());
616 // Add optional parameters to the running program from Argv
617 for (unsigned i=0, e = Args.size(); i != e; ++i)
618 ProgramArgs.push_back(Args[i].c_str());
619 ProgramArgs.push_back(0); // NULL terminator
621 // Now that we have a binary, run it!
622 std::cout << "<program>" << std::flush;
623 DEBUG(std::cerr << "\nAbout to run:\t";
624 for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i)
625 std::cerr << " " << ProgramArgs[i];
629 FileRemover OutputBinaryRemover(OutputBinary);
631 if (RSHPath.isEmpty())
632 return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
633 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
634 Timeout, MemoryLimit);
636 return RunProgramWithTimeout(sys::Path(RSHPath), &ProgramArgs[0],
637 sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
638 Timeout, MemoryLimit);
641 int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
642 std::string &OutputFile,
643 const std::vector<std::string> &ArgsForGCC) {
644 sys::Path uniqueFilename(InputFile+LTDL_SHLIB_EXT);
646 if (uniqueFilename.makeUnique(true, &ErrMsg)) {
647 std::cerr << "Error making unique filename: " << ErrMsg << "\n";
650 OutputFile = uniqueFilename.toString();
652 std::vector<const char*> GCCArgs;
654 GCCArgs.push_back(GCCPath.c_str());
657 // Compile the C/asm file into a shared object
658 GCCArgs.push_back("-x");
659 GCCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
660 GCCArgs.push_back("-fno-strict-aliasing");
661 GCCArgs.push_back(InputFile.c_str()); // Specify the input filename.
662 GCCArgs.push_back("-x");
663 GCCArgs.push_back("none");
664 #if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
665 GCCArgs.push_back("-G"); // Compile a shared library, `-G' for Sparc
666 #elif defined(__APPLE__)
667 // link all source files into a single module in data segment, rather than
668 // generating blocks. dynamic_lookup requires that you set
669 // MACOSX_DEPLOYMENT_TARGET=10.3 in your env. FIXME: it would be better for
670 // bugpoint to just pass that in the environment of GCC.
671 GCCArgs.push_back("-single_module");
672 GCCArgs.push_back("-dynamiclib"); // `-dynamiclib' for MacOS X/PowerPC
673 GCCArgs.push_back("-undefined");
674 GCCArgs.push_back("dynamic_lookup");
676 GCCArgs.push_back("-shared"); // `-shared' for Linux/X86, maybe others
679 #if defined(__ia64__) || defined(__alpha__) || defined(__amd64__)
680 GCCArgs.push_back("-fPIC"); // Requires shared objs to contain PIC
683 GCCArgs.push_back("-mcpu=v9");
685 GCCArgs.push_back("-o");
686 GCCArgs.push_back(OutputFile.c_str()); // Output to the right filename.
687 GCCArgs.push_back("-O2"); // Optimize the program a bit.
691 // Add any arguments intended for GCC. We locate them here because this is
692 // most likely -L and -l options that need to come before other libraries but
693 // after the source. Other options won't be sensitive to placement on the
694 // command line, so this should be safe.
695 for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i)
696 GCCArgs.push_back(ArgsForGCC[i].c_str());
697 GCCArgs.push_back(0); // NULL terminator
701 std::cout << "<gcc>" << std::flush;
702 DEBUG(std::cerr << "\nAbout to run:\t";
703 for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i)
704 std::cerr << " " << GCCArgs[i];
707 if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
709 ProcessFailure(GCCPath, &GCCArgs[0]);
715 /// create - Try to find the `gcc' executable
717 GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
718 sys::Path GCCPath = FindExecutable("gcc", ProgramPath);
719 if (GCCPath.isEmpty()) {
720 Message = "Cannot find `gcc' in executable directory or PATH!\n";
725 if (!RSHHost.empty())
726 RSHPath = FindExecutable("rsh", ProgramPath);
728 Message = "Found gcc: " + GCCPath.toString() + "\n";
729 return new GCC(GCCPath, RSHPath);