Skip to content

Commit

Permalink
Add experimental -internal-linker switch to enable LLD opt-in
Browse files Browse the repository at this point in the history
And infer CMake LDC_WITH_LLD automatically based on availability of LLVM
3.9+ with LLD headers & libs.
  • Loading branch information
kinke committed May 28, 2017
1 parent 00d5f9b commit 1444581
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ set(LIB_SUFFIX "" CACHE STRING "Appended to the library installation directory.
option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays")
mark_as_advanced(GENERATE_OFFTI)

option(LDC_WITH_LLD "Integrate LLD, the LLVM cross-linker")

if(D_VERSION EQUAL 1)
message(FATAL_ERROR "D version 1 is no longer supported.
Please consider using D version 2 or checkout the 'd1' git branch for the last version supporting D version 1.")
Expand Down Expand Up @@ -448,16 +446,23 @@ if(GENERATE_OFFTI)
append("-DGENERATE_OFFTI" LDC_CXXFLAGS)
endif()

if(LDC_WITH_LLD)
append("-DLDC_WITH_LLD" LDC_CXXFLAGS)
#
# LLD integration (requires LLVM >= 3.9 with LLD headers & libs)
#
set(LDC_WITH_LLD OFF)
if(LDC_LLVM_VER GREATER 308)
if(EXISTS "${LLVM_INCLUDE_DIRS}/lld/Driver/Driver.h")
message(STATUS "Building LDC with LLD support")
append("-DLDC_WITH_LLD" LDC_CXXFLAGS)
set(LDC_WITH_LLD ON)
endif()
endif()

option(RISCV_LLVM_DEV, "full RISC-V support with riscv-llvm")
mark_as_advanced(RISCV_LLVM_DEV)

#
# Enable building with riscv-llvm, for full RISC-V support.
#
option(RISCV_LLVM_DEV, "full RISC-V support with riscv-llvm")
mark_as_advanced(RISCV_LLVM_DEV)
if(RISCV_LLVM_DEV)
append("-DRISCV_LLVM_DEV" LDC_CXXFLAGS)
endif()
Expand Down
2 changes: 1 addition & 1 deletion driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class LdArgsBuilder : public ArgsBuilder {

//////////////////////////////////////////////////////////////////////////////

int linkObjToBinaryGcc(llvm::StringRef outputPath,
int linkObjToBinaryGcc(llvm::StringRef outputPath, bool useInternalLinker,
llvm::cl::boolOrDefault fullyStaticFlag) {
// find gcc for linking
const std::string tool = getGcc();
Expand Down
3 changes: 1 addition & 2 deletions driver/linker-msvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void addMscrtLibs(std::vector<std::string> &args,

//////////////////////////////////////////////////////////////////////////////

int linkObjToBinaryMSVC(llvm::StringRef outputPath,
int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
llvm::cl::boolOrDefault fullyStaticFlag) {
if (!opts::ccSwitches.empty()) {
error(Loc(), "-Xcc is not supported for MSVC");
Expand Down Expand Up @@ -165,7 +165,6 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
logstr << "\n"; // FIXME where's flush ?

#if LDC_WITH_LLD
const bool useInternalLinker = true; // TODO
if (useInternalLinker) {
const auto fullArgs =
getFullArgs("lld-link.exe", args, global.params.verbose);
Expand Down
23 changes: 13 additions & 10 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,27 @@

//////////////////////////////////////////////////////////////////////////////

static llvm::cl::opt<bool>
static llvm::cl::opt<llvm::cl::boolOrDefault>
staticFlag("static", llvm::cl::ZeroOrMore,
llvm::cl::desc("Create a statically linked binary, including "
"all system dependencies"));

#if LDC_WITH_LLD
static llvm::cl::opt<bool>
useInternalLinker("internal-linker", llvm::cl::ZeroOrMore, llvm::cl::Hidden,
llvm::cl::desc("Use internal LLD for linking"));
#else
constexpr bool useInternalLinker = false;
#endif

//////////////////////////////////////////////////////////////////////////////

// linker-gcc.cpp
int linkObjToBinaryGcc(llvm::StringRef outputPath,
int linkObjToBinaryGcc(llvm::StringRef outputPath, bool useInternalLinker,
llvm::cl::boolOrDefault fullyStaticFlag);

// linker-msvc.cpp
int linkObjToBinaryMSVC(llvm::StringRef outputPath,
int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
llvm::cl::boolOrDefault fullyStaticFlag);

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -135,16 +143,11 @@ int linkObjToBinary() {

createDirectoryForFileOrFail(gExePath);

llvm::cl::boolOrDefault fullyStaticFlag = llvm::cl::BOU_UNSET;
if (staticFlag.getNumOccurrences() != 0) {
fullyStaticFlag = staticFlag ? llvm::cl::BOU_TRUE : llvm::cl::BOU_FALSE;
}

if (global.params.targetTriple->isWindowsMSVCEnvironment()) {
return linkObjToBinaryMSVC(gExePath, fullyStaticFlag);
return linkObjToBinaryMSVC(gExePath, useInternalLinker, staticFlag);
}

return linkObjToBinaryGcc(gExePath, fullyStaticFlag);
return linkObjToBinaryGcc(gExePath, useInternalLinker, staticFlag);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 1444581

Please sign in to comment.