Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patches for LLVM 3.8.0 #15417

Merged
merged 3 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions deps/checksums/llvm-3.8.0.src.tar.xz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
07a7a74f3c6bd65de4702bf941b511a0
1 change: 1 addition & 0 deletions deps/checksums/llvm-3.8.0.src.tar.xz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2c76e79d803768ed20af6ca1801cf2518071bf9835c54580ea3eb6219a66cdcf8b4c575f192c15082cc18d2468b7611dacb57950b605813a2317125c2d33c138
184 changes: 184 additions & 0 deletions deps/llvm-3.8.0_threads.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
From 69ef168544e4f15b793dd35d272008fde9a6e835 Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
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<TargetMachine> 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<Module>
llvm::splitCodeGen(std::unique_ptr<Module> M,
ArrayRef<llvm::raw_pwrite_stream *> 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<thread> Threads;
- SplitModule(std::move(M), OSs.size(), [&](std::unique_ptr<Module> 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<char, 0> 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<char, 0> &BC) {
- LLVMContext Ctx;
- ErrorOr<std::unique_ptr<Module>> MOrErr =
- parseBitcodeFile(MemoryBufferRef(StringRef(BC.data(), BC.size()),
- "<split-module>"),
- Ctx);
- if (!MOrErr)
- report_fatal_error("Failed to read bitcode");
- std::unique_ptr<Module> 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
26 changes: 26 additions & 0 deletions deps/llvm-3.8.0_winshlib.patch
Original file line number Diff line number Diff line change
@@ -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) > $@

Loading