]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Get rustc compiling with LLVM 3.{3,4} again
authorAlex Crichton <alex@alexcrichton.com>
Wed, 26 Feb 2014 22:06:27 +0000 (14:06 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 26 Feb 2014 23:01:15 +0000 (15:01 -0800)
The travis builds have been breaking recently because LLVM 3.5 upstream is
changing. This looks like it's likely to continue, so it would be more useful
for us if we could lock ourselves to a system LLVM version that is not changing.

This commit has the support to bring our C++ glue to LLVM back in line with what
was possible back in LLVM 3.{3,4}. I don't think we're going to be able to
reasonably protect against regressions in the future, but this kind of code is a
good sign that we can continue to use the system LLVM for simple-ish things.
Codegen for ARM won't work and it won't have some of the perf improvements we
have, but using the system LLVM should work well enough for development.

src/rustllvm/PassWrapper.cpp
src/rustllvm/RustWrapper.cpp
src/rustllvm/rustllvm.h

index c1655b3a415001ae7ae856199ef7afda128da8ed..2be7c84ab03484f34c92f40cef5709af201379f3 100644 (file)
@@ -166,7 +166,11 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
   PassManager *PM = unwrap<PassManager>(PMR);
 
   std::string ErrorInfo;
+#if LLVM_VERSION_MINOR >= 4
   raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
+#else
+  raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
+#endif
   if (ErrorInfo != "") {
     LLVMRustError = ErrorInfo.c_str();
     return false;
@@ -184,9 +188,21 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
                     const char* path) {
   PassManager *PM = unwrap<PassManager>(PMR);
   std::string ErrorInfo;
+
+#if LLVM_VERSION_MINOR >= 4
   raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
+#else
+  raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
+#endif
+
   formatted_raw_ostream FOS(OS);
+
+#if LLVM_VERSION_MINOR >= 5
   PM->add(createPrintModulePass(FOS));
+#else
+  PM->add(createPrintModulePass(&FOS));
+#endif
+
   PM->run(*unwrap(M));
 }
 
index 75e0375b13ecb9429ecb9d634db1e56c3952ca45..d8fc5b15850e127cef3f7eff618876ed2e484200 100644 (file)
@@ -91,10 +91,14 @@ extern "C" void LLVMRemoveReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) {
                       AttributeSet::get(A->getContext(), AttributeSet::ReturnIndex,  B));
 }
 
+#if LLVM_VERSION_MINOR >= 5
 extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {
   Function *A = unwrap<Function>(Fn);
   A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
 }
+#else
+extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {}
+#endif
 
 extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
                                             LLVMValueRef source,
@@ -156,7 +160,11 @@ DIT unwrapDI(LLVMValueRef ref) {
     return DIT(ref ? unwrap<MDNode>(ref) : NULL);
 }
 
+#if LLVM_VERSION_MINOR >= 5
 extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION;
+#else
+extern "C" const uint32_t LLVMRustDebugMetadataVersion = 1;
+#endif
 
 extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
                                       const char *name,
@@ -278,8 +286,12 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStructType(
         unwrapDI<DIType>(DerivedFrom),
         unwrapDI<DIArray>(Elements),
         RunTimeLang,
-        unwrapDI<DIType>(VTableHolder),
-        UniqueId));
+        unwrapDI<DIType>(VTableHolder)
+#if LLVM_VERSION_MINOR >= 5
+        ,UniqueId));
+#else
+        ));
+#endif
 }
 
 extern "C" LLVMValueRef LLVMDIBuilderCreateMemberType(
@@ -440,8 +452,12 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateUnionType(
         AlignInBits,
         Flags,
         unwrapDI<DIArray>(Elements),
-        RunTimeLang,
-        UniqueId));
+        RunTimeLang
+#if LLVM_VERSION_MINOR >= 5
+        ,UniqueId));
+#else
+        ));
+#endif
 }
 
 extern "C" void LLVMSetUnnamedAddr(LLVMValueRef Value, LLVMBool Unnamed) {
@@ -541,6 +557,7 @@ extern "C" char *LLVMValueToString(LLVMValueRef Value) {
     return strdup(os.str().data());
 }
 
+#if LLVM_VERSION_MINOR >= 5
 extern "C" bool
 LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
     Module *Dst = unwrap(dst);
@@ -559,6 +576,26 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
     }
     return true;
 }
+#else
+extern "C" bool
+LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
+    Module *Dst = unwrap(dst);
+    MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
+    std::string Err;
+    Module *Src = llvm::getLazyBitcodeModule(buf, Dst->getContext(), &Err);
+    if (!Src) {
+        LLVMRustError = Err.c_str();
+        delete buf;
+        return false;
+    }
+
+    if (Linker::LinkModules(Dst, Src, Linker::DestroySource, &Err)) {
+        LLVMRustError = Err.c_str();
+        return false;
+    }
+    return true;
+}
+#endif
 
 extern "C" void*
 LLVMRustOpenArchive(char *path) {
@@ -578,9 +615,14 @@ LLVMRustOpenArchive(char *path) {
 
 extern "C" const char*
 LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {
-    for (Archive::child_iterator child = ar->child_begin(),
-                                   end = ar->child_end();
-         child != end; ++child) {
+#if LLVM_VERSION_MINOR >= 5
+    Archive::child_iterator child = ar->child_begin(),
+                              end = ar->child_end();
+#else
+    Archive::child_iterator child = ar->begin_children(),
+                              end = ar->end_children();
+#endif
+    for (; child != end; ++child) {
         StringRef sect_name;
         error_code err = child->getName(sect_name);
         if (err) continue;
@@ -598,8 +640,15 @@ LLVMRustDestroyArchive(Archive *ar) {
     delete ar;
 }
 
+#if LLVM_VERSION_MINOR >= 5
 extern "C" void
 LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
     GlobalValue *V = unwrap<GlobalValue>(Value);
     V->setDLLStorageClass(GlobalValue::DLLExportStorageClass);
 }
+#else
+extern "C" void
+LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
+    LLVMSetLinkage(Value, LLVMDLLExportLinkage);
+}
+#endif
index e45a910fc8cab8bc5167be75cb7679a3db38bd1f..f046587052a120f949d6d6e29dbfc06e5f811ccd 100644 (file)
@@ -16,7 +16,6 @@
 #include "llvm/PassManager.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/Lint.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm-c/ExecutionEngine.h"
 #include "llvm-c/Object.h"
 
+#if LLVM_VERSION_MINOR >= 5
+#include "llvm/IR/IRPrintingPasses.h"
+#else
+#include "llvm/Assembly/PrintModulePass.h"
+#endif
+
 // Used by RustMCJITMemoryManager::getPointerToNamedFunction()
 // to get around glibc issues. See the function for more information.
 #ifdef __linux__