Skip to content

Commit

Permalink
improve linker setup for Win64
Browse files Browse the repository at this point in the history
  • Loading branch information
Trass3r committed Jul 1, 2014
1 parent 956f1ff commit 9654a02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
37 changes: 24 additions & 13 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ static void CreateDirectoryOnDisk(llvm::StringRef fileName)
llvm::StringRef dir(llvm::sys::path::parent_path(fileName));
if (!dir.empty() && !llvm::sys::fs::exists(dir))
{
bool Existed;
#if LDC_LLVM_VER >= 305
std::error_code
std::error_code ec = llvm::sys::fs::create_directory(dir);
#else
llvm::error_code
bool existed;
llvm::error_code ec = llvm::sys::fs::create_directory(dir, existed);
#endif
ec = llvm::sys::fs::create_directory(dir, Existed);
if (ec)
{
error(Loc(), "failed to create path to file: %s\n%s", dir.data(), ec.message().c_str());
Expand Down Expand Up @@ -255,9 +254,7 @@ static int linkObjToBinaryWin(bool sharedLib)
// build arguments
std::vector<std::string> args;

// be verbose if requested
if (!global.params.verbose)
args.push_back("/NOLOGO");
args.push_back("/NOLOGO");

// specify that the image will contain a table of safe exception handlers (32bit only)
if (!global.params.is64bit)
Expand All @@ -271,14 +268,25 @@ static int linkObjToBinaryWin(bool sharedLib)

// because of a LLVM bug
// most of the bug is fixed in LLVM 3.4
#if LDC_LLVM_VER >= 304
#if LDC_LLVM_VER < 304
if (global.params.symdebug)
args.push_back("/LARGEADDRESSAWARE:NO");
else
#endif
args.push_back("/LARGEADDRESSAWARE:NO");
args.push_back("/LARGEADDRESSAWARE");

// output debug information
if (global.params.symdebug)
{
args.push_back("/DEBUG");
}

// remove dead code and fold identical COMDATs
if (!opts::disableLinkerStripDead)
{
args.push_back("/OPT:REF");
args.push_back("/OPT:ICF");
}

// specify creation of DLL
if (sharedLib)
Expand Down Expand Up @@ -313,14 +321,13 @@ static int linkObjToBinaryWin(bool sharedLib)
// additional linker switches
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
{
static const std::string LIBPATH("-L");
static const std::string LIB("-l");
std::string str(static_cast<const char *>(global.params.linkswitches->data[i]));
if (str.length() > 2)
{
if (std::equal(LIBPATH.begin(), LIBPATH.end(), str.begin()))
// rewrite common -L and -l switches
if (str[0] == '-' && str[1] == 'L')
str = "/LIBPATH:" + str.substr(2);
else if (std::equal(LIB.begin(), LIB.end(), str.begin()))
else if (str[0] == '-' && str[1] == 'l')
{
str = str.substr(2) + ".lib";
}
Expand Down Expand Up @@ -444,8 +451,12 @@ void deleteExecutable()
//assert(gExePath.isValid());
bool is_directory;
assert(!(!llvm::sys::fs::is_directory(gExePath, is_directory) && is_directory));
#if LDC_LLVM_VER < 305
bool Existed;
llvm::sys::fs::remove(gExePath, Existed);
#else
llvm::sys::fs::remove(gExePath);
#endif
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ macro(build_runtime d_flags c_flags ld_flags lib_suffix path_suffix outlist_targ
${DCRT_BC}
${LDC_IMPORTS}
${PHOBOS2_BC}
VERBATIM
)
else()
set(bclibs
Expand Down

0 comments on commit 9654a02

Please sign in to comment.