Fix build with LLVM trunk. (#2767)

This commit is contained in:
Johan Engelen 2018-07-09 20:09:44 +02:00 committed by Martin Kinkelin
parent 653270df53
commit 0c8c0e6a18
5 changed files with 48 additions and 7 deletions

View file

@ -472,6 +472,9 @@ void recoverObjectFile(llvm::StringRef cacheObjectHash,
{ {
int FD; int FD;
if (llvm::sys::fs::openFileForWrite(cacheFile.c_str(), 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)) { llvm::sys::fs::F_Append)) {
error(Loc(), "Failed to open the cached file for writing: %s", error(Loc(), "Failed to open the cached file for writing: %s",
cacheFile.c_str()); cacheFile.c_str());

View file

@ -106,8 +106,19 @@ char *concat(const char *a, int b) {
* Runs the given executable, returning its error code. * Runs the given executable, returning its error code.
*/ */
int execute(const std::string &exePath, const char **args) { int execute(const std::string &exePath, const char **args) {
#if LDC_LLVM_VER >= 700
std::vector<llvm::StringRef> 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; std::string errorMsg;
int rc = ls::ExecuteAndWait(exePath, args, nullptr, int rc = ls::ExecuteAndWait(exePath, argv, envVars,
#if LDC_LLVM_VER >= 600 #if LDC_LLVM_VER >= 600
{}, {},
#else #else

View file

@ -658,11 +658,18 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
const auto fullArgs = const auto fullArgs =
getFullArgs("ld.lld", argsBuilder.args, global.params.verbose); 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; bool success = false;
if (global.params.targetTriple->isOSBinFormatELF()) { if (global.params.targetTriple->isOSBinFormatELF()) {
success = lld::elf::link(fullArgs, /*CanExitEarly*/ false); success = lld::elf::link(fullArgs, CanExitEarly);
} else if (global.params.targetTriple->isOSBinFormatMachO()) { } 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); success = lld::mach_o::link(fullArgs);
#endif
} else { } else {
error(Loc(), "unknown target binary format for internal linking"); error(Loc(), "unknown target binary format for internal linking");
} }

View file

@ -173,14 +173,23 @@ int executeToolAndWait(const std::string &tool_,
return -1; return -1;
} }
// Construct real argument list. // Construct real argument list; first entry is the tool itself.
// First entry is the tool itself, last entry must be NULL.
auto realargs = getFullArgs(tool, args, verbose); auto realargs = getFullArgs(tool, args, verbose);
realargs.push_back(nullptr); #if LDC_LLVM_VER >= 700
std::vector<llvm::StringRef> 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. // Execute tool.
std::string errstr; 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 #if LDC_LLVM_VER >= 600
{}, {},
#else #else

View file

@ -39,8 +39,19 @@ int main(int argc, const char **argv) {
return 1; return 1;
} }
#if LDC_LLVM_VER >= 700
std::vector<StringRef> 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; std::string ErrMsg;
int Result = sys::ExecuteAndWait(*Program, argv, nullptr, int Result = sys::ExecuteAndWait(*Program, Argv, Env,
#if LDC_LLVM_VER >= 600 #if LDC_LLVM_VER >= 600
{}, {},
#else #else