From c9597d78ebbc7813987d5c9dc48b7907a9c2617b Mon Sep 17 00:00:00 2001 From: Jakub Bogusz Date: Sat, 28 Aug 2021 10:26:27 +0200 Subject: [PATCH] - added 10266 patch (https://github.com/ocaml/ocaml/pull/10266) to fix build with glibc 2.34 --- ocaml-10266.patch | 148 ++++++++++++++++++++++++++++++++++++++++++++++ ocaml.spec | 7 ++- 2 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 ocaml-10266.patch diff --git a/ocaml-10266.patch b/ocaml-10266.patch new file mode 100644 index 0000000..0f29b1a --- /dev/null +++ b/ocaml-10266.patch @@ -0,0 +1,148 @@ +From 632563b19ca72ec0ae10c7ed767a025c342d3155 Mon Sep 17 00:00:00 2001 +From: Xavier Leroy +Date: Tue, 2 Mar 2021 19:06:56 +0100 +Subject: [PATCH 1/3] Dynamically allocate the alternate signal stack + +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. +--- + 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 3ff152c2693..285dbd7febd 100644 +--- a/runtime/caml/signals.h ++++ b/runtime/caml/signals.h +@@ -87,7 +87,7 @@ value caml_do_pending_actions_exn (void); + value caml_process_pending_actions_with_root (value extra_root); // raises + value caml_process_pending_actions_with_root_exn (value extra_root); + int caml_set_signal_action(int signo, int action); +-CAMLextern 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 2183142da18..38eb5e3a47a 100644 +--- a/runtime/signals_byt.c ++++ b/runtime/signals_byt.c +@@ -81,4 +81,4 @@ int caml_set_signal_action(int signo, int action) + return 0; + } + +-CAMLexport 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 1be1b45d420..47b3e29af70 100644 +--- a/runtime/signals_nat.c ++++ b/runtime/signals_nat.c +@@ -174,8 +174,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 +@@ -269,28 +267,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 + } + +-CAMLexport 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 never, 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 + } + +From 9f5b312d457490032e21d54baa85774e78dcd6c9 Mon Sep 17 00:00:00 2001 +From: Xavier Leroy +Date: Wed, 3 Mar 2021 17:57:25 +0100 +Subject: [PATCH 2/3] Typo in comment + +--- + runtime/signals_nat.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/runtime/signals_nat.c b/runtime/signals_nat.c +index 47b3e29af70..ca86956783c 100644 +--- a/runtime/signals_nat.c ++++ b/runtime/signals_nat.c +@@ -281,7 +281,7 @@ void caml_init_signals(void) + 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 never, where SIGSTKSZ ++ 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) + +From 1a6cc6022e35b5a5e8e3b97586e78b39d78df51a Mon Sep 17 00:00:00 2001 +From: Xavier Leroy +Date: Fri, 5 Mar 2021 19:10:11 +0100 +Subject: [PATCH 3/3] Update Changes + +--- + Changes | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/Changes b/Changes +index 1bb07e81d09..9c73ad02e32 100644 +--- a/Changes ++++ b/Changes +@@ -69,6 +69,11 @@ Working version + to the debugger via a socket. + (Antonin Décimo, review by Xavier Leroy) + ++- #10250, #10266: Dynamically allocate alternate signal stacks to ++ accommodate changes in Glibc 2.34. ++ (Xavier Leroy, reports by Tomasz Kłoczko and R.W.M. Jones, review by Anil ++ Madhavapeddy, Stephen Dolan, and Florian Angeletti) ++ + ### Code generation and optimizations: + + - #9876: do not cache the young_limit GC variable in a processor register. diff --git a/ocaml.spec b/ocaml.spec index f3dee63..f6b8865 100644 --- a/ocaml.spec +++ b/ocaml.spec @@ -29,6 +29,7 @@ Source4: https://github.com/mmottl/pure-fun/archive/v1.0.13/pure-fun-1.0.13.tar. # note: dead URL Source5: http://www.ocaml.info/ocaml_sources/ds-contrib.tar.gz # Source5-md5: 77fa1da7375dea1393cc0b6cd802d7e1 +Patch0: %{name}-10266.patch URL: https://www.ocaml.org/ Requires: %{name}-runtime = %{epoch}:%{version}-%{release} Provides: ocaml-bytes-devel @@ -164,12 +165,14 @@ Okasaki'ego, napisane w OCamlu, wraz z dodatkami. %prep %setup -q -a1 -a3 +%patch0 -p1 + mkdir examples tar xzf %{SOURCE4} -C examples tar xzf %{SOURCE5} -C examples # order mess with docs somewhat mkdir -p docs/html -mv htmlman docs/html/ocaml +%{__mv} htmlman docs/html/ocaml %build %configure \ @@ -216,7 +219,7 @@ ln -sf %{_libdir}/%{name}/{scrape,add}labels $RPM_BUILD_ROOT%{_bindir} %{__rm} -r $RPM_BUILD_ROOT%{_mandir}/man3 # install info pages -cp -f infoman/*.gz $RPM_BUILD_ROOT%{_infodir} +cp -p infoman/ocaml.info{,.body-*}.gz $RPM_BUILD_ROOT%{_infodir} %clean rm -rf $RPM_BUILD_ROOT -- 2.43.0