Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
@ 2023-03-16 11:36 Simon Rowe
  2023-03-19 16:25 ` Thomas Petazzoni via buildroot
  2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
  0 siblings, 2 replies; 10+ messages in thread
From: Simon Rowe @ 2023-03-16 11:36 UTC (permalink / raw)
  To: buildroot; +Cc: Simon Rowe

LVM uses some glibc-specific functions to try and control locking
memory in RAM. As a result the package is currently disabled when
using musl.

Apply patches taken from gentoo:

    https://github.com/gentoo/gentoo/pull/25883
    https://github.com/gentoo/gentoo/pull/26024

and drop the prohibition on musl in Config.in.

Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
---
 .../lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch | 25 +++++++++++
 ...002-lvm2-2.03.14-r1-fopen-to-freopen.patch | 44 +++++++++++++++++++
 .../lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch  | 20 +++++++++
 .../lvm2/0004-lvm2-2.03.14-freopen_n2.patch   | 36 +++++++++++++++
 package/lvm2/Config.in                        |  5 ---
 5 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch
 create mode 100644 package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch
 create mode 100644 package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch
 create mode 100644 package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch

diff --git a/package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch b/package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch
new file mode 100644
index 0000000000..14b3164c3f
--- /dev/null
+++ b/package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch
@@ -0,0 +1,25 @@
+https://bugs.gentoo.org/712336
+https://bugs.gentoo.org/549506
+
+Adds fcntl.h into daemon-server.c to define fcntl and some constants.
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694
+---
+ 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 88905a7..771b021 100644
+--- a/libdaemon/server/daemon-server.c
++++ b/libdaemon/server/daemon-server.c
+@@ -28,6 +28,7 @@
+ #include <sys/un.h>
+ #include <unistd.h>
+ #include <signal.h>
++#include <fcntl.h>
+ 
+ #include <syslog.h> /* FIXME. For the global closelog(). */
+ 
+-- 
+2.35.1
+
diff --git a/package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch b/package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch
new file mode 100644
index 0000000000..1d47fdb283
--- /dev/null
+++ b/package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch
@@ -0,0 +1,44 @@
+In musl stdout, stdin and stderr are read-only unlike in glibc.
+This patch changes std* = fopen(...) to freopen(..., std*).
+
+See: https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html and https://wiki.gentoo.org/wiki/User:Sam/Musl_porting_notes
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694
+---
+ tools/lvmcmdline.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
+index 1e12bed..19da1e5 100644
+--- a/tools/lvmcmdline.c
++++ b/tools/lvmcmdline.c
+@@ -3384,7 +3384,7 @@ static int _check_standard_fds(void)
+ 	int err = is_valid_fd(STDERR_FILENO);
+ 
+ 	if (!is_valid_fd(STDIN_FILENO) &&
+-	    !(stdin = fopen(_PATH_DEVNULL, "r"))) {
++		!freopen(_PATH_DEVNULL, "r", stdin)) {
+ 		if (err)
+ 			perror("stdin stream open");
+ 		else
+@@ -3394,7 +3394,7 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDOUT_FILENO) &&
+-	    !(stdout = fopen(_PATH_DEVNULL, "w"))) {
++		!freopen(_PATH_DEVNULL, "w", stdout)) {
+ 		if (err)
+ 			perror("stdout stream open");
+ 		/* else no stdout */
+@@ -3402,7 +3402,7 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDERR_FILENO) &&
+-	    !(stderr = fopen(_PATH_DEVNULL, "w"))) {
++		!freopen(_PATH_DEVNULL, "w", stderr)) {
+ 		printf("stderr stream open: %s\n",
+ 		       strerror(errno));
+ 		return 0;
+-- 
+2.35.1
+
diff --git a/package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch b/package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch
new file mode 100644
index 0000000000..d593dca171
--- /dev/null
+++ b/package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch
@@ -0,0 +1,20 @@
+https://git.alpinelinux.org/aports/tree/main/lvm2/mallinfo.patch
+
+Patch from Alpine, disables _allocate_memory since mallinfo isn't defined in musl.
+19:17 <@sam_> your caution is well-advised, but it should be safe enough given it's only affecting the non-glibc path
+
+Should be looked back to!
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694
+
+--- ./lib/mm/memlock.c.orig	2015-03-09 11:18:41.560028850 -0100
++++ ./lib/mm/memlock.c	2015-03-09 11:19:54.504373309 -0100
+@@ -137,7 +137,7 @@
+ 
+ static void _allocate_memory(void)
+ {
+-#ifndef VALGRIND_POOL
++#if !defined(VALGRIND_POOL) && defined(__GLIBC__)
+ 	void *stack_mem;
+ 	struct rlimit limit;
+ 	int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
diff --git a/package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch b/package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch
new file mode 100644
index 0000000000..d19bc99b7c
--- /dev/null
+++ b/package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch
@@ -0,0 +1,36 @@
+In musl, the standard streams are read-only. To modify them we need to
+use freopen. This patch does the same as lvm2-2.03.14-r1-fopen-to-freopen.patch
+
+https://listman.redhat.com/archives/lvm-devel/2022-June/024203.html
+
+See also:
+https://wiki.gentoo.org/wiki/User:Sam/Musl_porting_notes#error:_assignment_of_read-only_variable_.27.5Bstdout.7Cstdin.7Cstderr.5D.27
+https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html
+
+Fetch from: http://listman.redhat.com/archives/lvm-devel/attachments/20220621/3594a4a7/attachment.bin
+
+---
+ lib/log/log.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/lib/log/log.c b/lib/log/log.c
+index 7b4d537..897c183 100644
+--- a/lib/log/log.c
++++ b/lib/log/log.c
+@@ -207,8 +207,12 @@ 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.35.1
+
diff --git a/package/lvm2/Config.in b/package/lvm2/Config.in
index cc740dd40c..577a90656a 100644
--- a/package/lvm2/Config.in
+++ b/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"
-- 
2.22.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
  2023-03-16 11:36 [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl Simon Rowe
@ 2023-03-19 16:25 ` Thomas Petazzoni via buildroot
  2023-03-21 13:39   ` Simon Rowe
  2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
  1 sibling, 1 reply; 10+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-03-19 16:25 UTC (permalink / raw)
  To: Simon Rowe; +Cc: buildroot

Hello Simon,

On Thu, 16 Mar 2023 11:36:15 +0000
Simon Rowe <simon.rowe@nutanix.com> wrote:

> LVM uses some glibc-specific functions to try and control locking
> memory in RAM. As a result the package is currently disabled when
> using musl.
> 
> Apply patches taken from gentoo:
> 
>     https://github.com/gentoo/gentoo/pull/25883
>     https://github.com/gentoo/gentoo/pull/26024
> 
> and drop the prohibition on musl in Config.in.
> 
> Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>

Thanks Simon for those patches! Could you rework the 4 patches so that
they are generated with git format-patch and have your Signed-off-by? I
recommend that you take the upstream Git repo of lvm2, checkout the tag
corresponding to version 2.03.14, apply the 4 Gentoo patches, each time
turning the changes into a proper commit.

Another thing to look at is that the multipath-tools package is
selecting BR2_PACKAGE_LVM2_STANDARD_INSTALL, so you need to check
whether the depends on !BR2_TOOLCHAIN_USES_MUSL used in
BR2_PACKAGE_MULTIPATH_TOOLS is still needed? Perhaps thanks to your
work on lvm2 it is now possible to build/use multipath-tools with musl.

Another question is the upstream status of the Gentoo patches? Have
they been submitted for inclusion by the upstream lvm2 project?

Thanks!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
  2023-03-19 16:25 ` Thomas Petazzoni via buildroot
