Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/llvm/files/4.0.1/, sys-devel/llvm/files/5.0.1/, sys-devel/llvm/
Date: Fri, 01 Dec 2017 23:41:08
Message-Id: 1512171643.3f7b543082fa986823d08a1df44eb8bf634f10df.mgorny@gentoo
1 commit: 3f7b543082fa986823d08a1df44eb8bf634f10df
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Dec 1 16:23:42 2017 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Fri Dec 1 23:40:43 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3f7b5430
7
8 sys-devel/llvm: Backport unloading prevention fix
9
10 Bug: https://bugs.gentoo.org/617154
11
12 ...Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch | 56 +++++++++++++++++
13 ...Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch | 71 ++++++++++++++++++++++
14 .../{llvm-4.0.1.ebuild => llvm-4.0.1-r1.ebuild} | 4 ++
15 sys-devel/llvm/llvm-5.0.1_rc2.ebuild | 4 ++
16 sys-devel/llvm/llvm-5.0.9999.ebuild | 4 ++
17 5 files changed, 139 insertions(+)
18
19 diff --git a/sys-devel/llvm/files/4.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch b/sys-devel/llvm/files/4.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
20 new file mode 100644
21 index 00000000000..b857136498b
22 --- /dev/null
23 +++ b/sys-devel/llvm/files/4.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
24 @@ -0,0 +1,56 @@
25 +From 937b23b5fffa59deb1dc342cc5602d387d84a762 Mon Sep 17 00:00:00 2001
26 +From: Michal Gorny <mgorny@g.o>
27 +Date: Mon, 27 Nov 2017 22:23:09 +0000
28 +Subject: [PATCH] [cmake] Pass -Wl,-z,nodelete on Linux to prevent unloading
29 +
30 +Prevent unloading shared libraries on Linux when dlclose() is called.
31 +This is necessary since command-line option parsing API relies on
32 +registering the global option instances in the option parser instance
33 +which can be loaded in a different shared library.
34 +
35 +Given that we can't reliably remove those options when a library is
36 +unloaded, the parser ends up containing dangling references. Since glibc
37 +has relatively complex library unloading rules, some of the LLVM
38 +libraries can be unloaded while others (including the Support library)
39 +stay loaded causing quite a mayhem. To reliably prevent that, just
40 +forbid unloading all libraries -- it's a very bad idea anyway.
41 +
42 +While the issue arguably happens only with BUILD_SHARED_LIBS, it may
43 +affect any library reusing llvm::cl interface.
44 +
45 +Based on patch provided Ross Hayward on https://bugs.gentoo.org/617154.
46 +Previously hit by Fedora back in Feb 2016:
47 +https://lists.freedesktop.org/archives/mesa-dev/2016-February/107242.html
48 +
49 +Differential Revision: https://reviews.llvm.org/D40459
50 +
51 +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319105 91177308-0d34-0410-b5e6-96231b3b80d8
52 +---
53 + cmake/modules/HandleLLVMOptions.cmake | 8 ++++++++
54 + unittests/Support/DynamicLibrary/CMakeLists.txt | 7 +++++++
55 + 2 files changed, 15 insertions(+)
56 +
57 + 4.0.1 backport: removed the unittest part
58 +
59 +diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
60 +index c5390371845..b5059a8a60e 100644
61 +--- a/cmake/modules/HandleLLVMOptions.cmake
62 ++++ b/cmake/modules/HandleLLVMOptions.cmake
63 +@@ -151,6 +151,14 @@ if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR
64 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
65 + endif()
66 +
67 ++# Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded
68 ++# by dlclose(). We need that since the CLI API relies on cross-references
69 ++# between global objects which became horribly broken when one of the libraries
70 ++# is unloaded.
71 ++if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
72 ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete")
73 ++endif()
74 ++
75 +
76 + function(append value)
77 + foreach(variable ${ARGN})
78 +--
79 +2.15.1
80 +
81
82 diff --git a/sys-devel/llvm/files/5.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch b/sys-devel/llvm/files/5.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
83 new file mode 100644
84 index 00000000000..21702748893
85 --- /dev/null
86 +++ b/sys-devel/llvm/files/5.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
87 @@ -0,0 +1,71 @@
88 +From 937b23b5fffa59deb1dc342cc5602d387d84a762 Mon Sep 17 00:00:00 2001
89 +From: Michal Gorny <mgorny@g.o>
90 +Date: Mon, 27 Nov 2017 22:23:09 +0000
91 +Subject: [PATCH] [cmake] Pass -Wl,-z,nodelete on Linux to prevent unloading
92 +
93 +Prevent unloading shared libraries on Linux when dlclose() is called.
94 +This is necessary since command-line option parsing API relies on
95 +registering the global option instances in the option parser instance
96 +which can be loaded in a different shared library.
97 +
98 +Given that we can't reliably remove those options when a library is
99 +unloaded, the parser ends up containing dangling references. Since glibc
100 +has relatively complex library unloading rules, some of the LLVM
101 +libraries can be unloaded while others (including the Support library)
102 +stay loaded causing quite a mayhem. To reliably prevent that, just
103 +forbid unloading all libraries -- it's a very bad idea anyway.
104 +
105 +While the issue arguably happens only with BUILD_SHARED_LIBS, it may
106 +affect any library reusing llvm::cl interface.
107 +
108 +Based on patch provided Ross Hayward on https://bugs.gentoo.org/617154.
109 +Previously hit by Fedora back in Feb 2016:
110 +https://lists.freedesktop.org/archives/mesa-dev/2016-February/107242.html
111 +
112 +Differential Revision: https://reviews.llvm.org/D40459
113 +
114 +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319105 91177308-0d34-0410-b5e6-96231b3b80d8
115 +---
116 + cmake/modules/HandleLLVMOptions.cmake | 8 ++++++++
117 + unittests/Support/DynamicLibrary/CMakeLists.txt | 7 +++++++
118 + 2 files changed, 15 insertions(+)
119 +
120 +diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
121 +index c5390371845..b5059a8a60e 100644
122 +--- a/cmake/modules/HandleLLVMOptions.cmake
123 ++++ b/cmake/modules/HandleLLVMOptions.cmake
124 +@@ -151,6 +151,14 @@ if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR
125 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
126 + endif()
127 +
128 ++# Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded
129 ++# by dlclose(). We need that since the CLI API relies on cross-references
130 ++# between global objects which became horribly broken when one of the libraries
131 ++# is unloaded.
132 ++if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
133 ++ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,nodelete")
134 ++endif()
135 ++
136 +
137 + function(append value)
138 + foreach(variable ${ARGN})
139 +diff --git a/unittests/Support/DynamicLibrary/CMakeLists.txt b/unittests/Support/DynamicLibrary/CMakeLists.txt
140 +index 9355979221a..c6201b1ad31 100644
141 +--- a/unittests/Support/DynamicLibrary/CMakeLists.txt
142 ++++ b/unittests/Support/DynamicLibrary/CMakeLists.txt
143 +@@ -24,5 +24,12 @@ function(dynlib_add_module NAME)
144 + add_dependencies(DynamicLibraryTests ${NAME})
145 + endfunction(dynlib_add_module)
146 +
147 ++# Revert -Wl,-z,nodelete on this test since it relies on the file
148 ++# being unloaded.
149 ++if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
150 ++ string(REPLACE "-Wl,-z,nodelete" "" CMAKE_SHARED_LINKER_FLAGS
151 ++ ${CMAKE_SHARED_LINKER_FLAGS})
152 ++endif()
153 ++
154 + dynlib_add_module(PipSqueak)
155 + dynlib_add_module(SecondLib)
156 +--
157 +2.15.1
158 +
159
160 diff --git a/sys-devel/llvm/llvm-4.0.1.ebuild b/sys-devel/llvm/llvm-4.0.1-r1.ebuild
161 similarity index 97%
162 rename from sys-devel/llvm/llvm-4.0.1.ebuild
163 rename to sys-devel/llvm/llvm-4.0.1-r1.ebuild
164 index 6ee123541ac..1931365e8a7 100644
165 --- a/sys-devel/llvm/llvm-4.0.1.ebuild
166 +++ b/sys-devel/llvm/llvm-4.0.1-r1.ebuild
167 @@ -75,6 +75,10 @@ src_prepare() {
168 # https://bugs.gentoo.org/show_bug.cgi?id=565358
169 eapply "${FILESDIR}"/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
170
171 + # Backport the fix for dlclose() causing option parser mess
172 + # e.g. https://bugs.gentoo.org/617154
173 + eapply "${FILESDIR}"/4.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
174 +
175 # support building llvm against musl-libc
176 use elibc_musl && eapply "${FILESDIR}"/9999/musl-fixes.patch
177
178
179 diff --git a/sys-devel/llvm/llvm-5.0.1_rc2.ebuild b/sys-devel/llvm/llvm-5.0.1_rc2.ebuild
180 index 374656b01b2..42978ec5cce 100644
181 --- a/sys-devel/llvm/llvm-5.0.1_rc2.ebuild
182 +++ b/sys-devel/llvm/llvm-5.0.1_rc2.ebuild
183 @@ -75,6 +75,10 @@ src_prepare() {
184 # https://bugs.gentoo.org/show_bug.cgi?id=565358
185 eapply "${FILESDIR}"/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
186
187 + # Backport the fix for dlclose() causing option parser mess
188 + # e.g. https://bugs.gentoo.org/617154
189 + eapply "${FILESDIR}"/5.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
190 +
191 # disable use of SDK on OSX, bug #568758
192 sed -i -e 's/xcrun/false/' utils/lit/lit/util.py || die
193
194
195 diff --git a/sys-devel/llvm/llvm-5.0.9999.ebuild b/sys-devel/llvm/llvm-5.0.9999.ebuild
196 index 3bf676e4360..2c8a9d8ecf0 100644
197 --- a/sys-devel/llvm/llvm-5.0.9999.ebuild
198 +++ b/sys-devel/llvm/llvm-5.0.9999.ebuild
199 @@ -75,6 +75,10 @@ src_prepare() {
200 # https://bugs.gentoo.org/show_bug.cgi?id=565358
201 eapply "${FILESDIR}"/9999/0007-llvm-config-Clean-up-exported-values-update-for-shar.patch
202
203 + # Backport the fix for dlclose() causing option parser mess
204 + # e.g. https://bugs.gentoo.org/617154
205 + eapply "${FILESDIR}"/5.0.1/0001-cmake-Pass-Wl-z-nodelete-on-Linux-to-prevent-unloadi.patch
206 +
207 # disable use of SDK on OSX, bug #568758
208 sed -i -e 's/xcrun/false/' utils/lit/lit/util.py || die