Skip to content

Commit 68a92c5

Browse files
committed
auto merge of #12581 : alexcrichton/rust/older-llvm, r=brson
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.
2 parents 780adff + bbdaf01 commit 68a92c5

File tree

4 files changed

+87
-26
lines changed

4 files changed

+87
-26
lines changed

.travis.yml

+9-18
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,23 @@
33
# it treats unknown languages as ruby-like I believe.
44
language: c
55

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

19-
# All of the llvm tools are suffixed with "-3.5" which we don't want, so symlink
10+
# All of the llvm tools are suffixed with "-3.3" which we don't want, so symlink
2011
# them all into a local directory and just use that
2112
#
2213
# FIXME: this shouldn't update the src/llvm sub-repo, that takes about a minute
2314
# it's gotta download so much stuff.
2415
before_script:
2516
- mkdir -p local-llvm/bin
26-
- ln -nsf /usr/bin/llvm-config-3.5 local-llvm/bin/llvm-config
27-
- ln -nsf /usr/bin/llvm-mc-3.5 local-llvm/bin/llvm-mc
28-
- ln -nsf /usr/bin/llvm-as-3.5 local-llvm/bin/llvm-as
29-
- ln -nsf /usr/bin/llvm-dis-3.5 local-llvm/bin/llvm-dis
30-
- ln -nsf /usr/bin/llc-3.5 local-llvm/bin/llc
31-
- ln -nsf /usr/include/llvm-3.5 local-llvm/include
17+
- ln -nsf /usr/bin/llvm-config-3.3 local-llvm/bin/llvm-config
18+
- ln -nsf /usr/bin/llvm-mc-3.3 local-llvm/bin/llvm-mc
19+
- ln -nsf /usr/bin/llvm-as-3.3 local-llvm/bin/llvm-as
20+
- ln -nsf /usr/bin/llvm-dis-3.3 local-llvm/bin/llvm-dis
21+
- ln -nsf /usr/bin/llc-3.3 local-llvm/bin/llc
22+
- ln -nsf /usr/include/llvm-3.3 local-llvm/include
3223
- ./configure --disable-optimize-tests --llvm-root=`pwd`/local-llvm --enable-fast-make --enable-clang
3324

3425
# Tidy everything up first, then build a few things, and then run a few tests.

src/rustllvm/PassWrapper.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
166166
PassManager *PM = unwrap<PassManager>(PMR);
167167

168168
std::string ErrorInfo;
169+
#if LLVM_VERSION_MINOR >= 4
169170
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
171+
#else
172+
raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
173+
#endif
170174
if (ErrorInfo != "") {
171175
LLVMRustError = ErrorInfo.c_str();
172176
return false;
@@ -184,9 +188,21 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
184188
const char* path) {
185189
PassManager *PM = unwrap<PassManager>(PMR);
186190
std::string ErrorInfo;
191+
192+
#if LLVM_VERSION_MINOR >= 4
187193
raw_fd_ostream OS(path, ErrorInfo, sys::fs::F_None);
194+
#else
195+
raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
196+
#endif
197+
188198
formatted_raw_ostream FOS(OS);
199+
200+
#if LLVM_VERSION_MINOR >= 5
189201
PM->add(createPrintModulePass(FOS));
202+
#else
203+
PM->add(createPrintModulePass(&FOS));
204+
#endif
205+
190206
PM->run(*unwrap(M));
191207
}
192208

src/rustllvm/RustWrapper.cpp

+56-7
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ extern "C" void LLVMRemoveReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) {
9191
AttributeSet::get(A->getContext(), AttributeSet::ReturnIndex, B));
9292
}
9393

94+
#if LLVM_VERSION_MINOR >= 5
9495
extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {
9596
Function *A = unwrap<Function>(Fn);
9697
A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
9798
}
99+
#else
100+
extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {}
101+
#endif
98102

99103
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
100104
LLVMValueRef source,
@@ -156,7 +160,11 @@ DIT unwrapDI(LLVMValueRef ref) {
156160
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
157161
}
158162

163+
#if LLVM_VERSION_MINOR >= 5
159164
extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION;
165+
#else
166+
extern "C" const uint32_t LLVMRustDebugMetadataVersion = 1;
167+
#endif
160168

