1 |
commit: ac0ba596486e18bea03c0a59cc95b0c036443ebb |
2 |
Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun May 26 08:20:45 2019 +0000 |
4 |
Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun May 26 08:25:54 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ac0ba596 |
7 |
|
8 |
dev-lang/erlang: fix lto support, bug #681778 |
9 |
|
10 |
re:replace/4 used libpcre2 with a stack overflow check. |
11 |
lto was smart enough to inline the check too much to |
12 |
make it useless. |
13 |
|
14 |
The changes uninlines stack prober and fixes re:replace/4. |
15 |
|
16 |
Reported-by: Fabio Coatti |
17 |
Closes: https://bugs.gentoo.org/681778 |
18 |
Package-Manager: Portage-2.3.66, Repoman-2.3.12 |
19 |
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org> |
20 |
|
21 |
dev-lang/erlang/erlang-21.3-r1.ebuild | 161 ++++++++++++++++++++++++++++ |
22 |
dev-lang/erlang/files/erlang-21.3-lto.patch | 140 ++++++++++++++++++++++++ |
23 |
2 files changed, 301 insertions(+) |
24 |
|
25 |
diff --git a/dev-lang/erlang/erlang-21.3-r1.ebuild b/dev-lang/erlang/erlang-21.3-r1.ebuild |
26 |
new file mode 100644 |
27 |
index 00000000000..75e06e5602b |
28 |
--- /dev/null |
29 |
+++ b/dev-lang/erlang/erlang-21.3-r1.ebuild |
30 |
@@ -0,0 +1,161 @@ |
31 |
+# Copyright 1999-2019 Gentoo Authors |
32 |
+# Distributed under the terms of the GNU General Public License v2 |
33 |
+ |
34 |
+EAPI=6 |
35 |
+WX_GTK_VER="3.0" |
36 |
+ |
37 |
+inherit autotools eapi7-ver elisp-common java-pkg-opt-2 systemd wxwidgets |
38 |
+ |
39 |
+# NOTE: If you need symlinks for binaries please tell maintainers or |
40 |
+# open up a bug to let it be created. |
41 |
+ |
42 |
+UPSTREAM_V="$(ver_cut 1-2)" |
43 |
+ |
44 |
+DESCRIPTION="Erlang programming language, runtime environment and libraries (OTP)" |
45 |
+HOMEPAGE="https://www.erlang.org/" |
46 |
+SRC_URI="https://github.com/erlang/otp/archive/OTP-${PV}.tar.gz -> ${P}.tar.gz |
47 |
+ http://erlang.org/download/otp_doc_man_${UPSTREAM_V}.tar.gz -> ${PN}_doc_man_${UPSTREAM_V}.tar.gz |
48 |
+ doc? ( http://erlang.org/download/otp_doc_html_${UPSTREAM_V}.tar.gz -> ${PN}_doc_html_${UPSTREAM_V}.tar.gz )" |
49 |
+ |
50 |
+LICENSE="Apache-2.0" |
51 |
+SLOT="0" |
52 |
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~sparc ~x86 ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~x64-solaris" |
53 |
+IUSE="doc emacs +hipe java +kpoll libressl odbc pgo sctp ssl systemd tk wxwidgets" |
54 |
+ |
55 |
+RDEPEND=" |
56 |
+ sys-libs/ncurses:0 |
57 |
+ sys-libs/zlib |
58 |
+ emacs? ( virtual/emacs ) |
59 |
+ java? ( >=virtual/jdk-1.8:* ) |
60 |
+ odbc? ( dev-db/unixODBC ) |
61 |
+ sctp? ( net-misc/lksctp-tools ) |
62 |
+ ssl? ( |
63 |
+ !libressl? ( >=dev-libs/openssl-0.9.7d:0= ) |
64 |
+ libressl? ( dev-libs/libressl:0= ) |
65 |
+ ) |
66 |
+ systemd? ( sys-apps/systemd ) |
67 |
+ tk? ( dev-lang/tk:0 ) |
68 |
+ wxwidgets? ( x11-libs/wxGTK:${WX_GTK_VER}[X,opengl] ) |
69 |
+" |
70 |
+DEPEND="${RDEPEND} |
71 |
+ dev-lang/perl |
72 |
+" |
73 |
+ |
74 |
+S="${WORKDIR}/otp-OTP-${PV}" |
75 |
+ |
76 |
+PATCHES=( |
77 |
+ "${FILESDIR}/18.2.1-wx3.0.patch" |
78 |
+ "${FILESDIR}/${PN}-20.3.2-dont-ignore-LDFLAGS.patch" |
79 |
+ "${FILESDIR}/${PN}-add-epmd-pid-file-creation-for-openrc.patch" |
80 |
+ "${FILESDIR}/${PN}-custom-autoconf.patch" |
81 |
+ "${FILESDIR}/${PN}-21.3-lto.patch" |
82 |
+) |
83 |
+ |
84 |
+SITEFILE=50"${PN}"-gentoo.el |
85 |
+ |
86 |
+src_prepare() { |
87 |
+ default |
88 |
+ |
89 |
+ ./otp_build autoconf |
90 |
+ find -name configure.in -execdir mv '{}' configure.ac \; || die "find failed" |
91 |
+ eautoreconf |
92 |
+} |
93 |
+ |
94 |
+src_configure() { |
95 |
+ use wxwidgets && setup-wxwidgets |
96 |
+ |
97 |
+ local myconf=( |
98 |
+ --disable-builtin-zlib |
99 |
+ $(use_enable hipe) |
100 |
+ $(use_enable kpoll kernel-poll) |
101 |
+ $(use_with java javac) |
102 |
+ $(use_with odbc) |
103 |
+ $(use_enable sctp) |
104 |
+ $(use_with ssl ssl "${EPREFIX}"/usr) |
105 |
+ $(use_enable ssl dynamic-ssl-lib) |
106 |
+ $(use_enable systemd) |
107 |
+ $(use_enable pgo) |
108 |
+ $(usex wxwidgets "--with-wx-config=${WX_CONFIG}" "--with-wxdir=/dev/null") |
109 |
+ --enable-threads |
110 |
+ ) |
111 |
+ econf "${myconf[@]}" |
112 |
+} |
113 |
+ |
114 |
+src_compile() { |
115 |
+ if use pgo; then |
116 |
+ # disable distcc and ccache |
117 |
+ export DISTCC_HOSTS="" |
118 |
+ export CCACHE_DISABLE=1 |
119 |
+ fi |
120 |
+ |
121 |
+ emake |
122 |
+ |
123 |
+ if use emacs ; then |
124 |
+ pushd lib/tools/emacs &>/dev/null || die |
125 |
+ elisp-compile *.el |
126 |
+ popd &>/dev/null || die |
127 |
+ fi |
128 |
+} |
129 |
+ |
130 |
+extract_version() { |
131 |
+ local path="$1" |
132 |
+ local var_name="$2" |
133 |
+ sed -n -e "/^${var_name} = \(.*\)$/s::\1:p" "${S}/${path}/vsn.mk" || die "extract_version() failed" |
134 |
+} |
135 |
+ |
136 |
+src_install() { |
137 |
+ local erl_libdir_rel="$(get_libdir)/erlang" |
138 |
+ local erl_libdir="/usr/${erl_libdir_rel}" |
139 |
+ local erl_interface_ver="$(extract_version lib/erl_interface EI_VSN)" |
140 |
+ local erl_erts_ver="$(extract_version erts VSN)" |
141 |
+ local my_manpath="/usr/share/${PN}/man" |
142 |
+ |
143 |
+ [[ -z "${erl_erts_ver}" ]] && die "Couldn't determine erts version" |
144 |
+ [[ -z "${erl_interface_ver}" ]] && die "Couldn't determine interface version" |
145 |
+ |
146 |
+ emake INSTALL_PREFIX="${D}" install |
147 |
+ |
148 |
+ if use doc ; then |
149 |
+ local DOCS=( "AUTHORS" "HOWTO"/* "README.md" "CONTRIBUTING.md" "${WORKDIR}"/doc/. "${WORKDIR}"/lib/. "${WORKDIR}"/erts-* ) |
150 |
+ docompress -x /usr/share/doc/${PF} |
151 |
+ else |
152 |
+ local DOCS=("README.md") |
153 |
+ fi |
154 |
+ |
155 |
+ einstalldocs |
156 |
+ |
157 |
+ dosym "../${erl_libdir_rel}/bin/erl" /usr/bin/erl |
158 |
+ dosym "../${erl_libdir_rel}/bin/erlc" /usr/bin/erlc |
159 |
+ dosym "../${erl_libdir_rel}/bin/escript" /usr/bin/escript |
160 |
+ dosym "../${erl_libdir_rel}/lib/erl_interface-${erl_interface_ver}/bin/erl_call" /usr/bin/erl_call |
161 |
+ dosym "../${erl_libdir_rel}/erts-${erl_erts_ver}/bin/beam.smp" /usr/bin/beam.smp |
162 |
+ |
163 |
+ ## Clean up the no longer needed files |
164 |
+ rm "${ED}/${erl_libdir}/Install" || die |
165 |
+ |
166 |
+ insinto "${my_manpath}" |
167 |
+ doins -r "${WORKDIR}"/man/* |
168 |
+ # extend MANPATH, so the normal man command can find it |
169 |
+ # see bug 189639 |
170 |
+ newenvd - "90erlang" <<-_EOF_ |
171 |
+ MANPATH="${my_manpath}" |
172 |
+ _EOF_ |
173 |
+ |
174 |
+ if use emacs ; then |
175 |
+ elisp-install erlang lib/tools/emacs/*.{el,elc} |
176 |
+ sed -e "s:/usr/share:${EPREFIX}/usr/share:g" \ |
177 |
+ "${FILESDIR}/${SITEFILE}" > "${T}/${SITEFILE}" || die |
178 |
+ elisp-site-file-install "${T}/${SITEFILE}" |
179 |
+ fi |
180 |
+ |
181 |
+ newinitd "${FILESDIR}"/epmd.init epmd |
182 |
+ use systemd && systemd_dounit "${FILESDIR}"/epmd.service |
183 |
+} |
184 |
+ |
185 |
+pkg_postinst() { |
186 |
+ use emacs && elisp-site-regen |
187 |
+} |
188 |
+ |
189 |
+pkg_postrm() { |
190 |
+ use emacs && elisp-site-regen |
191 |
+} |
192 |
|
193 |
diff --git a/dev-lang/erlang/files/erlang-21.3-lto.patch b/dev-lang/erlang/files/erlang-21.3-lto.patch |
194 |
new file mode 100644 |
195 |
index 00000000000..c41e89f42c6 |
196 |
--- /dev/null |
197 |
+++ b/dev-lang/erlang/files/erlang-21.3-lto.patch |
198 |
@@ -0,0 +1,140 @@ |
199 |
+https://github.com/erlang/otp/pull/2194 |
200 |
+https://bugs.gentoo.org/681778 |
201 |
+ |
202 |
+From ed751968d8dc4c0b58210247e94409a8a52cc501 Mon Sep 17 00:00:00 2001 |
203 |
+From: Sergei Trofimovich <slyfox@g.o> |
204 |
+Date: Thu, 28 Mar 2019 08:38:56 +0000 |
205 |
+Subject: [PATCH] stdlib: fix re:replace on LTO builds |
206 |
+ |
207 |
+Fabio Coatti reported elixir build failure in https://bugs.gentoo.org/681778. |
208 |
+The minimal reproducer looks like that (from otp git tree): |
209 |
+ |
210 |
+ $ ./configure CFLAGS='-O2 -flto' LDFLAGS='-O2 -flto=8' |
211 |
+ $ make |
212 |
+ $ ERL_TOP=$PWD \ |
213 |
+ PATH=$ERL_TOP/bin:$PATH \ |
214 |
+ \ |
215 |
+ bin/erl \ |
216 |
+ \ |
217 |
+ -noshell -eval 're:replace("a","b","c",[{return,list}]).' \ |
218 |
+ -s erlang halt |
219 |
+ |
220 |
+ {"init terminating in do_boot",{badarg,[{re,replace,["a","b","c",[{return,list}]], |
221 |
+ [{file,"re.erl"},{line,362}]}, |
222 |
+ {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,680}]}, |
223 |
+ {init,start_it,1,[]}, |
224 |
+ {init,start_em,1,[]}, |
225 |
+ {init,do_boot,3,[]}]}} |
226 |
+ init terminating in do_boot ({badarg,[{re,replace,[[_],[_],[_],[_]],[{_},{_}]}, |
227 |
+ {erl_eval,do_apply,6,[{_},{_}]},{init,start_it,1,[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}) |
228 |
+ Crash dump is being written to: erl_crash.dump...done |
229 |
+ |
230 |
+The failure happens in libpcre2 where stack overflow is mis-identified |
231 |
+at function entry of |
232 |
+ |
233 |
+ erts_pcre_compile2() |
234 |
+ compile_regex() |
235 |
+ if (PUBL(stack_guard) != NULL && PUBL(stack_guard)()) |
236 |
+ { |
237 |
+ *errorcodeptr= ERR85; |
238 |
+ return FALSE; |
239 |
+ } |
240 |
+ |
241 |
+The stack "overflow" detection happens in |
242 |
+ |
243 |
+ thr_wrapper() |
244 |
+ ethr_set_stacklimit__() |
245 |
+ |
246 |
+because the stack usage code relies on the fact that ethr_set_stacklimit__() |
247 |
+and similar functions don't get inlined into callers for stack growth |
248 |
+measurement. |
249 |
+ |
250 |
+Before the change inlining avoidance was achieved by putting functions |
251 |
+into standalone translation units. LTO makes this technique inefficient. |
252 |
+ |
253 |
+The change marks functions explicitly as __attribute__((__noinline__)) on gcc. |
254 |
+ |
255 |
+Reported-by: Fabio Coatti |
256 |
+Bug: https://bugs.gentoo.org/681778 |
257 |
+Signed-off-by: Sergei Trofimovich <slyfox@g.o> |
258 |
+--- |
259 |
+ erts/emulator/beam/global.h | 9 +++++---- |
260 |
+ erts/emulator/beam/sys.h | 10 ++++++++++ |
261 |
+ erts/include/internal/ethr_internal.h | 2 +- |
262 |
+ erts/include/internal/ethread_inline.h | 3 +++ |
263 |
+ 4 files changed, 19 insertions(+), 5 deletions(-) |
264 |
+ |
265 |
+diff --git a/erts/emulator/beam/global.h b/erts/emulator/beam/global.h |
266 |
+index f9bbe4167f9..4c8d3d3dbe6 100644 |
267 |
+--- a/erts/emulator/beam/global.h |
268 |
++++ b/erts/emulator/beam/global.h |
269 |
+@@ -1216,10 +1216,11 @@ Uint64 erts_timestamp_millis(void); |
270 |
+ |
271 |
+ Export* erts_find_function(Eterm, Eterm, unsigned int, ErtsCodeIndex); |
272 |
+ |
273 |
+-void *erts_calc_stacklimit(char *prev_c, UWord stacksize); |
274 |
+-int erts_check_below_limit(char *ptr, char *limit); |
275 |
+-int erts_check_above_limit(char *ptr, char *limit); |
276 |
+-void *erts_ptr_id(void *ptr); |
277 |
++/* ERTS_NOINLINE prevents link-time optimization across modules */ |
278 |
++void *erts_calc_stacklimit(char *prev_c, UWord stacksize) ERTS_NOINLINE; |
279 |
++int erts_check_below_limit(char *ptr, char *limit) ERTS_NOINLINE; |
280 |
++int erts_check_above_limit(char *ptr, char *limit) ERTS_NOINLINE; |
281 |
++void *erts_ptr_id(void *ptr) ERTS_NOINLINE; |
282 |
+ |
283 |
+ Eterm store_external_or_ref_in_proc_(Process *, Eterm); |
284 |
+ Eterm store_external_or_ref_(Uint **, ErlOffHeap*, Eterm); |
285 |
+diff --git a/erts/emulator/beam/sys.h b/erts/emulator/beam/sys.h |
286 |
+index a6312293cc8..24b6738e082 100644 |
287 |
+--- a/erts/emulator/beam/sys.h |
288 |
++++ b/erts/emulator/beam/sys.h |
289 |
+@@ -63,6 +63,16 @@ |
290 |
+ # endif |
291 |
+ #endif |
292 |
+ |
293 |
++#ifndef ERTS_NOINLINE |
294 |
++# if ERTS_AT_LEAST_GCC_VSN__(3,1,1) |
295 |
++# define ERTS_NOINLINE __attribute__((__noinline__)) |
296 |
++# elif defined(__WIN32__) |
297 |
++# define ERTS_NOINLINE __declspec(noinline) |
298 |
++# else |
299 |
++# define ERTS_NOINLINE |
300 |
++# endif |
301 |
++#endif |
302 |
++ |
303 |
+ #if defined(DEBUG) || defined(ERTS_ENABLE_LOCK_CHECK) |
304 |
+ # undef ERTS_CAN_INLINE |
305 |
+ # define ERTS_CAN_INLINE 0 |
306 |
+diff --git a/erts/include/internal/ethr_internal.h b/erts/include/internal/ethr_internal.h |
307 |
+index ac27ff2ed09..17ec84c52b6 100644 |
308 |
+--- a/erts/include/internal/ethr_internal.h |
309 |
++++ b/erts/include/internal/ethr_internal.h |
310 |
+@@ -90,7 +90,7 @@ int ethr_init_common__(ethr_init_data *id); |
311 |
+ int ethr_late_init_common__(ethr_late_init_data *lid); |
312 |
+ void ethr_run_exit_handlers__(void); |
313 |
+ void ethr_ts_event_destructor__(void *vtsep); |
314 |
+-void ethr_set_stacklimit__(char *prev_c, size_t stacksize); |
315 |
++void ethr_set_stacklimit__(char *prev_c, size_t stacksize) ETHR_NOINLINE; |
316 |
+ |
317 |
+ #if defined(ETHR_X86_RUNTIME_CONF__) |
318 |
+ void ethr_x86_cpuid__(int *eax, int *ebx, int *ecx, int *edx); |
319 |
+diff --git a/erts/include/internal/ethread_inline.h b/erts/include/internal/ethread_inline.h |
320 |
+index 8e6bcfc4a8c..f25ba4ae721 100644 |
321 |
+--- a/erts/include/internal/ethread_inline.h |
322 |
++++ b/erts/include/internal/ethread_inline.h |
323 |
+@@ -62,12 +62,15 @@ |
324 |
+ # define ETHR_INLINE __inline__ |
325 |
+ # if ETHR_AT_LEAST_GCC_VSN__(3, 1, 1) |
326 |
+ # define ETHR_FORCE_INLINE __inline__ __attribute__((__always_inline__)) |
327 |
++# define ETHR_NOINLINE __attribute__((__noinline__)) |
328 |
+ # else |
329 |
+ # define ETHR_FORCE_INLINE __inline__ |
330 |
++# define ETHR_NOINLINE |
331 |
+ # endif |
332 |
+ #elif defined(__WIN32__) |
333 |
+ # define ETHR_INLINE __forceinline |
334 |
+ # define ETHR_FORCE_INLINE __forceinline |
335 |
++# define ETHR_NOINLINE __declspec(noinline) |
336 |
+ #endif |
337 |
+ |
338 |
+ #endif /* #ifndef ETHREAD_INLINE_H__ */ |