@ 2023-03-21 13:39   ` Simon Rowe
  2023-03-21 13:54     ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Rowe @ 2023-03-21 13:39 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: buildroot@buildroot.org


[-- Attachment #1.1: Type: text/plain, Size: 1469 bytes --]

On 19 March 2023 Thomas Petazzoni wrote:

> Thanks Simon for those patches! Could you rework the 4 patches so that
> they are generated with git format-patch and have your Signed-off-by? I
> recommend that you take the upstream Git repo of lvm2, checkout the tag
> corresponding to version 2.03.14, apply the 4 Gentoo patches, each time
> turning the changes into a proper commit.

I am not the author of these patches, which is why I didn’t add a ‘Signed-off-by:’. I followed what I thought the process was for patches originating from elsewhere by adding a ‘Fetch from:’ to each patch as mentioned in 19.4 of the manual. I can regenerate them if that’s the correct approach.

> Another thing to look at is that the multipath-tools package is
> selecting BR2_PACKAGE_LVM2_STANDARD_INSTALL, so you need to check
> whether the depends on !BR2_TOOLCHAIN_USES_MUSL used in
> BR2_PACKAGE_MULTIPATH_TOOLS is still needed? Perhaps thanks to your
> work on lvm2 it is now possible to build/use multipath-tools with musl.

I’ve not got a use case for multipath myself by I’ll check if I can get it to build with these patches.

> Another question is the upstream status of the Gentoo patches? Have
> they been submitted for inclusion by the upstream lvm2 project?

There seems to be a suggestion that was attempted on the ticket

https://bugs.gentoo.org/549506

but that was some time ago and there’s no sign of them being accepted.

Regards
Simon

[-- Attachment #1.2: Type: text/html, Size: 4157 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
  2023-03-21 13:39   ` Simon Rowe
