Pass -Xlinker flags to gcc when it builds the shared object.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28939 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-06-27 20:35:36 +00:00
parent 4df24f2caf
commit 130e2a3611
3 changed files with 45 additions and 25 deletions

View File

@@ -288,7 +288,7 @@ std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) {
std::string SharedObjectFile; std::string SharedObjectFile;
if (gcc->MakeSharedObject(OutputCFile.toString(), GCC::CFile, if (gcc->MakeSharedObject(OutputCFile.toString(), GCC::CFile,
SharedObjectFile)) SharedObjectFile, AdditionalLinkerArgs))
exit(1); exit(1);
// Remove the intermediate C file // Remove the intermediate C file
@@ -308,7 +308,7 @@ bool BugDriver::diffProgram(const std::string &BytecodeFile,
bool ProgramExitedNonzero; bool ProgramExitedNonzero;
// Execute the program, generating an output file... // Execute the program, generating an output file...
sys::Path Output (executeProgram("", BytecodeFile, SharedObject, 0, sys::Path Output(executeProgram("", BytecodeFile, SharedObject, 0,
&ProgramExitedNonzero)); &ProgramExitedNonzero));
// If we're checking the program exit code, assume anything nonzero is bad. // If we're checking the program exit code, assume anything nonzero is bad.

View File

@@ -459,44 +459,63 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
} }
int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType, int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
std::string &OutputFile) { std::string &OutputFile,
const std::vector<std::string> &ArgsForGCC) {
sys::Path uniqueFilename(InputFile+LTDL_SHLIB_EXT); sys::Path uniqueFilename(InputFile+LTDL_SHLIB_EXT);
uniqueFilename.makeUnique(); uniqueFilename.makeUnique();
OutputFile = uniqueFilename.toString(); OutputFile = uniqueFilename.toString();
std::vector<const char*> GCCArgs;
GCCArgs.push_back(GCCPath.c_str());
// Compile the C/asm file into a shared object // Compile the C/asm file into a shared object
const char* GCCArgs[] = { GCCArgs.push_back("-x");
GCCPath.c_str(), GCCArgs.push_back(fileType == AsmFile ? "assembler" : "c");
"-x", (fileType == AsmFile) ? "assembler" : "c", GCCArgs.push_back("-fno-strict-aliasing");
"-fno-strict-aliasing", GCCArgs.push_back(InputFile.c_str()); // Specify the input filename.
InputFile.c_str(), // Specify the input filename...
#if defined(sparc) || defined(__sparc__) || defined(__sparcv9) #if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
"-G", // Compile a shared library, `-G' for Sparc GCCArgs.push_back("-G"); // Compile a shared library, `-G' for Sparc
#elif defined(__APPLE__) #elif defined(__APPLE__)
"-single_module", // link all source files into a single module // link all source files into a single module in data segment, rather than
"-dynamiclib", // `-dynamiclib' for MacOS X/PowerPC // generating blocks. dynamic_lookup requires that you set
"-undefined", // in data segment, rather than generating // MACOSX_DEPLOYMENT_TARGET=10.3 in your env. FIXME: it would be better for
"dynamic_lookup", // blocks. dynamic_lookup requires that you set // bugpoint to just pass that in the environment of GCC.
// MACOSX_DEPLOYMENT_TARGET=10.3 in your env. GCCArgs.push_back("-single_module");
GCCArgs.push_back("-dynamiclib"); // `-dynamiclib' for MacOS X/PowerPC
GCCArgs.push_back("-undefined");
GCCArgs.push_back("dynamic_lookup");
#else #else
"-shared", // `-shared' for Linux/X86, maybe others GCCArgs.push_back("-shared"); // `-shared' for Linux/X86, maybe others
#endif #endif
#if defined(__ia64__) || defined(__alpha__) #if defined(__ia64__) || defined(__alpha__)
"-fPIC", // IA64 requires shared objs to contain PIC GCCArgs.push_back("-fPIC"); // Requires shared objs to contain PIC
#endif #endif
#ifdef __sparc__ #ifdef __sparc__
"-mcpu=v9", GCCArgs.push_back("-mcpu=v9");
#endif #endif
"-o", OutputFile.c_str(), // Output to the right filename... GCCArgs.push_back("-o");
"-O2", // Optimize the program a bit... GCCArgs.push_back(OutputFile.c_str()); // Output to the right filename.
0 GCCArgs.push_back("-O2"); // Optimize the program a bit.
};
// 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(0); // NULL terminator
std::cout << "<gcc>" << std::flush; std::cout << "<gcc>" << std::flush;
if (RunProgramWithTimeout(GCCPath, GCCArgs, sys::Path(), sys::Path(), if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
sys::Path())) { sys::Path())) {
ProcessFailure(GCCPath, GCCArgs); ProcessFailure(GCCPath, &GCCArgs[0]);
return 1; return 1;
} }
return 0; return 0;

View File

@@ -48,7 +48,7 @@ class GCC {
public: public:
enum FileType { AsmFile, CFile }; enum FileType { AsmFile, CFile };
static GCC* create(const std::string &ProgramPath, std::string &Message); static GCC *create(const std::string &ProgramPath, std::string &Message);
/// ExecuteProgram - Execute the program specified by "ProgramFile" (which is /// ExecuteProgram - Execute the program specified by "ProgramFile" (which is
/// either a .s file, or a .c file, specified by FileType), with the specified /// either a .s file, or a .c file, specified by FileType), with the specified
@@ -70,7 +70,8 @@ public:
/// file or a .s file) into a shared object. /// file or a .s file) into a shared object.
/// ///
int MakeSharedObject(const std::string &InputFile, FileType fileType, int MakeSharedObject(const std::string &InputFile, FileType fileType,
std::string &OutputFile); std::string &OutputFile,
const std::vector<std::string> &ArgsForGCC);
}; };