Subject: [alpine-aports] [PATCH] main/xfsprogs: fix build on mips* and ppc64le

From: alpine-mips-patches <[email-masked]>
Date: Fri, 17 Nov 2018 20:29:33 +0000

musl-1.1.20 implements support (or lack thereof) for the MAP_SYNC flag by #define'ing
it uncoditionally in generic <sys/mman.h> then #undef'ining optionally in arch-specific
<bits/mman.h> (e.g. for mips* and powerpc*). So io/mmap.c fails to compile since it
includes <sys/mman.h> (which undefines MAP_SYNC on mips* and powerpc*) after "linux.h"
(which either defines fallback MAP_SYNC values or pulls <asm-generic/mman{-common.h}>).

The proposes patch also fixes the flawed MAP_SYNC detection logic in the configure script
because io/mmap.c always uses the MAP_SYNC definition (either real one or zero fallback).
Otherwise xfsprogs wrongly detects the MAP_SYNC presence on mips* and ppc64le and the code
does not define MAP_SYNC fallback so io/mmap.c still fails to compile.

Note the last (2018-07-11) successful xfsprogs build for ppc64le was against musl-1.1.19
(without any support for MAP_SYNC).

The problem with MAP_SYNC detection is as follows. The configure script checks only
<asm-generic/mman{-common}.h> headers for the MAP_SYNC definition instead of using
the arch-specific <asm/mman.h>. But some architectures (mips, powerpc, parisc) do not
support the MAP_SYNC feature at all, do not use the <asm-generic/mman{-common.h}> files
and do not define the flag in the corresponding <asm/mman.h> header.
---
 main/xfsprogs/APKBUILD                |  6 ++-
 main/xfsprogs/musl-MAP_SYNC-fix.patch | 53 +++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 main/xfsprogs/musl-MAP_SYNC-fix.patch

diff --git a/main/xfsprogs/APKBUILD b/main/xfsprogs/APKBUILD
index 38bc7ac206..32654423d6 100644
--- a/main/xfsprogs/APKBUILD
+++ b/main/xfsprogs/APKBUILD
@@ -2,7 +2,7 @@
 # Maintainer: Natanael Copa <[email-masked]>
 pkgname=xfsprogs
 pkgver=4.17.0
-pkgrel=1
+pkgrel=2
 pkgdesc="XFS filesystem utilities"
 url="http://xfs.org/index.php/Main_Page"
 arch="all"
@@ -11,6 +11,7 @@ makedepends="linux-headers util-linux-dev bash gzip python3"
 options="!check"  # no test suite
 subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-extra"
 source="https://www.kernel.org/pub/linux/utils/fs/xfs/$pkgname/$pkgname-$pkgver.tar.gz
+	musl-MAP_SYNC-fix.patch
 	"
 
 builddir="$srcdir/$pkgname-$pkgver"
@@ -49,4 +50,5 @@ extra() {
 	mv "$pkgdir"/usr "$subpkgdir"/
 }
 
-sha512sums="19bdb9b1698b07d42c52976c17ac8dc95170e59bbd7d74e3d6faadd36cba88ed36a8b0c309052cab01ecb3a14e564b42ea982380b76922401be516d463476548  xfsprogs-4.17.0.tar.gz"
+sha512sums="19bdb9b1698b07d42c52976c17ac8dc95170e59bbd7d74e3d6faadd36cba88ed36a8b0c309052cab01ecb3a14e564b42ea982380b76922401be516d463476548  xfsprogs-4.17.0.tar.gz
+bc7971207a296d8112f8993f6a266533135aae59a4438bb511f472931c37b8ce3033c597d67abbd3664f4405317aeb049e747c1811c9495c1a24d98935f799cc  musl-MAP_SYNC-fix.patch"
diff --git a/main/xfsprogs/musl-MAP_SYNC-fix.patch b/main/xfsprogs/musl-MAP_SYNC-fix.patch
new file mode 100644
index 0000000000..09e41ca26f
--- /dev/null
+++ b/main/xfsprogs/musl-MAP_SYNC-fix.patch
@@ -0,0 +1,53 @@
+--- a/configure
++++ b/configure
+@@ -14507,8 +14507,7 @@
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h.  */
+ 
+-#include <asm-generic/mman.h>
+-#include <asm-generic/mman-common.h>
++#include <asm/mman.h>
+ 
+ int
+ main ()
+--- a/include/linux.h
++++ b/include/linux.h
+@@ -327,12 +327,4 @@
+ #define HAVE_GETFSMAP
+ #endif /* HAVE_GETFSMAP */
+ 
+-#ifndef HAVE_MAP_SYNC
+-#define MAP_SYNC 0
+-#define MAP_SHARED_VALIDATE 0
+-#else
+-#include <asm-generic/mman.h>
+-#include <asm-generic/mman-common.h>
+-#endif /* HAVE_MAP_SYNC */
+-
+ #endif	/* __XFS_LINUX_H__ */
+--- a/io/mmap.c
++++ b/io/mmap.c
+@@ -23,6 +23,11 @@
+ #include "init.h"
+ #include "io.h"
+ 
++#ifndef HAVE_MAP_SYNC
++#define MAP_SYNC 0
++#define MAP_SHARED_VALIDATE 0
++#endif
++
+ static cmdinfo_t mmap_cmd;
+ static cmdinfo_t mread_cmd;
+ static cmdinfo_t msync_cmd;
+--- a/m4/package_libcdev.m4
++++ b/m4/package_libcdev.m4
+@@ -335,8 +335,7 @@
+ AC_DEFUN([AC_HAVE_MAP_SYNC],
+   [ AC_MSG_CHECKING([for MAP_SYNC])
+     AC_TRY_COMPILE([
+-#include <asm-generic/mman.h>
+-#include <asm-generic/mman-common.h>
++#include <asm/mman.h>
+     ], [
+         int flags = MAP_SYNC | MAP_SHARED_VALIDATE;
+     ], have_map_sync=yes
-- 
2.19.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---