@ 2023-03-21 13:54     ` Thomas Petazzoni via buildroot
  2023-03-23 12:36       ` Simon Rowe
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-03-21 13:54 UTC (permalink / raw)
  To: Simon Rowe; +Cc: buildroot@buildroot.org

Hello Simon,

On Tue, 21 Mar 2023 13:39:12 +0000
Simon Rowe <simon.rowe@nutanix.com> wrote:

> I am not the author of these patches, which is why I didn’t add a
> ‘Signed-off-by:’. I followed what I thought the process was for
> patches originating from elsewhere by adding a ‘Fetch from:’ to each
> patch as mentioned in 19.4 of the manual. I can regenerate them if
> that’s the correct approach.

A Signed-off-by is not only an indication of the author, but also an
indication of the chain of people through which the patch traveled. For
example in the Linux kernel, patches have a SoB from the author, then a
SoB from the maintainer taking the patch, and possibly another SoB from
yet another maintainer taking the patch from that previous maintainer.

In Buildroot, we therefore have patches with two SoB: one from the
original author, and one from the developer bringing the patch into
Buildroot. Or alternatively patches with only one SoB, from the
developer bringing the patch into Buildroot (you in this case) when the
original patch lacks an SoB.

> I’ve not got a use case for multipath myself by I’ll check if I can
> get it to build with these patches.

Good!

> > Another question is the upstream status of the Gentoo patches? Have
> > they been submitted for inclusion by the upstream lvm2 project?  
> 
> There seems to be a suggestion that was attempted on the ticket
> 
> https://bugs.gentoo.org/549506
> 
> but that was some time ago and there’s no sign of them being accepted.

It's been a while ago. Perhaps time to do another attempt at
upstreaming those patches?

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
  2023-03-21 13:54     ` Thomas Petazzoni via buildroot
@ 2023-03-23 12:36       ` Simon Rowe
  2023-03-23 13:15         ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Rowe @ 2023-03-23 12:36 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: buildroot@buildroot.org


