Update armel patch
authorStéphane Glondu <glondu@debian.org>
Mon, 1 Jul 2024 07:51:43 +0000 (09:51 +0200)
committerStéphane Glondu <glondu@debian.org>
Mon, 1 Jul 2024 07:51:43 +0000 (09:51 +0200)
debian/patches/0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch [new file with mode: 0644]
debian/patches/0010-Detect-if-atomic-64-bit-load-from-RO-memory-works.patch [deleted file]
debian/patches/series

diff --git a/debian/patches/0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch b/debian/patches/0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch
new file mode 100644 (file)
index 0000000..07193f1
--- /dev/null
@@ -0,0 +1,41 @@
+From: =?utf-8?q?St=C3=A9phane_Glondu?= <glondu@debian.org>
+Date: Fri, 28 Jun 2024 07:53:21 +0200
+Subject: Avoid atomic 64-bit load on Debian armel
+
+Bug: https://github.com/ocaml/ocaml/issues/13234
+Forwarded: https://github.com/ocaml/ocaml/pull/13267
+---
+ otherlibs/runtime_events/runtime_events_consumer.c | 13 +++++++++++--
+ 1 file changed, 11 insertions(+), 2 deletions(-)
+
+diff --git a/otherlibs/runtime_events/runtime_events_consumer.c b/otherlibs/runtime_events/runtime_events_consumer.c
+index 9df4eb5..1771df7 100644
+--- a/otherlibs/runtime_events/runtime_events_consumer.c
++++ b/otherlibs/runtime_events/runtime_events_consumer.c
+@@ -189,7 +189,16 @@ caml_runtime_events_create_cursor(const char_os* runtime_events_path, int pid,
+   cursor->ring_file_size_bytes = GetFileSize(cursor->ring_file_handle, NULL);
+ #else
+-  ring_fd = open(runtime_events_loc, O_RDONLY, 0);
++#if defined(__ARM_ARCH) && __ARM_ARCH <= 5
++  /* Atomic 64-bit load requires RW memory on Debian armel.  See:
++     https://github.com/ocaml/ocaml/issues/13234 */
++  const int open_flags = O_RDWR;
++  const int mmap_prot = PROT_READ | PROT_WRITE;
++#else
++  const int open_flags = O_RDONLY;
++  const int mmap_prot = PROT_READ;
++#endif
++  ring_fd = open(runtime_events_loc, open_flags, 0);
+   if( ring_fd == -1 ) {
+     caml_stat_free(cursor);
+@@ -210,7 +219,7 @@ caml_runtime_events_create_cursor(const char_os* runtime_events_path, int pid,
+   /* This cast is necessary for compatibility with Illumos' non-POSIX
+     mmap/munmap */
+   cursor->metadata = (struct runtime_events_metadata_header *)
+-                      mmap(NULL, cursor->ring_file_size_bytes, PROT_READ,
++                      mmap(NULL, cursor->ring_file_size_bytes, mmap_prot,
+                           MAP_SHARED, ring_fd, 0);
+   if( cursor->metadata == MAP_FAILED ) {
diff --git a/debian/patches/0010-Detect-if-atomic-64-bit-load-from-RO-memory-works.patch b/debian/patches/0010-Detect-if-atomic-64-bit-load-from-RO-memory-works.patch
deleted file mode 100644 (file)
index 9f1d8f2..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-From: =?utf-8?q?St=C3=A9phane_Glondu?= <glondu@debian.org>
-Date: Fri, 28 Jun 2024 07:53:21 +0200
-Subject: Detect if atomic 64-bit load from RO memory works
-
-Bug: https://github.com/ocaml/ocaml/issues/13234
-Forwarded: https://github.com/ocaml/ocaml/pull/13267
----
- aclocal.m4                                         | 21 +++++++++++++++++++++
- configure.ac                                       |  5 +++++
- otherlibs/runtime_events/runtime_events_consumer.c | 11 +++++++++--
- runtime/caml/s.h.in                                |  2 ++
- 4 files changed, 37 insertions(+), 2 deletions(-)
-
-diff --git a/aclocal.m4 b/aclocal.m4
-index cb73385..6f8e119 100644
---- a/aclocal.m4
-+++ b/aclocal.m4
-@@ -573,3 +573,24 @@ AC_DEFUN([OCAML_CC_SUPPORTS_ATOMIC], [
-    AC_MSG_RESULT([no])])
-   LIBS="$saved_LIBS"
- ])
-+
-+AC_DEFUN([OCAML_ATOMIC_LOAD64_RW_CHECK], [
-+  AC_MSG_CHECKING([whether atomic 64-bit load from RO memory works])
-+  saved_LIBS="$LIBS"
-+  LIBS="$LIBS $1"
-+  OCAML_RUN_IFELSE([AC_LANG_SOURCE([[
-+    #include <stdlib.h>
-+    #include <stdint.h>
-+    #include <stdatomic.h>
-+    #include <sys/mman.h>
-+    int main() {
-+      uint64_t *a = mmap(NULL, 64, PROT_READ, MAP_ANONYMOUS | MAP_SHARED, 0, 0);
-+      uint64_t b = atomic_load_explicit(a, memory_order_acquire);
-+      return 0;
-+    }
-+    ]])],
-+  [AC_MSG_RESULT([yes])],
-+  [AC_DEFINE([ATOMIC_LOAD64_RW]) AC_MSG_RESULT([no])],
-+  [AC_MSG_RESULT([cross-compiling; assume yes])])
-+  LIBS="$saved_LIBS"
-+])
-diff --git a/configure.ac b/configure.ac
-index a8e4222..6cd9b64 100644
---- a/configure.ac
-+++ b/configure.ac
-@@ -1162,6 +1162,11 @@ OCAML_CC_SUPPORTS_ATOMIC([$cclibs])
- AS_IF([! $cc_supports_atomic],
-   [AC_MSG_FAILURE([C11 atomic support is required, use another C compiler])])
-+# Atomic 64-bit load requires RW memory on at least Debian armel
-+# See: https://github.com/ocaml/ocaml/issues/13234
-+
-+OCAML_ATOMIC_LOAD64_RW_CHECK([$cclibs])
-+
- # Full support for thread local storage
- # macOS and MinGW-w64 have problems with thread local storage accessed from DLLs
-diff --git a/otherlibs/runtime_events/runtime_events_consumer.c b/otherlibs/runtime_events/runtime_events_consumer.c
-index 9df4eb5..c3c7aca 100644
---- a/otherlibs/runtime_events/runtime_events_consumer.c
-+++ b/otherlibs/runtime_events/runtime_events_consumer.c
-@@ -189,7 +189,14 @@ caml_runtime_events_create_cursor(const char_os* runtime_events_path, int pid,
-   cursor->ring_file_size_bytes = GetFileSize(cursor->ring_file_handle, NULL);
- #else
--  ring_fd = open(runtime_events_loc, O_RDONLY, 0);
-+#ifndef ATOMIC_LOAD64_RW
-+  const int open_flags = O_RDONLY;
-+  const int mmap_prot = PROT_READ;
-+#else
-+  const int open_flags = O_RDWR;
-+  const int mmap_prot = PROT_READ | PROT_WRITE;
-+#endif
-+  ring_fd = open(runtime_events_loc, open_flags, 0);
-   if( ring_fd == -1 ) {
-     caml_stat_free(cursor);
-@@ -210,7 +217,7 @@ caml_runtime_events_create_cursor(const char_os* runtime_events_path, int pid,
-   /* This cast is necessary for compatibility with Illumos' non-POSIX
-     mmap/munmap */
-   cursor->metadata = (struct runtime_events_metadata_header *)
--                      mmap(NULL, cursor->ring_file_size_bytes, PROT_READ,
-+                      mmap(NULL, cursor->ring_file_size_bytes, mmap_prot,
-                           MAP_SHARED, ring_fd, 0);
-   if( cursor->metadata == MAP_FAILED ) {
-diff --git a/runtime/caml/s.h.in b/runtime/caml/s.h.in
-index 0dc2ed7..bf9cca0 100644
---- a/runtime/caml/s.h.in
-+++ b/runtime/caml/s.h.in
-@@ -309,3 +309,5 @@
- #undef HAS_BSD_GETAFFINITY_NP
- #undef HAS_ZSTD
-+
-+#undef ATOMIC_LOAD64_RW
index a8185c734f0974b9c15053ca3dffa87d31f591a8..441a118fe9b83d13709fca5ef2e06702ed782b21 100644 (file)
@@ -7,4 +7,4 @@
 0008-Filter-out-f-debug-file-prefix-map-from-ocamlc_cflag.patch
 0008-Fix-call-to-test-in-configure.ac.patch
 0009-Rework-fixed-register-assignments-on-m68k.patch
-0010-Detect-if-atomic-64-bit-load-from-RO-memory-works.patch
+0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch