diff --git a/deps/Makefile b/deps/Makefile index e1f6831334495..655e7f86514f0 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -720,6 +720,14 @@ $(eval $(call LLVM_PATCH,llvm-3.7.1_2)) $(eval $(call LLVM_PATCH,llvm-3.7.1_3)) $(eval $(call LLVM_PATCH,llvm-D14260)) $(LLVM_SRC_DIR)/llvm-3.7.1_2.patch-applied: $(LLVM_SRC_DIR)/llvm-3.7.1.patch-applied +else ifeq ($(LLVM_VER),3.8.0) +$(eval $(call LLVM_PATCH,llvm-3.7.1_3)) +$(eval $(call LLVM_PATCH,llvm-D14260)) +$(eval $(call LLVM_PATCH,llvm-3.8.0_winshlib)) +# Cygwin and openSUSE still use win32-threads mingw, https://llvm.org/bugs/show_bug.cgi?id=26365 +$(eval $(call LLVM_PATCH,llvm-3.8.0_threads)) +# fix replutil test on unix +$(eval $(call LLVM_PATCH,llvm-D17165-D18583)) endif # LLVM_VER ifeq ($(LLVM_VER),3.7.1) diff --git a/deps/checksums/llvm-3.8.0.src.tar.xz/md5 b/deps/checksums/llvm-3.8.0.src.tar.xz/md5 new file mode 100644 index 0000000000000..d0d99639e9c9d --- /dev/null +++ b/deps/checksums/llvm-3.8.0.src.tar.xz/md5 @@ -0,0 +1 @@ +07a7a74f3c6bd65de4702bf941b511a0 diff --git a/deps/checksums/llvm-3.8.0.src.tar.xz/sha512 b/deps/checksums/llvm-3.8.0.src.tar.xz/sha512 new file mode 100644 index 0000000000000..afe5665688e85 --- /dev/null +++ b/deps/checksums/llvm-3.8.0.src.tar.xz/sha512 @@ -0,0 +1 @@ +2c76e79d803768ed20af6ca1801cf2518071bf9835c54580ea3eb6219a66cdcf8b4c575f192c15082cc18d2468b7611dacb57950b605813a2317125c2d33c138 diff --git a/deps/llvm-3.8.0_threads.patch b/deps/llvm-3.8.0_threads.patch new file mode 100644 index 0000000000000..9e52e2291045e --- /dev/null +++ b/deps/llvm-3.8.0_threads.patch @@ -0,0 +1,184 @@ +From 69ef168544e4f15b793dd35d272008fde9a6e835 Mon Sep 17 00:00:00 2001 +From: Alex Crichton +Date: Thu, 28 Jan 2016 20:44:50 -0800 +Subject: [PATCH] Don't compile usage of std::thread + +As of the time of this writing it's not actually used anywhere meaningfullly +throughout the LLVM repo that we need, and it unfortunately uses `std::thread` +which isn't available in mingw-w64 toolchains with the win32 threading model +(the one that we use). + +Two major changes were made to achieve this: + +1. The `ThreadPool.cpp` file was just entirely commented out. This isn't used + anywhere in the LLVM repo nor in Rust itself. +2. The `ParallelCG.cpp` file was mostly deleted. Unfortunately it's used a few + places in LLVM and is needed to link correctly, but we in Rust don't use it + at all. For now it's just a stub implementation that hopefully compiles + everywhere, but perhaps we can find a less invasive (aka doesn't have rebase + conflicts in the future) change to apply soon. + +For reference, the upstream LLVM bug has been reported [1] + +[1]: https://llvm.org/bugs/show_bug.cgi?id=26365 +--- + include/llvm/Support/ThreadPool.h | 4 +++ + include/llvm/Support/thread.h | 4 +++ + lib/CodeGen/ParallelCG.cpp | 63 +-------------------------------------- + lib/Support/ThreadPool.cpp | 4 +++ + 4 files changed, 13 insertions(+), 62 deletions(-) + +diff --git a/include/llvm/Support/ThreadPool.h b/include/llvm/Support/ThreadPool.h +index 745334d..4564615 100644 +--- a/include/llvm/Support/ThreadPool.h ++++ b/include/llvm/Support/ThreadPool.h +@@ -11,6 +11,8 @@ + // + //===----------------------------------------------------------------------===// + ++#if 0 ++ + #ifndef LLVM_SUPPORT_THREAD_POOL_H + #define LLVM_SUPPORT_THREAD_POOL_H + +@@ -134,3 +136,5 @@ class ThreadPool { + } + + #endif // LLVM_SUPPORT_THREAD_POOL_H ++ ++#endif +diff --git a/include/llvm/Support/thread.h b/include/llvm/Support/thread.h +index 2d13041..80340e6 100644 +--- a/include/llvm/Support/thread.h ++++ b/include/llvm/Support/thread.h +@@ -14,6 +14,8 @@ + // + //===----------------------------------------------------------------------===// + ++#if 0 ++ + #ifndef LLVM_SUPPORT_THREAD_H + #define LLVM_SUPPORT_THREAD_H + +@@ -64,3 +66,5 @@ struct thread { + #endif // LLVM_ENABLE_THREADS + + #endif ++ ++#endif +diff --git a/lib/CodeGen/ParallelCG.cpp b/lib/CodeGen/ParallelCG.cpp +index e73ba02..7362cda 100644 +--- a/lib/CodeGen/ParallelCG.cpp ++++ b/lib/CodeGen/ParallelCG.cpp +@@ -25,72 +25,11 @@ + + using namespace llvm; + +-static void codegen(Module *M, llvm::raw_pwrite_stream &OS, +- const Target *TheTarget, StringRef CPU, StringRef Features, +- const TargetOptions &Options, Reloc::Model RM, +- CodeModel::Model CM, CodeGenOpt::Level OL, +- TargetMachine::CodeGenFileType FileType) { +- std::unique_ptr TM(TheTarget->createTargetMachine( +- M->getTargetTriple(), CPU, Features, Options, RM, CM, OL)); +- +- legacy::PassManager CodeGenPasses; +- if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType)) +- report_fatal_error("Failed to setup codegen"); +- CodeGenPasses.run(*M); +-} +- + std::unique_ptr + llvm::splitCodeGen(std::unique_ptr M, + ArrayRef OSs, StringRef CPU, + StringRef Features, const TargetOptions &Options, + Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL, + TargetMachine::CodeGenFileType FileType) { +- StringRef TripleStr = M->getTargetTriple(); +- std::string ErrMsg; +- const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg); +- if (!TheTarget) +- report_fatal_error(Twine("Target not found: ") + ErrMsg); +- +- if (OSs.size() == 1) { +- codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM, +- OL, FileType); +- return M; +- } +- +- std::vector Threads; +- SplitModule(std::move(M), OSs.size(), [&](std::unique_ptr MPart) { +- // We want to clone the module in a new context to multi-thread the codegen. +- // We do it by serializing partition modules to bitcode (while still on the +- // main thread, in order to avoid data races) and spinning up new threads +- // which deserialize the partitions into separate contexts. +- // FIXME: Provide a more direct way to do this in LLVM. +- SmallVector BC; +- raw_svector_ostream BCOS(BC); +- WriteBitcodeToFile(MPart.get(), BCOS); +- +- llvm::raw_pwrite_stream *ThreadOS = OSs[Threads.size()]; +- Threads.emplace_back( +- [TheTarget, CPU, Features, Options, RM, CM, OL, FileType, +- ThreadOS](const SmallVector &BC) { +- LLVMContext Ctx; +- ErrorOr> MOrErr = +- parseBitcodeFile(MemoryBufferRef(StringRef(BC.data(), BC.size()), +- ""), +- Ctx); +- if (!MOrErr) +- report_fatal_error("Failed to read bitcode"); +- std::unique_ptr MPartInCtx = std::move(MOrErr.get()); +- +- codegen(MPartInCtx.get(), *ThreadOS, TheTarget, CPU, Features, +- Options, RM, CM, OL, FileType); +- }, +- // Pass BC using std::move to ensure that it get moved rather than +- // copied into the thread's context. +- std::move(BC)); +- }); +- +- for (thread &T : Threads) +- T.join(); +- +- return {}; ++ return M; + } +diff --git a/lib/Support/ThreadPool.cpp b/lib/Support/ThreadPool.cpp +index d4dcb2e..bc25c59 100644 +--- a/lib/Support/ThreadPool.cpp ++++ b/lib/Support/ThreadPool.cpp +@@ -11,6 +11,8 @@ + // + //===----------------------------------------------------------------------===// + ++#if 0 ++ + #include "llvm/Support/ThreadPool.h" + + #include "llvm/Config/llvm-config.h" +@@ -153,3 +155,5 @@ ThreadPool::~ThreadPool() { + } + + #endif ++ ++#endif +diff --git a/unittests/Support/ThreadPool.cpp b/unittests/Support/ThreadPool.cpp +index 0f36c38..32f4eab 100644 +--- a/unittests/Support/ThreadPool.cpp ++++ b/unittests/Support/ThreadPool.cpp +@@ -7,6 +7,8 @@ + // + //===----------------------------------------------------------------------===// + ++#if 0 ++ + #include "llvm/Support/ThreadPool.h" + + #include "llvm/ADT/STLExtras.h" +@@ -166,3 +168,5 @@ TEST_F(ThreadPoolTest, PoolDestruction) { + } + ASSERT_EQ(5, checked_in); + } ++ ++#endif diff --git a/deps/llvm-3.8.0_winshlib.patch b/deps/llvm-3.8.0_winshlib.patch new file mode 100644 index 0000000000000..5aea42869827f --- /dev/null +++ b/deps/llvm-3.8.0_winshlib.patch @@ -0,0 +1,26 @@ +diff --git a/tools/llvm-shlib/Makefile b/tools/llvm-shlib/Makefile +index 2bc81da..4ff211d 100644 +--- a/tools/llvm-shlib/Makefile ++++ b/tools/llvm-shlib/Makefile +@@ -86,11 +86,19 @@ $(LibName.SO): $(SHLIB_STUBS) + $(Echo) Collecting global symbols of $(notdir $*) + $(Verb) $(NM_PATH) -g $< > $@ + ++# The Windows ABI specifies leading underscores only on 32bit, so ++# make sure we don't strip them on x86_64 ++ifeq ($(ARCH),x86_64) ++ABI_UNDERSCORE = ++else ++ABI_UNDERSCORE =_ ++endif ++ + $(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir + $(Echo) Generating exports for $(LIBRARYNAME) + $(Verb) ($(SED) -n \ +- -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \ +- -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \ ++ -e "s/^.* T $(ABI_UNDERSCORE)\([^.][^.]*\)$$/\1/p" \ ++ -e "s/^.* [BDR] $(ABI_UNDERSCORE)\([^.][^.]*\)$$/\1 DATA/p" \ + $(SHLIB_FRAGS) \ + | sort -u) > $@ + diff --git a/deps/llvm-D17165-D18583.patch b/deps/llvm-D17165-D18583.patch new file mode 100644 index 0000000000000..0af0ebbc56bd3 --- /dev/null +++ b/deps/llvm-D17165-D18583.patch @@ -0,0 +1,225 @@ +From 11adcc4de0797c83e61ae0240927f0bafcf041a9 Mon Sep 17 00:00:00 2001 +From: Keno Fischer +Date: Sat, 13 Feb 2016 02:04:29 +0000 +Subject: [PATCH] [Cloning] Clone every Function's Debug Info + +Summary: +Export the CloneDebugInfoMetadata utility, which clones all debug info +associated with a function into the first module. Also use this function +in CloneModule on each function we clone (the CloneFunction entrypoint +already does this). + +Without this, cloning a module will lead to DI quality regressions, +especially since r252219 reversed the Function <-> DISubprogram edge +(before we could get lucky and have this edge preserved if the +DISubprogram itself was, e.g. due to location metadata). + +This was verified to fix missing debug information in julia and +a unittest to verify the new behavior is included. + +Patch by Yichao Yu! Thanks! + +Reviewers: loladiro, pcc +Differential Revision: http://reviews.llvm.org/D17165 + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260791 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + include/llvm/Transforms/Utils/Cloning.h | 5 +++++ + lib/Transforms/Utils/CloneFunction.cpp | 4 ++-- + lib/Transforms/Utils/CloneModule.cpp | 1 + + unittests/Transforms/Utils/Cloning.cpp | 25 +++++++++++++++++++++++++ + 4 files changed, 33 insertions(+), 2 deletions(-) + +diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h +index 4f006f2..0bae2bd 100644 +--- a/include/llvm/Transforms/Utils/Cloning.h ++++ b/include/llvm/Transforms/Utils/Cloning.h +@@ -130,6 +130,11 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap, + bool ModuleLevelChanges, + ClonedCodeInfo *CodeInfo = nullptr); + ++/// Clone the module-level debug info associated with OldFunc. The cloned data ++/// will point to NewFunc instead. ++void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, ++ ValueToValueMapTy &VMap); ++ + /// Clone OldFunc into NewFunc, transforming the old arguments into references + /// to VMap values. Note that if NewFunc already has basic blocks, the ones + /// cloned into it will be added to the end of the function. This function +diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp +index 6454afb..8b5692a 100644 +--- a/lib/Transforms/Utils/CloneFunction.cpp ++++ b/lib/Transforms/Utils/CloneFunction.cpp +@@ -187,8 +187,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs, + + // Clone the module-level debug info associated with OldFunc. The cloned data + // will point to NewFunc instead. +-static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, +- ValueToValueMapTy &VMap) { ++void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, ++ ValueToValueMapTy &VMap) { + DebugInfoFinder Finder; + Finder.processModule(*OldFunc->getParent()); + +diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp +index 53de62a..b16a02a 100644 +--- a/lib/Transforms/Utils/CloneModule.cpp ++++ b/lib/Transforms/Utils/CloneModule.cpp +@@ -136,6 +136,7 @@ std::unique_ptr llvm::CloneModule( + VMap[&*J] = &*DestI++; + } + ++ CloneDebugInfoMetadata(F, &*I, VMap); + SmallVector Returns; // Ignore returns cloned. + CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns); + } +diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp +index 25e322e..b761e4e 100644 +--- a/unittests/Transforms/Utils/Cloning.cpp ++++ b/unittests/Transforms/Utils/Cloning.cpp +@@ -423,6 +423,7 @@ class CloneModule : public ::testing::Test { + void SetupModule() { OldM = new Module("", C); } + + void CreateOldModule() { ++ DIBuilder DBuilder(*OldM); + IRBuilder<> IBuilder(C); + + auto *FuncType = FunctionType::get(Type::getVoidTy(C), false); +@@ -431,9 +432,25 @@ class CloneModule : public ::testing::Test { + auto *F = + Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM); + F->setPersonalityFn(PersFn); ++ ++ // Create debug info ++ auto *File = DBuilder.createFile("filename.c", "/file/dir/"); ++ DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None); ++ DISubroutineType *DFuncType = DBuilder.createSubroutineType(ParamTypes); ++ auto *CU = ++ DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c", ++ "/file/dir", "CloneModule", false, "", 0); ++ // Function DI ++ auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, DFuncType, ++ true, true, 3, 0, false); ++ F->setSubprogram(Subprogram); ++ + auto *Entry = BasicBlock::Create(C, "", F); + IBuilder.SetInsertPoint(Entry); + IBuilder.CreateRetVoid(); ++ ++ // Finalize the debug info ++ DBuilder.finalize(); + } + + void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); } +@@ -447,4 +464,12 @@ TEST_F(CloneModule, Verify) { + EXPECT_FALSE(verifyModule(*NewM)); + } + ++TEST_F(CloneModule, Subprogram) { ++ Function *NewF = NewM->getFunction("f"); ++ DISubprogram *SP = NewF->getSubprogram(); ++ EXPECT_TRUE(SP != nullptr); ++ EXPECT_EQ(SP->getName(), "f"); ++ EXPECT_EQ(SP->getFile()->getFilename(), "filename.c"); ++ EXPECT_EQ(SP->getLine(), (unsigned)4); ++} + } +From af289e04413504c3bdc252e08c3fe17bf7ea6dc8 Mon Sep 17 00:00:00 2001 +From: Peter Collingbourne +Date: Wed, 30 Mar 2016 22:05:13 +0000 +Subject: [PATCH] Cloning: Reduce complexity of debug info cloning and fix + correctness issue. + +Commit r260791 contained an error in that it would introduce a cross-module +reference in the old module. It also introduced O(N^2) complexity in the +module cloner by requiring the entire module to be visited for each function. +Fix both of these problems by avoiding use of the CloneDebugInfoMetadata +function (which is only designed to do intra-module cloning) and cloning +function-attached metadata in the same way that we clone all other metadata. + +Differential Revision: http://reviews.llvm.org/D18583 + +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264935 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + include/llvm/Transforms/Utils/Cloning.h | 5 ----- + lib/Transforms/Utils/CloneFunction.cpp | 13 +++++++++++-- + lib/Transforms/Utils/CloneModule.cpp | 1 - + unittests/Transforms/Utils/Cloning.cpp | 6 ++++++ + 4 files changed, 17 insertions(+), 8 deletions(-) + +diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h +index 0bae2bd..4f006f2 100644 +--- a/include/llvm/Transforms/Utils/Cloning.h ++++ b/include/llvm/Transforms/Utils/Cloning.h +@@ -130,11 +130,6 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap, + bool ModuleLevelChanges, + ClonedCodeInfo *CodeInfo = nullptr); + +-/// Clone the module-level debug info associated with OldFunc. The cloned data +-/// will point to NewFunc instead. +-void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, +- ValueToValueMapTy &VMap); +- + /// Clone OldFunc into NewFunc, transforming the old arguments into references + /// to VMap values. Note that if NewFunc already has basic blocks, the ones + /// cloned into it will be added to the end of the function. This function +diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp +index 05b0a17..8e1715a 100644 +--- a/lib/Transforms/Utils/CloneFunction.cpp ++++ b/lib/Transforms/Utils/CloneFunction.cpp +@@ -119,6 +119,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc, + .addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex, + OldAttrs.getFnAttributes())); + ++ SmallVector, 1> MDs; ++ OldFunc->getAllMetadata(MDs); ++ for (auto MD : MDs) ++ NewFunc->setMetadata( ++ MD.first, ++ MapMetadata(MD.second, VMap, ++ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges, ++ TypeMapper, Materializer)); ++ + // Loop over all of the basic blocks in the function, cloning them as + // appropriate. Note that we save BE this way in order to handle cloning of + // recursive functions into themselves. +@@ -187,8 +196,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs, + + // Clone the module-level debug info associated with OldFunc. The cloned data + // will point to NewFunc instead. +-void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, +- ValueToValueMapTy &VMap) { ++static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc, ++ ValueToValueMapTy &VMap) { + DebugInfoFinder Finder; + Finder.processModule(*OldFunc->getParent()); + +diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp +index 494e275..929f51b 100644 +--- a/lib/Transforms/Utils/CloneModule.cpp ++++ b/lib/Transforms/Utils/CloneModule.cpp +@@ -138,7 +138,6 @@ std::unique_ptr llvm::CloneModule( + VMap[&*J] = &*DestI++; + } + +- CloneDebugInfoMetadata(F, &*I, VMap); + SmallVector Returns; // Ignore returns cloned. + CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns); + } +diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp +index b761e4e..f06a20f 100644 +--- a/unittests/Transforms/Utils/Cloning.cpp ++++ b/unittests/Transforms/Utils/Cloning.cpp +@@ -464,6 +464,12 @@ TEST_F(CloneModule, Verify) { + EXPECT_FALSE(verifyModule(*NewM)); + } + ++TEST_F(CloneModule, OldModuleUnchanged) { ++ DebugInfoFinder Finder; ++ Finder.processModule(*OldM); ++ EXPECT_EQ(1U, Finder.subprogram_count()); ++} ++ + TEST_F(CloneModule, Subprogram) { + Function *NewF = NewM->getFunction("f"); + DISubprogram *SP = NewF->getSubprogram(); diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index fd5aa56e3f851..7fec1e4b9e21b 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -337,7 +337,7 @@ class JuliaJITEventListener: public JITEventListener Addr = sym_iter.getAddress().get(); Section = sym_iter.getSection().get(); assert(Section != EndSection && Section->isText()); - SectionAddr = Section->getAddress().get(); + SectionAddr = Section->getAddress(); Section->getName(sName); SectionLoadAddr = getLoadAddress(sName); #elif defined(LLVM37)