Skip to content

Commit

Permalink
auto merge of rust-lang#12581 : alexcrichton/rust/older-llvm, r=brson
Browse files Browse the repository at this point in the history
In doing so, revert travis to not using a 3.5 build because it seems to be changing enough that it's breaking our C++ glue frequently enough.
  • Loading branch information
bors committed Feb 27, 2014
2 parents 780adff + bbdaf01 commit 68a92c5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 26 deletions.
27 changes: 9 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,23 @@
# it treats unknown languages as ruby-like I believe.
language: c

# Before we start doing anything, install the latest stock LLVM. These are
# maintained by LLVM, and more information can be found at llvm.org/apt.
#
# Right now, the highest version is 3.5, and our SVN version is roughly aligned
# with the 3.5 API (hurray!)
# Before we start doing anything, install a stock LLVM
install:
- sudo sh -c "echo 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise main' >> /etc/apt/sources.list"
- sudo sh -c "echo 'deb-src http://llvm.org/apt/precise/ llvm-toolchain-precise main' >> /etc/apt/sources.list"
- sudo sh -c "echo 'deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu precise main' >> /etc/apt/sources.list"
- wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
- sudo apt-get update -qq
- sudo apt-get install -y --force-yes -qq llvm-3.5 llvm-3.5-dev clang-3.5 lldb-3.5
- sudo apt-get install llvm-3.3 llvm-3.3-dev clang-3.3 lldb-3.3

# All of the llvm tools are suffixed with "-3.5" which we don't want, so symlink
# All of the llvm tools are suffixed with "-3.3" which we don't want, so symlink
# them all into a local directory and just use that
#
# FIXME: this shouldn't update the src/llvm sub-repo, that takes about a minute
# it's gotta download so much stuff.
before_script:
- mkdir -p local-llvm/bin
- ln -nsf /usr/bin/llvm-config-3.5 local-llvm/bin/llvm-config
- ln -nsf /usr/bin/llvm-mc-3.5 local-llvm/bin/llvm-mc
- ln -nsf /usr/bin/llvm-as-3.5 local-llvm/bin/llvm-as
- ln -nsf /usr/bin/llvm-dis-3.5 local-llvm/bin/llvm-dis
- ln -nsf /usr/bin/llc-3.5 local-llvm/bin/llc
- ln -nsf /usr/include/llvm-3.5 local-llvm/include
- ln -nsf /usr/bin/llvm-config-3.3 local-llvm/bin/llvm-config
- ln -nsf /usr/bin/llvm-mc-3.3 local-llvm/bin/llvm-mc
- ln -nsf /usr/bin/llvm-as-3.3 local-llvm/bin/llvm-as
- ln -nsf /usr/bin/llvm-dis-3.3 local-llvm/bin/llvm-dis
- ln -nsf /usr/bin/llc-3.3 local-llvm/bin/llc
- ln -nsf /usr/include/llvm-3.3 local-llvm/include
- ./configure --disable-optimize-tests --llvm-root=`pwd`/local-llvm --enable-fast-make --enable-clang

# Tidy everything up first, then build a few things, and then run a few tests.
Expand Down
16 changes: 16 additions & 0 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

Expand Down
63 changes: 56 additions & 7 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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
7 changes: 6 additions & 1 deletion src/rustllvm/rustllvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,6 +51,12 @@
#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__
Expand Down

0 comments on commit 68a92c5

Please sign in to comment.