From 0c8c0e6a1821cdf3d1cf7ea0a378b273760aeefe Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Mon, 9 Jul 2018 20:09:44 +0200 Subject: [PATCH] Fix build with LLVM trunk. (#2767) --- driver/cache.cpp | 3 +++ driver/ldmd.cpp | 13 ++++++++++++- driver/linker-gcc.cpp | 9 ++++++++- driver/tool.cpp | 17 +++++++++++++---- utils/not.cpp | 13 ++++++++++++- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/driver/cache.cpp b/driver/cache.cpp index 9f2adf15d6..fa5077c949 100644 --- a/driver/cache.cpp +++ b/driver/cache.cpp @@ -472,6 +472,9 @@ void recoverObjectFile(llvm::StringRef cacheObjectHash, { int FD; if (llvm::sys::fs::openFileForWrite(cacheFile.c_str(), FD, +#if LDC_LLVM_VER >= 700 + llvm::sys::fs::CD_OpenExisting, +#endif llvm::sys::fs::F_Append)) { error(Loc(), "Failed to open the cached file for writing: %s", cacheFile.c_str()); diff --git a/driver/ldmd.cpp b/driver/ldmd.cpp index d01dd317db..450bdaab09 100644 --- a/driver/ldmd.cpp +++ b/driver/ldmd.cpp @@ -106,8 +106,19 @@ char *concat(const char *a, int b) { * Runs the given executable, returning its error code. */ int execute(const std::string &exePath, const char **args) { +#if LDC_LLVM_VER >= 700 + std::vector argv; + for (auto arg = args; arg != nullptr; ++arg) { + argv.push_back(*arg); + } + auto envVars = llvm::None; +#else + auto argv = args; + auto envVars = nullptr; +#endif + std::string errorMsg; - int rc = ls::ExecuteAndWait(exePath, args, nullptr, + int rc = ls::ExecuteAndWait(exePath, argv, envVars, #if LDC_LLVM_VER >= 600 {}, #else diff --git a/driver/linker-gcc.cpp b/driver/linker-gcc.cpp index 25c2cb5374..cd2db3599f 100644 --- a/driver/linker-gcc.cpp +++ b/driver/linker-gcc.cpp @@ -658,11 +658,18 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath, const auto fullArgs = getFullArgs("ld.lld", argsBuilder.args, global.params.verbose); + // CanExitEarly == true means that LLD can and will call `exit()` when errors occur. + const bool CanExitEarly = false; + bool success = false; if (global.params.targetTriple->isOSBinFormatELF()) { - success = lld::elf::link(fullArgs, /*CanExitEarly*/ false); + success = lld::elf::link(fullArgs, CanExitEarly); } else if (global.params.targetTriple->isOSBinFormatMachO()) { +#if LDC_LLVM_VER >= 700 + success = lld::mach_o::link(fullArgs, CanExitEarly); +#else success = lld::mach_o::link(fullArgs); +#endif } else { error(Loc(), "unknown target binary format for internal linking"); } diff --git a/driver/tool.cpp b/driver/tool.cpp index 6ae6710656..6655eb8c0c 100644 --- a/driver/tool.cpp +++ b/driver/tool.cpp @@ -173,14 +173,23 @@ int executeToolAndWait(const std::string &tool_, return -1; } - // Construct real argument list. - // First entry is the tool itself, last entry must be NULL. + // Construct real argument list; first entry is the tool itself. auto realargs = getFullArgs(tool, args, verbose); - realargs.push_back(nullptr); +#if LDC_LLVM_VER >= 700 + std::vector argv; + argv.reserve(realargs.size()); + for (auto &&arg : realargs) + argv.push_back(arg); + auto envVars = llvm::None; +#else + realargs.push_back(nullptr); // terminate with null + auto argv = &realargs[0]; + auto envVars = nullptr; +#endif // Execute tool. std::string errstr; - if (int status = llvm::sys::ExecuteAndWait(tool, &realargs[0], nullptr, + if (int status = llvm::sys::ExecuteAndWait(tool, argv, envVars, #if LDC_LLVM_VER >= 600 {}, #else diff --git a/utils/not.cpp b/utils/not.cpp index 1dedd99b79..2631f92cdd 100644 --- a/utils/not.cpp +++ b/utils/not.cpp @@ -39,8 +39,19 @@ int main(int argc, const char **argv) { return 1; } +#if LDC_LLVM_VER >= 700 + std::vector Argv; + Argv.reserve(argc); + for (int i = 0; i < argc; ++i) + Argv.push_back(argv[i]); + auto Env = llvm::None; +#else + auto Argv = argv; + auto Env = nullptr; +#endif + std::string ErrMsg; - int Result = sys::ExecuteAndWait(*Program, argv, nullptr, + int Result = sys::ExecuteAndWait(*Program, Argv, Env, #if LDC_LLVM_VER >= 600 {}, #else