[-- Attachment #1.1: Type: text/plain, Size: 1260 bytes --]

On 21 March 2023 Thomas Petazzoni wrote:

> A Signed-off-by is not only an indication of the author, but also an
> indication of the chain of people through which the patch traveled. For
> example in the Linux kernel, patches have a SoB from the author, then a
> SoB from the maintainer taking the patch, and possibly another SoB from
> yet another maintainer taking the patch from that previous maintainer.
>
> In Buildroot, we therefore have patches with two SoB: one from the
> original author, and one from the developer bringing the patch into
> Buildroot. Or alternatively patches with only one SoB, from the
> developer bringing the patch into Buildroot (you in this case) when the
> original patch lacks an SoB.

Thank you for explaining this, I’ll add the SoB to the new series.

> It's been a while ago. Perhaps time to do another attempt at
> upstreaming those patches?

After a little more research I’ve discovered that some of the fixes are covered by changesets present in the upstream master. I’ll replace my patches with those and try to upstream the remainder.

I’ve confirmed that multipath-tools builds with musl so I’ll include a patch for this. I’ve not tested if the resulting binary works though.

Regards
Simon

[-- Attachment #1.2: Type: text/html, Size: 3942 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
  2023-03-23 12:36       ` Simon Rowe
@ 2023-03-23 13:15         ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-03-23 13:15 UTC (permalink / raw)
  To: Simon Rowe; +Cc: buildroot@buildroot.org

On Thu, 23 Mar 2023 12:36:54 +0000
Simon Rowe <simon.rowe@nutanix.com> wrote:

> > It's been a while ago. Perhaps time to do another attempt at
> > upstreaming those patches?  
> 
> After a little more research I’ve discovered that some of the fixes
> are covered by changesets present in the upstream master. I’ll
> replace my patches with those and try to upstream the remainder.
> 
> I’ve confirmed that multipath-tools builds with musl so I’ll include
> a patch for this. I’ve not tested if the resulting binary works
> though.

This is all great news. Thanks a lot for the extra work, looking
forward to seeing the patches!

Best regards,

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 1/2] package/lvm2: enable package with musl
  2023-03-16 11:36 [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl Simon Rowe
  2023-03-19 16:25 ` Thomas Petazzoni via buildroot
@ 2023-03-23 14:13 ` Simon Rowe
  2023-03-23 14:13   ` [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable " Simon Rowe
  2023-03-26 21:10   ` [Buildroot] [PATCH v2 1/2] package/lvm2: enable package " Thomas Petazzoni via buildroot
  1 sibling, 2 replies; 10+ messages in thread
From: Simon Rowe @ 2023-03-23 14:13 UTC (permalink / raw)
  To: buildroot; +Cc: Simon Rowe, Alexander Egorenkov

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.

Apply patches based on those present in gentoo:

    https://github.com/gentoo/gentoo/pull/25883
    https://github.com/gentoo/gentoo/pull/26024

and drop the prohibition on musl in Config.in.

Also, backport a couple of compilation fixes needed build with musl.

Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
---
 ...sible-better-compilation-with-musl-c.patch | 30 +++++++++
 ...m-preallocate-memory-only-with-glibc.patch | 34 ++++++++++
 ...e-freopen-to-reopen-standard-streams.patch | 67 +++++++++++++++++++
 ...e-freopen-to-reopen-standard-streams.patch | 43 ++++++++++++
 package/lvm2/Config.in                        |  5 --
 5 files changed, 174 insertions(+), 5 deletions(-)
 create mode 100644 package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch
 create mode 100644 package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch
 create mode 100644 package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch
 create mode 100644 package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch

diff --git a/package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch b/package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch
new file mode 100644
index 0000000000..b46e4c92d6
--- /dev/null
+++ b/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: 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
+
diff --git a/package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch b/package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch
new file mode 100644
index 0000000000..d4dba07e84
--- /dev/null
+++ b/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: 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
+
diff --git a/package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch b/package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch
new file mode 100644
index 0000000000..6d57cc64f0
--- /dev/null
+++ b/package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch
@@ -0,0 +1,67 @@
+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)
+
+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
+
diff --git a/package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch b/package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch
new file mode 100644
index 0000000000..773bef2db0
--- /dev/null
+++ b/package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch
@@ -0,0 +1,43 @@
+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)
+
+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
+
diff --git a/package/lvm2/Config.in b/package/lvm2/Config.in
index cc740dd40c..577a90656a 100644
--- a/package/lvm2/Config.in
+++ b/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"
-- 
2.22.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable with musl
  2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
@ 2023-03-23 14:13   ` Simon Rowe
  2023-03-26 21:11     ` Thomas Petazzoni via buildroot
  2023-03-26 21:10   ` [Buildroot] [PATCH v2 1/2] package/lvm2: enable package " Thomas Petazzoni via buildroot
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Rowe @ 2023-03-23 14:13 UTC (permalink / raw)
  To: buildroot; +Cc: Simon Rowe, Alexander Egorenkov

Now LVM2 can be built using musl drop the toolchain config
restriction.

Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
---
 package/multipath-tools/Config.in | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/package/multipath-tools/Config.in b/package/multipath-tools/Config.in
index fc4b01b2ac..222f78b86c 100644
--- a/package/multipath-tools/Config.in
+++ b/package/multipath-tools/Config.in
@@ -1,14 +1,12 @@
-comment "multipath-tools needs udev and a uClibc or glibc toolchain w/ threads, dynamic library"
+comment "multipath-tools needs udev and a toolchain w/ threads, dynamic library"
 	depends on BR2_USE_MMU
 	depends on BR2_TOOLCHAIN_HAS_SYNC_4
-	depends on !BR2_TOOLCHAIN_USES_MUSL
 	depends on BR2_PACKAGE_LIBURCU_ARCH_SUPPORTS
 	depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS || !BR2_PACKAGE_HAS_UDEV
 
 config BR2_PACKAGE_MULTIPATH_TOOLS
 	bool "multipath-tools"
 	depends on !BR2_STATIC_LIBS
-	depends on !BR2_TOOLCHAIN_USES_MUSL
 	depends on BR2_USE_MMU
 	depends on BR2_TOOLCHAIN_HAS_THREADS
 	depends on BR2_TOOLCHAIN_HAS_SYNC_4
-- 
2.22.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH v2 1/2] package/lvm2: enable package with musl
  2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
  2023-03-23 14:13   ` [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable " Simon Rowe
@ 2023-03-26 21:10   ` Thomas Petazzoni via buildroot
  1 sibling, 0 replies; 10+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-03-26 21:10 UTC (permalink / raw)
  To: Simon Rowe; +Cc: Alexander Egorenkov, buildroot

On Thu, 23 Mar 2023 14:13:26 +0000
Simon Rowe <simon.rowe@nutanix.com> wrote:

> 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.
> 
> Apply patches based on those present in gentoo:
> 
>     https://github.com/gentoo/gentoo/pull/25883
>     https://github.com/gentoo/gentoo/pull/26024
> 
> and drop the prohibition on musl in Config.in.
> 
> Also, backport a couple of compilation fixes needed build with musl.
> 
> Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
> ---
>  ...sible-better-compilation-with-musl-c.patch | 30 +++++++++
>  ...m-preallocate-memory-only-with-glibc.patch | 34 ++++++++++
>  ...e-freopen-to-reopen-standard-streams.patch | 67 +++++++++++++++++++
>  ...e-freopen-to-reopen-standard-streams.patch | 43 ++++++++++++
>  package/lvm2/Config.in                        |  5 --
>  5 files changed, 174 insertions(+), 5 deletions(-)
>  create mode 100644 package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch
>  create mode 100644 package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch
>  create mode 100644 package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch
>  create mode 100644 package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch

I've added more references to where the patches were found, and
applied. Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable with musl
  2023-03-23 14:13   ` [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable " Simon Rowe
@ 2023-03-26 21:11     ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 10+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-03-26 21:11 UTC (permalink / raw)
  To: Simon Rowe; +Cc: Alexander Egorenkov, buildroot

On Thu, 23 Mar 2023 14:13:27 +0000
Simon Rowe <simon.rowe@nutanix.com> wrote:

> Now LVM2 can be built using musl drop the toolchain config
> restriction.
> 
> Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
> ---
>  package/multipath-tools/Config.in | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Applied to master, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-03-26 21:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-16 11:36 [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl Simon Rowe
2023-03-19 16:25 ` Thomas Petazzoni via buildroot
2023-03-21 13:39   ` Simon Rowe
2023-03-21 13:54     ` Thomas Petazzoni via buildroot
2023-03-23 12:36       ` Simon Rowe
2023-03-23 13:15         ` Thomas Petazzoni via buildroot
2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
2023-03-23 14:13   ` [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable " Simon Rowe
2023-03-26 21:11     ` Thomas Petazzoni via buildroot
2023-03-26 21:10   ` [Buildroot] [PATCH v2 1/2] package/lvm2: enable package " Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox