Răsfoiți Sursa

package/lvm2: enable package with musl

LVM relies on the glibc-specific behaviour of assigning to the
standard streams (stdin etc). As a result the package is currently
disabled when using musl.

This commit backports two patches from upstream lvm2 (not yet in a
release) that fix some build issues with musl, and two additional
patches taken from the Gentoo distribution to address more issues.

With those 4 patches combined, lvm2 builds fine with musl and can
therefore be re-enabled in musl configurations.

Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Simon Rowe 2 ani în urmă
părinte
comite
c5e9422197

+ 30 - 0
package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch

@@ -0,0 +1,30 @@
+From bac596b3685520acaa404dc3ebd2131e6de96d47 Mon Sep 17 00:00:00 2001
+From: Zdenek Kabelac <zkabelac@redhat.com>
+Date: Wed, 16 Feb 2022 00:48:49 +0100
+Subject: [PATCH] clang: possible better compilation with musl c
+
+Try to help resolving reported compilation problem with
+clang & musl C.
+https://github.com/lvmteam/lvm2/issues/61
+
+Backported from: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4fd76de4b69f8e5e6d5afa03d54cb4b8986c4bcc
+Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
+---
+ libdaemon/server/daemon-server.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
+index 88905a7dd..96cfc392e 100644
+--- a/libdaemon/server/daemon-server.c
++++ b/libdaemon/server/daemon-server.c
+@@ -18,6 +18,7 @@
+ 
+ #include <dlfcn.h>
+ #include <errno.h>
++#include <fcntl.h> /* help musl C */
+ #include <pthread.h>
+ #include <sys/file.h>
+ #include <sys/stat.h>
+-- 
+2.22.3
+

+ 34 - 0
package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch

