Skip to content

Commit

Permalink
Fix build with LLVM trunk. (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanEngelen authored and kinke committed Jul 9, 2018
1 parent 653270d commit 0c8c0e6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
3 changes: 3 additions & 0 deletions driver/cache.cpp
Expand Up @@ -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());
Expand Down
13 changes: 12 additions & 1 deletion driver/ldmd.cpp
Expand Up @@ -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<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;
int rc = ls::ExecuteAndWait(exePath, args, nullptr,
int rc = ls::ExecuteAndWait(exePath, argv, envVars,
#if LDC_LLVM_VER >= 600
{},
#else
Expand Down
9 changes: 8 additions & 1 deletion driver/linker-gcc.cpp
Expand Up @@ -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");
}
Expand Down
17 changes: 13 additions & 4 deletions driver/tool.cpp
Expand Up @@ -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<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.
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
Expand Down
13 changes: 12 additions & 1 deletion utils/not.cpp
Expand Up @@ -39,8 +39,19 @@ int main(int argc, const char **argv) {
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;
int Result = sys::ExecuteAndWait(*Program, argv, nullptr,
int Result = sys::ExecuteAndWait(*Program, Argv, Env,
#if LDC_LLVM_VER >= 600
{},
#else
Expand Down

0 comments on commit 0c8c0e6

Please sign in to comment.