Skip to content

Commit ee9f74f

Browse files
committed
Add patches for LLVM 3.8.0
1 parent ec6f886 commit ee9f74f

File tree

5 files changed

+219
-1
lines changed

5 files changed

+219
-1
lines changed

deps/Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ LLVM_FLAGS += --enable-libcpp
414414
endif # USE_LIBCPP
415415
ifeq ($(OS), WINNT)
416416
LLVM_FLAGS += --with-extra-ld-options="-Wl,--stack,8388608" LDFLAGS=""
417-
LLVM_CPPFLAGS += -D__USING_SJLJ_EXCEPTIONS__ -D__CRT__NO_INLINE
417+
LLVM_CPPFLAGS += -D__USING_SJLJ_EXCEPTIONS__ -D__CRT__NO_INLINE -DMINGW_HAS_SECURE_API=1
418418
ifneq ($(BUILD_OS),WINNT)
419419
LLVM_CMAKE += -DCROSS_TOOLCHAIN_FLAGS_NATIVE=-DCMAKE_TOOLCHAIN_FILE=$(SRCDIR)/NATIVE.cmake
420420
endif # BUILD_OS != WINNT
@@ -720,6 +720,12 @@ $(eval $(call LLVM_PATCH,llvm-3.7.1_2))
720720
$(eval $(call LLVM_PATCH,llvm-3.7.1_3))
721721
$(eval $(call LLVM_PATCH,llvm-D14260))
722722
$(LLVM_SRC_DIR)/llvm-3.7.1_2.patch-applied: $(LLVM_SRC_DIR)/llvm-3.7.1.patch-applied
723+
else ifeq ($(LLVM_VER),3.8.0)
724+
$(eval $(call LLVM_PATCH,llvm-3.7.1_3))
725+
$(eval $(call LLVM_PATCH,llvm-D14260))
726+
$(eval $(call LLVM_PATCH,llvm-3.8.0_winshlib))
727+
# Cygwin and openSUSE still use win32-threads mingw, https://llvm.org/bugs/show_bug.cgi?id=26365
728+
$(eval $(call LLVM_PATCH,llvm-3.8.0_threads))
723729
endif # LLVM_VER
724730

725731
ifeq ($(LLVM_VER),3.7.1)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
07a7a74f3c6bd65de4702bf941b511a0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2c76e79d803768ed20af6ca1801cf2518071bf9835c54580ea3eb6219a66cdcf8b4c575f192c15082cc18d2468b7611dacb57950b605813a2317125c2d33c138

