Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-lang/ocaml/, dev-lang/ocaml/files/
Date: Sat, 09 Oct 2021 05:56:09
Message-Id: 1633758951.474a14bc9ede109fb7a8033667f42b6f63720962.sam@gentoo
1 commit: 474a14bc9ede109fb7a8033667f42b6f63720962
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Sat Oct 9 05:54:21 2021 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sat Oct 9 05:55:51 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=474a14bc
7
8 dev-lang/ocaml: fix build with glibc 2.34
9
10 Closes: https://bugs.gentoo.org/816765
11 Signed-off-by: Sam James <sam <AT> gentoo.org>
12
13 dev-lang/ocaml/files/ocaml-4.12.0-glibc-2.34.patch | 91 ++++++++++++++++++++++
14 dev-lang/ocaml/ocaml-4.12.0-r2.ebuild | 4 +
15 dev-lang/ocaml/ocaml-4.12.1.ebuild | 4 +
16 3 files changed, 99 insertions(+)
17
18 diff --git a/dev-lang/ocaml/files/ocaml-4.12.0-glibc-2.34.patch b/dev-lang/ocaml/files/ocaml-4.12.0-glibc-2.34.patch
19 new file mode 100644
20 index 00000000000..486b44846a8
21 --- /dev/null
22 +++ b/dev-lang/ocaml/files/ocaml-4.12.0-glibc-2.34.patch
23 @@ -0,0 +1,91 @@
24 +https://src.fedoraproject.org/rpms/ocaml/blob/129153b85109944bf0b2922949f77ef8f32b39a1/f/0004-Dynamically-allocate-the-alternate-signal-stack-1026.patch
25 +https://bugs.gentoo.org/816765
26 +
27 +From 3104d92743614f8f52039e0520116af4179880a5 Mon Sep 17 00:00:00 2001
28 +From: Xavier Leroy <xavierleroy@××××××××××××××××××××.com>
29 +Date: Fri, 5 Mar 2021 19:14:07 +0100
30 +Subject: [PATCH 4/4] Dynamically allocate the alternate signal stack (#10266)
31 +
32 +In Glibc 2.34 and later, SIGSTKSZ may not be a compile-time constant.
33 +It is no longer possible to statically allocate the alternate signal
34 +stack for the main thread, as we've been doing for the last 25 years.
35 +
36 +This commit implements dynamic allocation of the alternate signal stack
37 +even for the main thread. It reuses the code already in place to allocate
38 +the alternate signal stack for other threads.
39 +
40 +Fixes: #10250.
41 +(cherry picked from commit fc9534746bf5d08a4c109f22e344cf49d5d46d54)
42 +--- a/runtime/caml/signals.h
43 ++++ b/runtime/caml/signals.h
44 +@@ -87,7 +87,7 @@ value caml_do_pending_actions_exn (void);
45 + value caml_process_pending_actions_with_root (value extra_root); // raises
46 + value caml_process_pending_actions_with_root_exn (value extra_root);
47 + int caml_set_signal_action(int signo, int action);
48 +-CAMLextern void caml_setup_stack_overflow_detection(void);
49 ++CAMLextern int caml_setup_stack_overflow_detection(void);
50 +
51 + CAMLextern void (*caml_enter_blocking_section_hook)(void);
52 + CAMLextern void (*caml_leave_blocking_section_hook)(void);
53 +--- a/runtime/signals_byt.c
54 ++++ b/runtime/signals_byt.c
55 +@@ -81,4 +81,4 @@ int caml_set_signal_action(int signo, int action)
56 + return 0;
57 + }
58 +
59 +-CAMLexport void caml_setup_stack_overflow_detection(void) {}
60 ++CAMLexport int caml_setup_stack_overflow_detection(void) { return 0; }
61 +--- a/runtime/signals_nat.c
62 ++++ b/runtime/signals_nat.c
63 +@@ -181,8 +181,6 @@ DECLARE_SIGNAL_HANDLER(trap_handler)
64 + #error "CONTEXT_SP is required if HAS_STACK_OVERFLOW_DETECTION is defined"
65 + #endif
66 +
67 +-static char sig_alt_stack[SIGSTKSZ];
68 +-
69 + /* Code compiled with ocamlopt never accesses more than
70 + EXTRA_STACK bytes below the stack pointer. */
71 + #define EXTRA_STACK 256
72 +@@ -276,28 +274,33 @@ void caml_init_signals(void)
73 + #endif
74 +
75 + #ifdef HAS_STACK_OVERFLOW_DETECTION
76 +- {
77 +- stack_t stk;
78 ++ if (caml_setup_stack_overflow_detection() != -1) {
79 + struct sigaction act;
80 +- stk.ss_sp = sig_alt_stack;
81 +- stk.ss_size = SIGSTKSZ;
82 +- stk.ss_flags = 0;
83 + SET_SIGACT(act, segv_handler);
84 + act.sa_flags |= SA_ONSTACK | SA_NODEFER;
85 + sigemptyset(&act.sa_mask);
86 +- if (sigaltstack(&stk, NULL) == 0) { sigaction(SIGSEGV, &act, NULL); }
87 ++ sigaction(SIGSEGV, &act, NULL);
88 + }
89 + #endif
90 + }
91 +
92 +-CAMLexport void caml_setup_stack_overflow_detection(void)
93 ++/* Allocate and select an alternate stack for handling signals,
94 ++ especially SIGSEGV signals.
95 ++ Each thread needs its own alternate stack.
96 ++ The alternate stack used to be statically-allocated for the main thread,
97 ++ but this is incompatible with Glibc 2.34 and newer, where SIGSTKSZ
98 ++ may not be a compile-time constant (issue #10250). */
99 ++
100 ++CAMLexport int caml_setup_stack_overflow_detection(void)
101 + {
102 + #ifdef HAS_STACK_OVERFLOW_DETECTION
103 + stack_t stk;
104 + stk.ss_sp = malloc(SIGSTKSZ);
105 ++ if (stk.ss_sp == NULL) return -1;
106 + stk.ss_size = SIGSTKSZ;
107 + stk.ss_flags = 0;
108 +- if (stk.ss_sp)
109 +- sigaltstack(&stk, NULL);
110 ++ return sigaltstack(&stk, NULL);
111 ++#else
112 ++ return 0;
113 + #endif
114 + }
115
116 diff --git a/dev-lang/ocaml/ocaml-4.12.0-r2.ebuild b/dev-lang/ocaml/ocaml-4.12.0-r2.ebuild
117 index da99522c6e3..287a7f38e79 100644
118 --- a/dev-lang/ocaml/ocaml-4.12.0-r2.ebuild
119 +++ b/dev-lang/ocaml/ocaml-4.12.0-r2.ebuild
120 @@ -20,6 +20,10 @@ BDEPEND="${RDEPEND}
121 PDEPEND="emacs? ( app-emacs/ocaml-mode )
122 xemacs? ( app-xemacs/ocaml )"
123
124 +PATCHES=(
125 + "${FILESDIR}"/${PN}-4.12.0-glibc-2.34.patch
126 +)
127 +
128 src_prepare() {
129 default
130
131
132 diff --git a/dev-lang/ocaml/ocaml-4.12.1.ebuild b/dev-lang/ocaml/ocaml-4.12.1.ebuild
133 index da99522c6e3..287a7f38e79 100644
134 --- a/dev-lang/ocaml/ocaml-4.12.1.ebuild
135 +++ b/dev-lang/ocaml/ocaml-4.12.1.ebuild
136 @@ -20,6 +20,10 @@ BDEPEND="${RDEPEND}
137 PDEPEND="emacs? ( app-emacs/ocaml-mode )
138 xemacs? ( app-xemacs/ocaml )"
139
140 +PATCHES=(
141 + "${FILESDIR}"/${PN}-4.12.0-glibc-2.34.patch
142 +)
143 +
144 src_prepare() {
145 default