161169
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
162170
const char *name,
@@ -278,8 +286,12 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStructType(
278286
unwrapDI<DIType>(DerivedFrom),
279287
unwrapDI<DIArray>(Elements),
280288
RunTimeLang,
281-
unwrapDI<DIType>(VTableHolder),
282-
UniqueId));
289+
unwrapDI<DIType>(VTableHolder)
290+
#if LLVM_VERSION_MINOR >= 5
291+
,UniqueId));
292+
#else
293+
));
294+
#endif
283295
}
284296

285297
extern "C" LLVMValueRef LLVMDIBuilderCreateMemberType(
@@ -440,8 +452,12 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateUnionType(
440452
AlignInBits,
441453
Flags,
442454
unwrapDI<DIArray>(Elements),
443-
RunTimeLang,
444-
UniqueId));
455+
RunTimeLang
456+
#if LLVM_VERSION_MINOR >= 5
457+
,UniqueId));
458+
#else
459+
));
460+
#endif
445461
}
446462

447463
extern "C" void LLVMSetUnnamedAddr(LLVMValueRef Value, LLVMBool Unnamed) {
@@ -541,6 +557,7 @@ extern "C" char *LLVMValueToString(LLVMValueRef Value) {
541557
return strdup(os.str().data());
542558
}
543559

560+
#if LLVM_VERSION_MINOR >= 5
544561
extern "C" bool
545562
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
546563
Module *Dst = unwrap(dst);
@@ -559,6 +576,26 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
559576
}
560577
return true;
561578
}
579+
#else
580+
extern "C" bool
581+
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
582+
Module *Dst = unwrap(dst);
583+
MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
584+
std::string Err;
585+
Module *Src = llvm::getLazyBitcodeModule(buf, Dst->getContext(), &Err);
586+
if (!Src) {
587+
LLVMRustError = Err.c_str();
588+
delete buf;
589+
return false;
590+
}
591+
592+
if (Linker::LinkModules(Dst, Src, Linker::DestroySource, &Err)) {
593+
LLVMRustError = Err.c_str();
594+
return false;
595+
}
596+
return true;
597+
}
598+
#endif
562599

563600
extern "C" void*
564601
LLVMRustOpenArchive(char *path) {
@@ -578,9 +615,14 @@ LLVMRustOpenArchive(char *path) {
578615

579616
extern "C" const char*
580617
LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {
581-
for (Archive::child_iterator child = ar->child_begin(),
582-
end = ar->child_end();
583-
child != end; ++child) {
618+
#if LLVM_VERSION_MINOR >= 5
619+
Archive::child_iterator child = ar->child_begin(),
620+
end = ar->child_end();
621+
#else
622+
Archive::child_iterator child = ar->begin_children(),
623+
end = ar->end_children();
624+
#endif
625+
for (; child != end; ++child) {
584626
StringRef sect_name;
585627
error_code err = child->getName(sect_name);
586628
if (err) continue;
@@ -598,8 +640,15 @@ LLVMRustDestroyArchive(Archive *ar) {
598640
delete ar;
599641
}
600642

643+
#if LLVM_VERSION_MINOR >= 5
601644
extern "C" void
602645
LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
603646
GlobalValue *V = unwrap<GlobalValue>(Value);
604647
V->setDLLStorageClass(GlobalValue::DLLExportStorageClass);
605648
}
649+
#else
650+
extern "C" void
651+
LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
652+
LLVMSetLinkage(Value, LLVMDLLExportLinkage);
653+
}
654+
#endif

src/rustllvm/rustllvm.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/PassManager.h"
1717
#include "llvm/IR/InlineAsm.h"
1818
#include "llvm/IR/LLVMContext.h"
19-
#include "llvm/IR/IRPrintingPasses.h"
2019
#include "llvm/Analysis/Passes.h"
2120
#include "llvm/Analysis/Lint.h"
2221
#include "llvm/ADT/ArrayRef.h"
@@ -52,6 +51,12 @@
5251
#include "llvm-c/ExecutionEngine.h"
5352
#include "llvm-c/Object.h"
5453

54+
#if LLVM_VERSION_MINOR >= 5
55+
#include "llvm/IR/IRPrintingPasses.h"
56+
#else
57+
#include "llvm/Assembly/PrintModulePass.h"
58+
#endif
59+
5560
// Used by RustMCJITMemoryManager::getPointerToNamedFunction()
5661
// to get around glibc issues. See the function for more information.
5762
#ifdef __linux__

0 commit comments

Comments
 (0)