From 25c51f118b107c1e6d456d13ce12754984993ec8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Glondu?= Date: Mon, 1 Jul 2024 09:51:43 +0200 Subject: [PATCH] Update armel patch --- ...d-atomic-64-bit-load-on-Debian-armel.patch | 41 ++++++++ ...mic-64-bit-load-from-RO-memory-works.patch | 97 ------------------- debian/patches/series | 2 +- 3 files changed, 42 insertions(+), 98 deletions(-) create mode 100644 debian/patches/0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch delete mode 100644 debian/patches/0010-Detect-if-atomic-64-bit-load-from-RO-memory-works.patch 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 index 00000000..07193f17 --- /dev/null +++ b/debian/patches/0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch @@ -0,0 +1,41 @@ +From: =?utf-8?q?St=C3=A9phane_Glondu?= +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 index 9f1d8f2c..00000000 --- a/debian/patches/0010-Detect-if-atomic-64-bit-load-from-RO-memory-works.patch +++ /dev/null @@ -1,97 +0,0 @@ -From: =?utf-8?q?St=C3=A9phane_Glondu?= -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 -+ #include -+ #include -+ #include -+ 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 diff --git a/debian/patches/series b/debian/patches/series index a8185c73..441a118f 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -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 -- 2.30.2