deps/llvm-3.8.0_threads.patch

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
From 69ef168544e4f15b793dd35d272008fde9a6e835 Mon Sep 17 00:00:00 2001
2+
From: Alex Crichton <[email protected]>
3+
Date: Thu, 28 Jan 2016 20:44:50 -0800
4+
Subject: [PATCH] Don't compile usage of std::thread
5+
6+
As of the time of this writing it's not actually used anywhere meaningfullly
7+
throughout the LLVM repo that we need, and it unfortunately uses `std::thread`
8+
which isn't available in mingw-w64 toolchains with the win32 threading model
9+
(the one that we use).
10+
11+
Two major changes were made to achieve this:
12+
13+
1. The `ThreadPool.cpp` file was just entirely commented out. This isn't used
14+
anywhere in the LLVM repo nor in Rust itself.
15+
2. The `ParallelCG.cpp` file was mostly deleted. Unfortunately it's used a few
16+
places in LLVM and is needed to link correctly, but we in Rust don't use it
17+
at all. For now it's just a stub implementation that hopefully compiles
18+
everywhere, but perhaps we can find a less invasive (aka doesn't have rebase
19+
conflicts in the future) change to apply soon.
20+
21+
For reference, the upstream LLVM bug has been reported [1]
22+
23+
[1]: https://llvm.org/bugs/show_bug.cgi?id=26365
24+
---
25+
include/llvm/Support/ThreadPool.h | 4 +++
26+
include/llvm/Support/thread.h | 4 +++
27+
lib/CodeGen/ParallelCG.cpp | 63 +--------------------------------------
28+
lib/Support/ThreadPool.cpp | 4 +++
29+
4 files changed, 13 insertions(+), 62 deletions(-)
30+
31+
diff --git a/include/llvm/Support/ThreadPool.h b/include/llvm/Support/ThreadPool.h
32+
index 745334d..4564615 100644
33+
--- a/include/llvm/Support/ThreadPool.h
34+
+++ b/include/llvm/Support/ThreadPool.h
35+
@@ -11,6 +11,8 @@
36+
//
37+
//===----------------------------------------------------------------------===//
38+
39+
+#if 0
40+
+
41+
#ifndef LLVM_SUPPORT_THREAD_POOL_H
42+
#define LLVM_SUPPORT_THREAD_POOL_H
43+
44+
@@ -134,3 +136,5 @@ class ThreadPool {
45+
}
46+
47+
#endif // LLVM_SUPPORT_THREAD_POOL_H
48+
+
49+
+#endif
50+
diff --git a/include/llvm/Support/thread.h b/include/llvm/Support/thread.h
51+
index 2d13041..80340e6 100644
52+
--- a/include/llvm/Support/thread.h
53+
+++ b/include/llvm/Support/thread.h
54+
@@ -14,6 +14,8 @@
55+
//
56+
//===----------------------------------------------------------------------===//
57+
58+
+#if 0
59+
+
60+
#ifndef LLVM_SUPPORT_THREAD_H
61+
#define LLVM_SUPPORT_THREAD_H
62+
63+
@@ -64,3 +66,5 @@ struct thread {
64+
#endif // LLVM_ENABLE_THREADS
65+
66+
#endif
67+
+
68+
+#endif
69+
diff --git a/lib/CodeGen/ParallelCG.cpp b/lib/CodeGen/ParallelCG.cpp
70+
index e73ba02..7362cda 100644
71+
--- a/lib/CodeGen/ParallelCG.cpp
72+
+++ b/lib/CodeGen/ParallelCG.cpp
73+
@@ -25,72 +25,11 @@
74+
75+
using namespace llvm;
76+
77+
-static void codegen(Module *M, llvm::raw_pwrite_stream &OS,
78+
- const Target *TheTarget, StringRef CPU, StringRef Features,
79+
- const TargetOptions &Options, Reloc::Model RM,
80+
- CodeModel::Model CM, CodeGenOpt::Level OL,
81+
- TargetMachine::CodeGenFileType FileType) {
82+
- std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
83+
- M->getTargetTriple(), CPU, Features, Options, RM, CM, OL));
84+
-
85+
- legacy::PassManager CodeGenPasses;
86+
- if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType))
87+
- report_fatal_error("Failed to setup codegen");
88+
- CodeGenPasses.run(*M);
89+
-}
90+
-
91+
std::unique_ptr<Module>
92+
llvm::splitCodeGen(std::unique_ptr<Module> M,
93+
ArrayRef<llvm::raw_pwrite_stream *> OSs, StringRef CPU,
94+
StringRef Features, const TargetOptions &Options,
95+
Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL,
96+
TargetMachine::CodeGenFileType FileType) {
97+
- StringRef TripleStr = M->getTargetTriple();
98+
- std::string ErrMsg;
99+
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
100+
- if (!TheTarget)
101+
- report_fatal_error(Twine("Target not found: ") + ErrMsg);
102+
-
103+
- if (OSs.size() == 1) {
104+
- codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM,
105+
- OL, FileType);
106+
- return M;
107+
- }
108+
-
109+
- std::vector<thread> Threads;
110+
- SplitModule(std::move(M), OSs.size(), [&](std::unique_ptr<Module> MPart) {
111+
- // We want to clone the module in a new context to multi-thread the codegen.
112+
- // We do it by serializing partition modules to bitcode (while still on the
113+
- // main thread, in order to avoid data races) and spinning up new threads
114+
- // which deserialize the partitions into separate contexts.
115+
- // FIXME: Provide a more direct way to do this in LLVM.
116+
- SmallVector<char, 0> BC;
117+
- raw_svector_ostream BCOS(BC);
118+
- WriteBitcodeToFile(MPart.get(), BCOS);
119+
-
120+
- llvm::raw_pwrite_stream *ThreadOS = OSs[Threads.size()];
121+
- Threads.emplace_back(
122+
- [TheTarget, CPU, Features, Options, RM, CM, OL, FileType,
123+
- ThreadOS](const SmallVector<char, 0> &BC) {
124+
- LLVMContext Ctx;
125+
- ErrorOr<std::unique_ptr<Module>> MOrErr =
126+
- parseBitcodeFile(MemoryBufferRef(StringRef(BC.data(), BC.size()),
127+
- "<split-module>"),
128+
- Ctx);
129+
- if (!MOrErr)
130+
- report_fatal_error("Failed to read bitcode");
131+
- std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
132+
-
133+
- codegen(MPartInCtx.get(), *ThreadOS, TheTarget, CPU, Features,
134+
- Options, RM, CM, OL, FileType);
135+
- },
136+
- // Pass BC using std::move to ensure that it get moved rather than
137+
- // copied into the thread's context.
138+
- std::move(BC));
139+
- });
140+
-
141+
- for (thread &T : Threads)
142+
- T.join();
143+
-
144+
- return {};
145+
+ return M;
146+
}
147+
diff --git a/lib/Support/ThreadPool.cpp b/lib/Support/ThreadPool.cpp
148+
index d4dcb2e..bc25c59 100644
149+
--- a/lib/Support/ThreadPool.cpp
150+
+++ b/lib/Support/ThreadPool.cpp
151+
@@ -11,6 +11,8 @@
152+
//
153+
//===----------------------------------------------------------------------===//
154+
155+
+#if 0
156+
+
157+
#include "llvm/Support/ThreadPool.h"
158+
159+
#include "llvm/Config/llvm-config.h"
160+
@@ -153,3 +155,5 @@ ThreadPool::~ThreadPool() {
161+
}
162+
163+
#endif
164+
+
165+
+#endif
166+
diff --git a/unittests/Support/ThreadPool.cpp b/unittests/Support/ThreadPool.cpp
167+
index 0f36c38..32f4eab 100644
168+
--- a/unittests/Support/ThreadPool.cpp
169+
+++ b/unittests/Support/ThreadPool.cpp
170+
@@ -7,6 +7,8 @@
171+
//
172+
//===----------------------------------------------------------------------===//
173+
174+
+#if 0
175+
+
176+
#include "llvm/Support/ThreadPool.h"
177+
178+
#include "llvm/ADT/STLExtras.h"
179+
@@ -166,3 +168,5 @@ TEST_F(ThreadPoolTest, PoolDestruction) {
180+
}
181+
ASSERT_EQ(5, checked_in);
182+
}
183+
+
184+
+#endif