@@ -0,0 +1,34 @@
+From b668022f9b8aecf52109c9e0b7e5847054231361 Mon Sep 17 00:00:00 2001
+From: Zdenek Kabelac <zkabelac@redhat.com>
+Date: Fri, 19 Aug 2022 16:15:17 +0200
+Subject: [PATCH] mm: preallocate memory only with glibc
+
+Use mallinfo() only with glibc.
+
+Backported from: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8370d117d7ef8a472c95315a3cd085696c90b3be
+Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
+---
+ lib/mm/memlock.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
+index 3d1a3927c..efcc6d91f 100644
+--- a/lib/mm/memlock.c
++++ b/lib/mm/memlock.c
+@@ -160,7 +160,12 @@ static void _touch_memory(void *mem, size_t size)
+ 
+ static void _allocate_memory(void)
+ {
+-#ifndef VALGRIND_POOL
++#if defined(__GLIBC__) && !defined(VALGRIND_POOL)
++	/* Memory allocation is currently only tested with glibc
++	 * for different C libraries, some other mechanisms might be needed
++	 * meanwhile let users use lvm2 code without memory preallocation.
++	 * Compilation for VALGRIND tracing also goes without preallocation.
++	 */
+ 	void *stack_mem;
+ 	struct rlimit limit;
+ 	int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
+-- 
+2.22.3
+

+ 68 - 0
package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch

@@ -0,0 +1,68 @@
+From 7c74ad9c349e381decc84c218112ea8e7bcc0b9c Mon Sep 17 00:00:00 2001
+From: Simon Rowe <simon.rowe@nutanix.com>
+Date: Thu, 23 Mar 2023 09:57:59 +0000
+Subject: [PATCH] cmdline: use freopen() to reopen standard streams
+
+In glibc stdin, stdout & stderr are variables that can be assigned to
+(https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html)
+however this not necessarily true of other C libraries.
+
+The gentoo musl porting notes
+(https://wiki.gentoo.org/wiki/Musl_porting_notes)
+recommend the substitution of
+
+    stdX = fopen(...)
+
+with
+
+    freopen(..., stdX)
+
+Taken from: https://github.com/gentoo/gentoo/blob/master/sys-fs/lvm2/files/lvm2-2.03.14-r1-fopen-to-freopen.patch
+Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
+---
+ tools/lvmcmdline.c | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
+index 1e12bedca..534368575 100644
+--- a/tools/lvmcmdline.c
++++ b/tools/lvmcmdline.c
+@@ -3384,7 +3384,11 @@ static int _check_standard_fds(void)
+ 	int err = is_valid_fd(STDERR_FILENO);
+ 
+ 	if (!is_valid_fd(STDIN_FILENO) &&
++#ifdef __GLIBC__
+ 	    !(stdin = fopen(_PATH_DEVNULL, "r"))) {
++#else
++	    !freopen(_PATH_DEVNULL, "r", stdin)) {
++#endif
+ 		if (err)
+ 			perror("stdin stream open");
+ 		else
+@@ -3394,7 +3398,11 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDOUT_FILENO) &&
++#ifdef __GLIBC__
+ 	    !(stdout = fopen(_PATH_DEVNULL, "w"))) {
++#else
++	    !freopen(_PATH_DEVNULL, "w", stdout)) {
++#endif
+ 		if (err)
+ 			perror("stdout stream open");
+ 		/* else no stdout */
+@@ -3402,7 +3410,11 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDERR_FILENO) &&
++#ifdef __GLIBC__
+ 	    !(stderr = fopen(_PATH_DEVNULL, "w"))) {
++#else
++	    !freopen(_PATH_DEVNULL, "w", stderr)) {
++#endif
+ 		printf("stderr stream open: %s\n",
+ 		       strerror(errno));
+ 		return 0;
+-- 
+2.22.3
+

+ 44 - 0
package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch

@@ -0,0 +1,44 @@
+From 6d6b953cf7d2b8d06e7b0363b1b06cb2e902aa0f Mon Sep 17 00:00:00 2001
+From: Simon Rowe <simon.rowe@nutanix.com>
+Date: Thu, 23 Mar 2023 10:07:02 +0000
+Subject: [PATCH] log: use freopen() to reopen standard streams
+
+In glibc stdin, stdout & stderr are variables that can be assigned to
+(https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html)
+however this not necessarily true of other C libraries.
+
+The gentoo musl porting notes
+(https://wiki.gentoo.org/wiki/Musl_porting_notes)
+recommend the substitution of
+
+    stdX = fopen(...)
+
+with
+
+    freopen(..., stdX)
+
+Taken from: https://github.com/gentoo/gentoo/blob/master/sys-fs/lvm2/files/lvm2-2.03.14-freopen_n2.patch
+Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
+---
+ lib/log/log.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/lib/log/log.c b/lib/log/log.c
+index 7b4d537b3..5f62c048c 100644
+--- a/lib/log/log.c
++++ b/lib/log/log.c
+@@ -208,7 +208,11 @@ int reopen_standard_stream(FILE **stream, const char *mode)
+ 
+ 	_check_and_replace_standard_log_streams(old_stream, new_stream);
+ 
++#ifdef __GLIBC__
+ 	*stream = new_stream;
++#else
++	freopen(NULL, mode, *stream);
++#endif
+ 	return 1;
+ }
+ 
+-- 
+2.22.3
+

+ 0 - 5
package/lvm2/Config.in

@@ -27,15 +27,10 @@ if BR2_PACKAGE_LVM2
 config BR2_PACKAGE_LVM2_STANDARD_INSTALL
 	bool "standard install instead of only dmsetup"
 	default y
-	# http://lists.busybox.net/pipermail/buildroot/2016-August/170592.html
-	depends on !BR2_TOOLCHAIN_USES_MUSL
 	help
 	  Install the standard suite of lvm2 programs. When this option
 	  is not set, only dmsetup is installed.
 
-comment "lvm2 standard install needs a glibc or uClibc toolchain"
-	depends on BR2_TOOLCHAIN_USES_MUSL
-
 endif
 
 comment "lvm2 needs a toolchain w/ threads, dynamic library"