Upstream patch for non-constant SIGSTKSZ in glibc 2.34

resolves: rhbz#1975167
This commit is contained in:
Richard W.M. Jones 2021-06-23 11:43:42 +01:00
parent dbbef17439
commit 3237fd89d4
7 changed files with 120 additions and 11 deletions

View File

@ -1,7 +1,7 @@
From 4c7732daae8f0d2a622f91f5ff3add5c2248a2e3 Mon Sep 17 00:00:00 2001 From 4c7732daae8f0d2a622f91f5ff3add5c2248a2e3 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 24 Jun 2014 10:00:15 +0100 Date: Tue, 24 Jun 2014 10:00:15 +0100
Subject: [PATCH 1/5] Don't add rpaths to libraries. Subject: [PATCH 1/6] Don't add rpaths to libraries.
--- ---
tools/Makefile | 4 ++-- tools/Makefile | 4 ++--
@ -23,5 +23,5 @@ index dbad0b74f..c920a5337 100644
> ocamlmklibconfig.ml > ocamlmklibconfig.ml
-- --
2.28.0.rc2 2.32.0

View File

@ -1,7 +1,7 @@
From 441ad77a0c89f4abdf104c668d579607f338a052 Mon Sep 17 00:00:00 2001 From 441ad77a0c89f4abdf104c668d579607f338a052 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 29 May 2012 20:44:18 +0100 Date: Tue, 29 May 2012 20:44:18 +0100
Subject: [PATCH 2/5] configure: Allow user defined C compiler flags. Subject: [PATCH 2/6] configure: Allow user defined C compiler flags.
--- ---
configure.ac | 4 ++++ configure.ac | 4 ++++
@ -23,5 +23,5 @@ index aa5f26f28..5153853b7 100644
# Enable SSE2 on x86 mingw to avoid using 80-bit registers. # Enable SSE2 on x86 mingw to avoid using 80-bit registers.
-- --
2.28.0.rc2 2.32.0

View File

@ -1,7 +1,7 @@
From 3318c5b805d8d6ae1d571f18f682c9f701b712e2 Mon Sep 17 00:00:00 2001 From 3318c5b805d8d6ae1d571f18f682c9f701b712e2 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 26 Apr 2019 16:16:29 +0100 Date: Fri, 26 Apr 2019 16:16:29 +0100
Subject: [PATCH 3/5] configure: Remove incorrect assumption about Subject: [PATCH 3/6] configure: Remove incorrect assumption about
cross-compiling. cross-compiling.
See https://github.com/ocaml/ocaml/issues/8647#issuecomment-487094390 See https://github.com/ocaml/ocaml/issues/8647#issuecomment-487094390
@ -39,5 +39,5 @@ index 5153853b7..4e97474a2 100644
# We first compute default values for as and aspp # We first compute default values for as and aspp
# If values have been given by the user then they take precedence over # If values have been given by the user then they take precedence over
-- --
2.28.0.rc2 2.32.0

View File

@ -1,7 +1,7 @@
From 01d8e3f82adb382fb90af15879f722e824834c84 Mon Sep 17 00:00:00 2001 From 01d8e3f82adb382fb90af15879f722e824834c84 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 18 Jan 2020 11:31:27 +0000 Date: Sat, 18 Jan 2020 11:31:27 +0000
Subject: [PATCH 4/5] Remove configure from .gitattributes. Subject: [PATCH 4/6] Remove configure from .gitattributes.
It's not a binary file. It's not a binary file.
--- ---
@ -24,5 +24,5 @@ index 200eb49c6..d871764de 100644
# http://krlmlr.github.io/using-gitattributes-to-avoid-merge-conflicts/ # http://krlmlr.github.io/using-gitattributes-to-avoid-merge-conflicts/
/.mailmap merge=union /.mailmap merge=union
-- --
2.28.0.rc2 2.32.0

View File

@ -1,7 +1,7 @@
From 122db7141d292d63cfbe2c7d7a4280cc73194ece Mon Sep 17 00:00:00 2001 From 122db7141d292d63cfbe2c7d7a4280cc73194ece Mon Sep 17 00:00:00 2001
From: Xavier Leroy <xavierleroy@users.noreply.github.com> From: Xavier Leroy <xavierleroy@users.noreply.github.com>
Date: Wed, 5 Aug 2020 11:17:52 +0200 Date: Wed, 5 Aug 2020 11:17:52 +0200
Subject: [PATCH 5/5] Fix type mismatches between definition and declaration Subject: [PATCH 5/6] Fix type mismatches between definition and declaration
(#9830) (#9830)
The C global variable caml_fl_merge and the C function The C global variable caml_fl_merge and the C function
@ -65,5 +65,5 @@ index 2b0bf1dc2..b75fb0980 100644
return 0; return 0;
} }
-- --
2.28.0.rc2 2.32.0

View File

@ -0,0 +1,103 @@
From 24a9db7784ddfcf0af2d2be2f51616ed960ae7e8 Mon Sep 17 00:00:00 2001
From: Xavier Leroy <xavierleroy@users.noreply.github.com>
Date: Fri, 5 Mar 2021 19:14:07 +0100
Subject: [PATCH 6/6] Dynamically allocate the alternate signal stack (#10266)
In Glibc 2.34 and later, SIGSTKSZ may not be a compile-time constant.
It is no longer possible to statically allocate the alternate signal
stack for the main thread, as we've been doing for the last 25 years.
This commit implements dynamic allocation of the alternate signal stack
even for the main thread. It reuses the code already in place to allocate
the alternate signal stack for other threads.
Fixes: #10250.
(cherry picked from commit fc9534746bf5d08a4c109f22e344cf49d5d46d54)
---
runtime/caml/signals.h | 2 +-
runtime/signals_byt.c | 2 +-
runtime/signals_nat.c | 25 ++++++++++++++-----------
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/runtime/caml/signals.h b/runtime/caml/signals.h
index 7ec1ad3ba..98b75107b 100644
--- a/runtime/caml/signals.h
+++ b/runtime/caml/signals.h
@@ -82,7 +82,7 @@ void caml_set_action_pending (void);
value caml_do_pending_actions_exn (void);
value caml_process_pending_actions_with_root (value extra_root); // raises
int caml_set_signal_action(int signo, int action);
-void caml_setup_stack_overflow_detection(void);
+CAMLextern int caml_setup_stack_overflow_detection(void);
CAMLextern void (*caml_enter_blocking_section_hook)(void);
CAMLextern void (*caml_leave_blocking_section_hook)(void);
diff --git a/runtime/signals_byt.c b/runtime/signals_byt.c
index 040de03c5..9bd2b20c6 100644
--- a/runtime/signals_byt.c
+++ b/runtime/signals_byt.c
@@ -86,4 +86,4 @@ int caml_set_signal_action(int signo, int action)
return 0;
}
-void caml_setup_stack_overflow_detection(void) {}
+CAMLexport int caml_setup_stack_overflow_detection(void) { return 0; }
diff --git a/runtime/signals_nat.c b/runtime/signals_nat.c
index fc5a77f84..f56fce6b7 100644
--- a/runtime/signals_nat.c
+++ b/runtime/signals_nat.c
@@ -195,8 +195,6 @@ DECLARE_SIGNAL_HANDLER(trap_handler)
#error "CONTEXT_SP is required if HAS_STACK_OVERFLOW_DETECTION is defined"
#endif
-static char sig_alt_stack[SIGSTKSZ];
-
/* Code compiled with ocamlopt never accesses more than
EXTRA_STACK bytes below the stack pointer. */
#define EXTRA_STACK 256
@@ -282,28 +280,33 @@ void caml_init_signals(void)
#endif
#ifdef HAS_STACK_OVERFLOW_DETECTION
- {
- stack_t stk;
+ if (caml_setup_stack_overflow_detection() != -1) {
struct sigaction act;
- stk.ss_sp = sig_alt_stack;
- stk.ss_size = SIGSTKSZ;
- stk.ss_flags = 0;
SET_SIGACT(act, segv_handler);
act.sa_flags |= SA_ONSTACK | SA_NODEFER;
sigemptyset(&act.sa_mask);
- if (sigaltstack(&stk, NULL) == 0) { sigaction(SIGSEGV, &act, NULL); }
+ sigaction(SIGSEGV, &act, NULL);
}
#endif
}
-void caml_setup_stack_overflow_detection(void)
+/* Allocate and select an alternate stack for handling signals,
+ especially SIGSEGV signals.
+ Each thread needs its own alternate stack.
+ The alternate stack used to be statically-allocated for the main thread,
+ but this is incompatible with Glibc 2.34 and newer, where SIGSTKSZ
+ may not be a compile-time constant (issue #10250). */
+
+CAMLexport int caml_setup_stack_overflow_detection(void)
{
#ifdef HAS_STACK_OVERFLOW_DETECTION
stack_t stk;
stk.ss_sp = malloc(SIGSTKSZ);
+ if (stk.ss_sp == NULL) return -1;
stk.ss_size = SIGSTKSZ;
stk.ss_flags = 0;
- if (stk.ss_sp)
- sigaltstack(&stk, NULL);
+ return sigaltstack(&stk, NULL);
+#else
+ return 0;
#endif
}
--
2.32.0

View File

@ -31,7 +31,7 @@
Name: ocaml Name: ocaml
Version: 4.11.1 Version: 4.11.1
Release: 3%{?dist} Release: 3%{?dist}.1
Summary: OCaml compiler and programming environment Summary: OCaml compiler and programming environment
@ -65,6 +65,9 @@ Patch0004: 0004-Remove-configure-from-.gitattributes.patch
# Fix compilation with LTO (upstream, but not in 4.11 branch). # Fix compilation with LTO (upstream, but not in 4.11 branch).
Patch0005: 0005-Fix-type-mismatches-between-definition-and-declarati.patch Patch0005: 0005-Fix-type-mismatches-between-definition-and-declarati.patch
# Upstream patch for non-constant SIGSTKSZ in glibc 2.34
Patch0006: 0006-Dynamically-allocate-the-alternate-signal-stack-1026.patch
BuildRequires: make BuildRequires: make
BuildRequires: git BuildRequires: git
BuildRequires: gcc BuildRequires: gcc
@ -375,6 +378,9 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/ocaml/eventlog_metadata
%changelog %changelog
* Wed Jun 23 2021 Richard W.M. Jones <rjones@redhat.com> - 4.11.1-3.el9.1
- Upstream patch for non-constant SIGSTKSZ in glibc 2.34
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 4.11.1-3 * Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 4.11.1-3
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937 - Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937