mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 17:43:35 +03:00
Removed linkExecutable() (dead code).
This commit is contained in:
parent
1cb982f568
commit
4b23e794ca
2 changed files with 2 additions and 170 deletions
|
@ -58,167 +58,6 @@ void linkModules(llvm::Module* dst, const Module_vector& MV)
|
||||||
|
|
||||||
static llvm::sys::Path gExePath;
|
static llvm::sys::Path gExePath;
|
||||||
|
|
||||||
int linkExecutable(const char* argv0)
|
|
||||||
{
|
|
||||||
Logger::println("*** Linking executable ***");
|
|
||||||
|
|
||||||
// error string
|
|
||||||
std::string errstr;
|
|
||||||
|
|
||||||
// find the llvm-ld program
|
|
||||||
llvm::sys::Path ldpath = llvm::sys::Program::FindProgramByName("llvm-ld");
|
|
||||||
if (ldpath.isEmpty())
|
|
||||||
{
|
|
||||||
ldpath.set("llvm-ld");
|
|
||||||
}
|
|
||||||
|
|
||||||
// build arguments
|
|
||||||
std::vector<const char*> args;
|
|
||||||
|
|
||||||
// first the program name ??
|
|
||||||
args.push_back("llvm-ld");
|
|
||||||
|
|
||||||
// output filename
|
|
||||||
std::string exestr;
|
|
||||||
if (global.params.exefile)
|
|
||||||
{ // explicit
|
|
||||||
exestr = global.params.exefile;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // inferred
|
|
||||||
// try root module name
|
|
||||||
if (Module::rootModule)
|
|
||||||
exestr = Module::rootModule->toChars();
|
|
||||||
else
|
|
||||||
exestr = "a.out";
|
|
||||||
}
|
|
||||||
if (global.params.os == OSWindows && !(exestr.substr(exestr.length()-4) == ".exe"))
|
|
||||||
exestr.append(".exe");
|
|
||||||
|
|
||||||
std::string outopt = "-o=" + exestr;
|
|
||||||
args.push_back(outopt.c_str());
|
|
||||||
|
|
||||||
// set the global gExePath
|
|
||||||
gExePath.set(exestr);
|
|
||||||
assert(gExePath.isValid());
|
|
||||||
|
|
||||||
// create path to exe
|
|
||||||
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
|
|
||||||
if (!llvm::sys::fs::exists(exedir.str()))
|
|
||||||
{
|
|
||||||
exedir.createDirectoryOnDisk(true, &errstr);
|
|
||||||
if (!errstr.empty())
|
|
||||||
{
|
|
||||||
error("failed to create path to linking output: %s\n%s", exedir.c_str(), errstr.c_str());
|
|
||||||
fatal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// strip debug info
|
|
||||||
if (!global.params.symdebug)
|
|
||||||
args.push_back("-strip-debug");
|
|
||||||
|
|
||||||
// optimization level
|
|
||||||
if (!optimize())
|
|
||||||
args.push_back("-disable-opt");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch(optLevel())
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
args.push_back("-disable-opt");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
args.push_back("-globaldce");
|
|
||||||
args.push_back("-disable-opt");
|
|
||||||
args.push_back("-globaldce");
|
|
||||||
args.push_back("-mem2reg");
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
// use default optimization
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// inlining
|
|
||||||
if (!(global.params.useInline || doInline()))
|
|
||||||
{
|
|
||||||
args.push_back("-disable-inlining");
|
|
||||||
}
|
|
||||||
|
|
||||||
// additional linker switches
|
|
||||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
|
|
||||||
{
|
|
||||||
char *p = static_cast<char *>(global.params.linkswitches->data[i]);
|
|
||||||
args.push_back(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// native please
|
|
||||||
args.push_back("-native");
|
|
||||||
|
|
||||||
|
|
||||||
// user libs
|
|
||||||
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
|
|
||||||
{
|
|
||||||
char *p = static_cast<char *>(global.params.libfiles->data[i]);
|
|
||||||
args.push_back(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// default libs
|
|
||||||
switch(global.params.os) {
|
|
||||||
case OSLinux:
|
|
||||||
case OSMacOSX:
|
|
||||||
args.push_back("-ldl");
|
|
||||||
case OSFreeBSD:
|
|
||||||
args.push_back("-lpthread");
|
|
||||||
args.push_back("-lm");
|
|
||||||
break;
|
|
||||||
case OSHaiku:
|
|
||||||
args.push_back("-lroot");
|
|
||||||
break;
|
|
||||||
case OSWindows:
|
|
||||||
// FIXME: I'd assume kernel32 etc
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// object files
|
|
||||||
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
|
|
||||||
{
|
|
||||||
char *p = static_cast<char *>(global.params.objfiles->data[i]);
|
|
||||||
args.push_back(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// print link command?
|
|
||||||
if (!quiet || global.params.verbose)
|
|
||||||
{
|
|
||||||
// Print it
|
|
||||||
for (int i = 0; i < args.size(); i++)
|
|
||||||
printf("%s ", args[i]);
|
|
||||||
printf("\n");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// terminate args list
|
|
||||||
args.push_back(NULL);
|
|
||||||
|
|
||||||
// try to call linker!!!
|
|
||||||
if (int status = llvm::sys::Program::ExecuteAndWait(ldpath, &args[0], NULL, NULL, 0,0, &errstr))
|
|
||||||
{
|
|
||||||
error("linking failed:\nstatus: %d", status);
|
|
||||||
if (!errstr.empty())
|
|
||||||
error("message: %s", errstr.c_str());
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
int linkObjToBinary(bool sharedLib)
|
int linkObjToBinary(bool sharedLib)
|
||||||
{
|
{
|
||||||
Logger::println("*** Linking executable ***");
|
Logger::println("*** Linking executable ***");
|
||||||
|
|
|
@ -18,13 +18,6 @@ namespace llvm
|
||||||
*/
|
*/
|
||||||
void linkModules(llvm::Module* dst, const std::vector<llvm::Module*>& MV);
|
void linkModules(llvm::Module* dst, const std::vector<llvm::Module*>& MV);
|
||||||
|
|
||||||
/**
|
|
||||||
* Link an executable.
|
|
||||||
* @param argv0 the argv[0] value as passed to main
|
|
||||||
* @return 0 on success.
|
|
||||||
*/
|
|
||||||
int linkExecutable(const char* argv0);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link an executable only from object files.
|
* Link an executable only from object files.
|
||||||
* @param argv0 the argv[0] value as passed to main
|
* @param argv0 the argv[0] value as passed to main
|
||||||
|
@ -38,12 +31,12 @@ int linkObjToBinary(bool sharedLib);
|
||||||
void createStaticLibrary();
|
void createStaticLibrary();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the executable that was previously linked with linkExecutable.
|
* Delete the executable that was previously linked with linkObjToBinary.
|
||||||
*/
|
*/
|
||||||
void deleteExecutable();
|
void deleteExecutable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the executable that was previously linked with linkExecutable.
|
* Runs the executable that was previously linked with linkObjToBinary.
|
||||||
* @return the return status of the executable.
|
* @return the return status of the executable.
|
||||||
*/
|
*/
|
||||||
int runExecutable();
|
int runExecutable();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue