Bitcode cmd arguments: fix compilation for LLVM < 3.8, and disable for LLVM 3.5.

This commit is contained in:
Johan Engelen 2016-06-10 12:42:05 +02:00
parent 683d9ecccd
commit 404d483c2a
4 changed files with 33 additions and 11 deletions

View file

@ -38,6 +38,11 @@ void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
// Merge the Linker Options with the pre-existing one // Merge the Linker Options with the pre-existing one
// (this can happen when passing a .bc file on the commandline) // (this can happen when passing a .bc file on the commandline)
#if LDC_LLVM_VER < 306
// Passing a bitcode file on the commandline is not supported for LLVM 3.5.
llvm_unreachable(
"Merging of Linker Options is not implemented for LLVM 3.5");
#else
auto *moduleFlags = M.getModuleFlagsMetadata(); auto *moduleFlags = M.getModuleFlagsMetadata();
for (unsigned i = 0, e = moduleFlags->getNumOperands(); i < e; ++i) { for (unsigned i = 0, e = moduleFlags->getNumOperands(); i < e; ++i) {
auto *flag = moduleFlags->getOperand(i); auto *flag = moduleFlags->getOperand(i);
@ -66,6 +71,7 @@ void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
break; break;
} }
#endif
} }
} }
} }

View file

@ -108,29 +108,41 @@ static std::string getOutputName(bool const sharedLib) {
namespace { namespace {
#if LDC_LLVM_VER >= 306
/// Insert an LLVM bitcode file into the module /// Insert an LLVM bitcode file into the module
void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M, void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
llvm::LLVMContext &Context) { llvm::LLVMContext &Context) {
Logger::println("*** Linking-in bitcode file %s ***", bcFile); Logger::println("*** Linking-in bitcode file %s ***", bcFile);
llvm::SMDiagnostic Err; llvm::SMDiagnostic Err;
std::unique_ptr<llvm::Module> loadedModule = std::unique_ptr<llvm::Module> loadedModule(
getLazyIRFileModule(bcFile, Err, Context); getLazyIRFileModule(bcFile, Err, Context));
if (!loadedModule) { if (!loadedModule) {
error(Loc(), "Error when loading LLVM bitcode file: %s", bcFile); error(Loc(), "Error when loading LLVM bitcode file: %s", bcFile);
return; return;
} }
#if LDC_LLVM_VER >= 308
llvm::Linker(M).linkInModule(std::move(loadedModule)); llvm::Linker(M).linkInModule(std::move(loadedModule));
#else
llvm::Linker(&M).linkInModule(loadedModule.release());
#endif
} }
#endif
} }
/// Insert LLVM bitcode files into the module /// Insert LLVM bitcode files into the module
void insertBitcodeFiles(llvm::Module &M, llvm::LLVMContext &Ctx, void insertBitcodeFiles(llvm::Module &M, llvm::LLVMContext &Ctx,
Array<const char *> &bitcodeFiles) { Array<const char *> &bitcodeFiles) {
#if LDC_LLVM_VER >= 306
for (const char *fname : bitcodeFiles) { for (const char *fname : bitcodeFiles) {
insertBitcodeIntoModule(fname, M, Ctx); insertBitcodeIntoModule(fname, M, Ctx);
} }
#else
if (!bitcodeFiles.empty()) {
error(Loc(),
"Passing LLVM bitcode files to LDC is not supported for LLVM < 3.6");
}
#endif
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -298,8 +310,7 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) {
default: default:
if (global.params.is64bit) { if (global.params.is64bit) {
args.push_back("-m64"); args.push_back("-m64");
} } else {
else {
args.push_back("-m32"); args.push_back("-m32");
} }
} }
@ -431,7 +442,8 @@ int executeMsvcToolAndWait(const std::string &tool,
auto comspecEnv = getenv("ComSpec"); auto comspecEnv = getenv("ComSpec");
if (!comspecEnv) { if (!comspecEnv) {
warning(Loc(), "'ComSpec' environment variable is not set, assuming 'cmd.exe'."); warning(Loc(),
"'ComSpec' environment variable is not set, assuming 'cmd.exe'.");
comspecEnv = "cmd.exe"; comspecEnv = "cmd.exe";
} }
std::string cmdExecutable = comspecEnv; std::string cmdExecutable = comspecEnv;

View file

@ -1,5 +1,7 @@
// Test linking with an LLVM bitcode file // Test linking with an LLVM bitcode file
// REQUIRES: atleast_llvm306
// RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input.d -of=%t.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input.d -of=%t.bc
// RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_import.d -of=%t2.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_import.d -of=%t2.bc
// RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input3.d -of=%t3.bc // RUN: %ldc -c -output-bc -I%S %S/inputs/link_bitcode_input3.d -of=%t3.bc

View file

@ -1,5 +1,7 @@
// Test passing of LLVM bitcode file with Linker Options set // Test passing of LLVM bitcode file with Linker Options set
// REQUIRES: atleast_llvm306
// Linker Options are currently only set on Windows platform, so we must (cross-)compile to Windows // Linker Options are currently only set on Windows platform, so we must (cross-)compile to Windows
// REQUIRES: target_X86 // REQUIRES: target_X86