]> git.pld-linux.org Git - packages/ocaml.git/blob - ocaml-10266.patch
- added 10266 patch (https://github.com/ocaml/ocaml/pull/10266) to fix build with...
[packages/ocaml.git] / ocaml-10266.patch
1 From 632563b19ca72ec0ae10c7ed767a025c342d3155 Mon Sep 17 00:00:00 2001
2 From: Xavier Leroy <xavier.leroy@college-de-france.fr>
3 Date: Tue, 2 Mar 2021 19:06:56 +0100
4 Subject: [PATCH 1/3] Dynamically allocate the alternate signal stack
5
6 In Glibc 2.34 and later, SIGSTKSZ may not be a compile-time constant.
7 It is no longer possible to statically allocate the alternate signal
8 stack for the main thread, as we've been doing for the last 25 years.
9
10 This commit implements dynamic allocation of the alternate signal stack
11 even for the main thread.  It reuses the code already in place to allocate
12 the alternate signal stack for other threads.
13
14 Fixes: #10250.
15 ---
16  runtime/caml/signals.h |  2 +-
17  runtime/signals_byt.c  |  2 +-
18  runtime/signals_nat.c  | 25 ++++++++++++++-----------
19  3 files changed, 16 insertions(+), 13 deletions(-)
20
21 diff --git a/runtime/caml/signals.h b/runtime/caml/signals.h
22 index 3ff152c2693..285dbd7febd 100644
23 --- a/runtime/caml/signals.h
24 +++ b/runtime/caml/signals.h
25 @@ -87,7 +87,7 @@ value caml_do_pending_actions_exn (void);
26  value caml_process_pending_actions_with_root (value extra_root); // raises
27  value caml_process_pending_actions_with_root_exn (value extra_root);
28  int caml_set_signal_action(int signo, int action);
29 -CAMLextern void caml_setup_stack_overflow_detection(void);
30 +CAMLextern int caml_setup_stack_overflow_detection(void);
31  
32  CAMLextern void (*caml_enter_blocking_section_hook)(void);
33  CAMLextern void (*caml_leave_blocking_section_hook)(void);
34 diff --git a/runtime/signals_byt.c b/runtime/signals_byt.c
35 index 2183142da18..38eb5e3a47a 100644
36 --- a/runtime/signals_byt.c
37 +++ b/runtime/signals_byt.c
38 @@ -81,4 +81,4 @@ int caml_set_signal_action(int signo, int action)
39      return 0;
40  }
41  
42 -CAMLexport void caml_setup_stack_overflow_detection(void) {}
43 +CAMLexport int caml_setup_stack_overflow_detection(void) { return 0; }
44 diff --git a/runtime/signals_nat.c b/runtime/signals_nat.c
45 index 1be1b45d420..47b3e29af70 100644
46 --- a/runtime/signals_nat.c
47 +++ b/runtime/signals_nat.c
48 @@ -174,8 +174,6 @@ DECLARE_SIGNAL_HANDLER(trap_handler)
49  #error "CONTEXT_SP is required if HAS_STACK_OVERFLOW_DETECTION is defined"
50  #endif
51  
52 -static char sig_alt_stack[SIGSTKSZ];
53 -
54  /* Code compiled with ocamlopt never accesses more than
55     EXTRA_STACK bytes below the stack pointer. */
56  #define EXTRA_STACK 256
57 @@ -269,28 +267,33 @@ void caml_init_signals(void)
58  #endif
59  
60  #ifdef HAS_STACK_OVERFLOW_DETECTION
61 -  {
62 -    stack_t stk;
63 +  if (caml_setup_stack_overflow_detection() != -1) {
64      struct sigaction act;
65 -    stk.ss_sp = sig_alt_stack;
66 -    stk.ss_size = SIGSTKSZ;
67 -    stk.ss_flags = 0;
68      SET_SIGACT(act, segv_handler);
69      act.sa_flags |= SA_ONSTACK | SA_NODEFER;
70      sigemptyset(&act.sa_mask);
71 -    if (sigaltstack(&stk, NULL) == 0) { sigaction(SIGSEGV, &act, NULL); }
72 +    sigaction(SIGSEGV, &act, NULL);
73    }
74  #endif
75  }
76  
77 -CAMLexport void caml_setup_stack_overflow_detection(void)
78 +/* Allocate and select an alternate stack for handling signals,
79 +   especially SIGSEGV signals.
80 +   Each thread needs its own alternate stack.
81 +   The alternate stack used to be statically-allocated for the main thread,
82 +   but this is incompatible with Glibc 2.34 and never, where SIGSTKSZ
83 +   may not be a compile-time constant (issue #10250). */
84 +
85 +CAMLexport int caml_setup_stack_overflow_detection(void)
86  {
87  #ifdef HAS_STACK_OVERFLOW_DETECTION
88    stack_t stk;
89    stk.ss_sp = malloc(SIGSTKSZ);
90 +  if (stk.ss_sp == NULL) return -1;
91    stk.ss_size = SIGSTKSZ;
92    stk.ss_flags = 0;
93 -  if (stk.ss_sp)
94 -    sigaltstack(&stk, NULL);
95 +  return sigaltstack(&stk, NULL);
96 +#else
97 +  return 0;
98  #endif
99  }
100
101 From 9f5b312d457490032e21d54baa85774e78dcd6c9 Mon Sep 17 00:00:00 2001
102 From: Xavier Leroy <xavier.leroy@college-de-france.fr>
103 Date: Wed, 3 Mar 2021 17:57:25 +0100
104 Subject: [PATCH 2/3] Typo in comment
105
106 ---
107  runtime/signals_nat.c | 2 +-
108  1 file changed, 1 insertion(+), 1 deletion(-)
109
110 diff --git a/runtime/signals_nat.c b/runtime/signals_nat.c
111 index 47b3e29af70..ca86956783c 100644
112 --- a/runtime/signals_nat.c
113 +++ b/runtime/signals_nat.c
114 @@ -281,7 +281,7 @@ void caml_init_signals(void)
115     especially SIGSEGV signals.
116     Each thread needs its own alternate stack.
117     The alternate stack used to be statically-allocated for the main thread,
118 -   but this is incompatible with Glibc 2.34 and never, where SIGSTKSZ
119 +   but this is incompatible with Glibc 2.34 and newer, where SIGSTKSZ
120     may not be a compile-time constant (issue #10250). */
121  
122  CAMLexport int caml_setup_stack_overflow_detection(void)
123
124 From 1a6cc6022e35b5a5e8e3b97586e78b39d78df51a Mon Sep 17 00:00:00 2001
125 From: Xavier Leroy <xavier.leroy@college-de-france.fr>
126 Date: Fri, 5 Mar 2021 19:10:11 +0100
127 Subject: [PATCH 3/3] Update Changes
128
129 ---
130  Changes | 5 +++++
131  1 file changed, 5 insertions(+)
132
133 diff --git a/Changes b/Changes
134 index 1bb07e81d09..9c73ad02e32 100644
135 --- a/Changes
136 +++ b/Changes
137 @@ -69,6 +69,11 @@ Working version
138    to the debugger via a socket.
139    (Antonin Décimo, review by Xavier Leroy)
140  
141 +- #10250, #10266: Dynamically allocate alternate signal stacks to
142 +   accommodate changes in Glibc 2.34.
143 +  (Xavier Leroy, reports by Tomasz Kłoczko and R.W.M. Jones, review by Anil
144 +   Madhavapeddy, Stephen Dolan, and Florian Angeletti)
145 +
146  ### Code generation and optimizations:
147  
148  - #9876: do not cache the young_limit GC variable in a processor register.
This page took 0.0479349999999999 seconds and 4 git commands to generate.