deps/llvm-3.8.0_winshlib.patch

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/tools/llvm-shlib/Makefile b/tools/llvm-shlib/Makefile
2+
index 2bc81da..4ff211d 100644
3+
--- a/tools/llvm-shlib/Makefile
4+
+++ b/tools/llvm-shlib/Makefile
5+
@@ -86,11 +86,19 @@ $(LibName.SO): $(SHLIB_STUBS)
6+
$(Echo) Collecting global symbols of $(notdir $*)
7+
$(Verb) $(NM_PATH) -g $< > $@
8+
9+
+# The Windows ABI specifies leading underscores only on 32bit, so
10+
+# make sure we don't strip them on x86_64
11+
+ifeq ($(ARCH),x86_64)
12+
+ABI_UNDERSCORE =
13+
+else
14+
+ABI_UNDERSCORE =_
15+
+endif
16+
+
17+
$(ObjDir)/$(LIBRARYNAME).exports: $(SHLIB_FRAGS) $(ObjDir)/.dir
18+
$(Echo) Generating exports for $(LIBRARYNAME)
19+
$(Verb) ($(SED) -n \
20+
- -e "s/^.* T _\([^.][^.]*\)$$/\1/p" \
21+
- -e "s/^.* [BDR] _\([^.][^.]*\)$$/\1 DATA/p" \
22+
+ -e "s/^.* T $(ABI_UNDERSCORE)\([^.][^.]*\)$$/\1/p" \
23+
+ -e "s/^.* [BDR] $(ABI_UNDERSCORE)\([^.][^.]*\)$$/\1 DATA/p" \
24+
$(SHLIB_FRAGS) \
25+
| sort -u) > $@
26+

0 commit comments

Comments
 (0)