mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 11:56:12 +03:00
Fix LLVM 5.0 build (#2173)
* Fix LLVM 5.0 compilation. * Fix adding linker option metadata to LLVM module. See https://reviews.llvm.org/D31349 * Version the SPIRV cache dir on travis.
This commit is contained in:
parent
76ebf6476c
commit
fdd66e5ea7
6 changed files with 81 additions and 16 deletions
|
@ -23,7 +23,7 @@ matrix:
|
||||||
env: LLVM_VERSION=3.5.2 OPTS="-DTEST_COVERAGE=ON"
|
env: LLVM_VERSION=3.5.2 OPTS="-DTEST_COVERAGE=ON"
|
||||||
- os: osx
|
- os: osx
|
||||||
d: ldc-beta
|
d: ldc-beta
|
||||||
env: LLVM_VERSION=5.0.0 OPTS="-DBUILD_SHARED_LIBS=OFF" LLVM_SPIRV_AVAILABLE=ON
|
env: LLVM_VERSION=5.0.0-1 OPTS="-DBUILD_SHARED_LIBS=OFF" LLVM_SPIRV_AVAILABLE=ON
|
||||||
- os: osx
|
- os: osx
|
||||||
d: ldc
|
d: ldc
|
||||||
env: LLVM_VERSION=4.0.0 OPTS="-DBUILD_SHARED_LIBS=ON"
|
env: LLVM_VERSION=4.0.0 OPTS="-DBUILD_SHARED_LIBS=ON"
|
||||||
|
@ -32,7 +32,7 @@ matrix:
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- llvm-spirv-5.0.0
|
- llvm-spirv-5.0.0-1
|
||||||
- llvm-4.0.1
|
- llvm-4.0.1
|
||||||
- llvm-4.0.0
|
- llvm-4.0.0
|
||||||
- llvm-3.9.1
|
- llvm-3.9.1
|
||||||
|
|
|
@ -73,7 +73,8 @@ createAndSetDiagnosticsOutputFile(IRState &irs, llvm::LLVMContext &ctx,
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Add the linker options metadata flag.
|
#if LDC_LLVM_VER < 500
|
||||||
|
/// Add the Linker Options module flag.
|
||||||
/// If the flag is already present, merge it with the new data.
|
/// If the flag is already present, merge it with the new data.
|
||||||
void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
|
void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
|
||||||
if (!M.getModuleFlag("Linker Options")) {
|
if (!M.getModuleFlag("Linker Options")) {
|
||||||
|
@ -119,6 +120,31 @@ void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
/// Add the "llvm.linker.options" metadata.
|
||||||
|
/// If the metadata is already present, merge it with the new data.
|
||||||
|
void emitLinkerOptions(IRState &irs, llvm::Module &M, llvm::LLVMContext &ctx) {
|
||||||
|
auto *linkerOptionsMD = M.getOrInsertNamedMetadata("llvm.linker.options");
|
||||||
|
|
||||||
|
// Add the new operands in front of the existing ones, such that linker
|
||||||
|
// options of .bc files passed on the cmdline are put _after_ the compiled .d
|
||||||
|
// file.
|
||||||
|
|
||||||
|
// Temporarily store metadata nodes that are already present
|
||||||
|
llvm::SmallVector<llvm::MDNode *, 5> oldMDNodes;
|
||||||
|
for (auto *MD : linkerOptionsMD->operands())
|
||||||
|
oldMDNodes.push_back(MD);
|
||||||
|
|
||||||
|
// Clear the list and add the new metadata nodes.
|
||||||
|
linkerOptionsMD->clearOperands();
|
||||||
|
for (auto *MD : irs.LinkerMetadataArgs)
|
||||||
|
linkerOptionsMD->addOperand(MD);
|
||||||
|
|
||||||
|
// Re-add metadata nodes that were already present
|
||||||
|
for (auto *MD : oldMDNodes)
|
||||||
|
linkerOptionsMD->addOperand(MD);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void emitLLVMUsedArray(IRState &irs) {
|
void emitLLVMUsedArray(IRState &irs) {
|
||||||
if (irs.usedArray.empty()) {
|
if (irs.usedArray.empty()) {
|
||||||
|
|
|
@ -118,33 +118,45 @@ static inline llvm::Optional<llvm::Reloc::Model> getRelocModel() {
|
||||||
static inline llvm::Reloc::Model getRelocModel() { return mRelocModel; }
|
static inline llvm::Reloc::Model getRelocModel() { return mRelocModel; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void printVersion() {
|
// This function exits the program.
|
||||||
printf("LDC - the LLVM D compiler (%s):\n", global.ldc_version);
|
void printVersion(llvm::raw_ostream &OS) {
|
||||||
printf(" based on DMD %s and LLVM %s\n", global.version,
|
OS << "LDC - the LLVM D compiler (" << global.ldc_version << "):\n";
|
||||||
global.llvm_version);
|
OS << " based on DMD " << global.version << " and LLVM " << global.llvm_version << "\n";
|
||||||
printf(" built with %s\n", ldc::built_with_Dcompiler_version);
|
OS << " built with " << ldc::built_with_Dcompiler_version << "\n";
|
||||||
#if defined(__has_feature)
|
#if defined(__has_feature)
|
||||||
#if __has_feature(address_sanitizer)
|
#if __has_feature(address_sanitizer)
|
||||||
printf(" compiled with address sanitizer enabled\n");
|
OS << " compiled with address sanitizer enabled\n";
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
printf(" Default target: %s\n", llvm::sys::getDefaultTargetTriple().c_str());
|
OS << " Default target: " << llvm::sys::getDefaultTargetTriple() << "\n";
|
||||||
std::string CPU = llvm::sys::getHostCPUName();
|
std::string CPU = llvm::sys::getHostCPUName();
|
||||||
if (CPU == "generic") {
|
if (CPU == "generic") {
|
||||||
CPU = "(unknown)";
|
CPU = "(unknown)";
|
||||||
}
|
}
|
||||||
printf(" Host CPU: %s\n", CPU.c_str());
|
OS << " Host CPU: " << CPU << "\n";
|
||||||
printf(" http://dlang.org - http://wiki.dlang.org/LDC\n");
|
OS << " http://dlang.org - http://wiki.dlang.org/LDC\n";
|
||||||
printf("\n");
|
OS << "\n";
|
||||||
|
|
||||||
// Without explicitly flushing here, only the target list is visible when
|
// Without explicitly flushing here, only the target list is visible when
|
||||||
// redirecting stdout to a file.
|
// redirecting stdout to a file.
|
||||||
fflush(stdout);
|
OS.flush();
|
||||||
|
|
||||||
|
llvm::TargetRegistry::printRegisteredTargetsForVersion(
|
||||||
|
#if LDC_LLVM_VER >= 500
|
||||||
|
OS
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
llvm::TargetRegistry::printRegisteredTargetsForVersion();
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function exits the program.
|
||||||
|
void printVersionStdout() {
|
||||||
|
printVersion(llvm::outs());
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Helper function to handle -d-debug=* and -d-version=*
|
// Helper function to handle -d-debug=* and -d-version=*
|
||||||
|
@ -351,7 +363,11 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
||||||
// finalize by expanding response files specified in config file
|
// finalize by expanding response files specified in config file
|
||||||
expandResponseFiles(allocator, allArguments);
|
expandResponseFiles(allocator, allArguments);
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 500
|
||||||
cl::SetVersionPrinter(&printVersion);
|
cl::SetVersionPrinter(&printVersion);
|
||||||
|
#else
|
||||||
|
cl::SetVersionPrinter(&printVersionStdout);
|
||||||
|
#endif
|
||||||
|
|
||||||
opts::hideLLVMOptions();
|
opts::hideLLVMOptions();
|
||||||
opts::createClashingOptions();
|
opts::createClashingOptions();
|
||||||
|
|
|
@ -200,7 +200,9 @@ struct IRState {
|
||||||
llvm::StringMap<llvm::GlobalVariable *> stringLiteral4ByteCache;
|
llvm::StringMap<llvm::GlobalVariable *> stringLiteral4ByteCache;
|
||||||
|
|
||||||
/// Vector of options passed to the linker as metadata in object file.
|
/// Vector of options passed to the linker as metadata in object file.
|
||||||
#if LDC_LLVM_VER >= 306
|
#if LDC_LLVM_VER >= 500
|
||||||
|
llvm::SmallVector<llvm::MDNode *, 5> LinkerMetadataArgs;
|
||||||
|
#elif LDC_LLVM_VER >= 306
|
||||||
llvm::SmallVector<llvm::Metadata *, 5> LinkerMetadataArgs;
|
llvm::SmallVector<llvm::Metadata *, 5> LinkerMetadataArgs;
|
||||||
#else
|
#else
|
||||||
llvm::SmallVector<llvm::Value *, 5> LinkerMetadataArgs;
|
llvm::SmallVector<llvm::Value *, 5> LinkerMetadataArgs;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Test passing of LLVM bitcode file with Linker Options set
|
// Test passing of LLVM bitcode file with Linker Options set
|
||||||
|
|
||||||
// REQUIRES: atleast_llvm306
|
// REQUIRES: atleast_llvm306
|
||||||
|
// LLVM >= 5.0 uses llvm.linker.options instead. See link_bitcode_libs_500.d.
|
||||||
|
// REQUIRES: atmost_llvm400
|
||||||
|
|
||||||
// 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
|
||||||
|
|
19
tests/linking/link_bitcode_libs_500.d
Normal file
19
tests/linking/link_bitcode_libs_500.d
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// Test passing of LLVM bitcode file with Linker Options set
|
||||||
|
|
||||||
|
// REQUIRES: atleast_llvm500
|
||||||
|
|
||||||
|
// Linker Options are currently only set on Windows platform, so we must (cross-)compile to Windows
|
||||||
|
// REQUIRES: target_X86
|
||||||
|
|
||||||
|
// RUN: %ldc -mtriple=x86_64-windows -c -output-bc %S/inputs/link_bitcode_libs_input.d -of=%t.bc \
|
||||||
|
// RUN: && %ldc -mtriple=x86_64-windows -c -singleobj -output-ll %t.bc %s -of=%t.ll \
|
||||||
|
// RUN: && FileCheck %s < %t.ll
|
||||||
|
|
||||||
|
pragma(lib, "library_one");
|
||||||
|
pragma(lib, "library_two");
|
||||||
|
|
||||||
|
// CHECK: !llvm.linker.options = !{![[ATTR_LIB1:[0-9]+]], ![[ATTR_LIB2:[0-9]+]], ![[ATTR_LIB3:[0-9]+]], ![[ATTR_LIB4:[0-9]+]]}
|
||||||
|
// CHECK: ![[ATTR_LIB1]]{{.*}}library_one
|
||||||
|
// CHECK: ![[ATTR_LIB2]]{{.*}}library_two
|
||||||
|
// CHECK: ![[ATTR_LIB3]]{{.*}}imported_one
|
||||||
|
// CHECK: ![[ATTR_LIB4]]{{.*}}imported_two
|
Loading…
Add table
Add a link
Reference in a new issue