Skip to contentSkip to conversation

package/eudev: fix build with musl + libselinux

PATCH Superseded Romain Naour 2 participants 3 messages Jul 31, 2015 – Aug 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 package/eudev: fix build with musl + libselinux

Add a patch to disable mallinfo statistics with musl toolchains which doesn't have struct mallinfo.

Fixes:
selinux-util.c: In function ?mac_selinux_init?:
selinux-util.c:70:25: error: storage size of ?before_mallinfo? isn?t known

         struct mallinfo before_mallinfo, after_mallinfo;

Add a second patch for strndupa() which is a GNU extension.

Fixes:
./.libs/libudev-core.a(selinux-util.o): In function `mac_selinux_bind':
selinux-util.c:(.text+0xd94): undefined reference to `strndupa'
collect2: error: ld returned 1 exit status

Cc Clayton Shotwell <[email protected]>

---
v3: Don't enclose the timestamp stuff inside HAVE_MALLINFO (ThomasP)
v2: new patch

---
 .../eudev/0002-build-sys-check-for-mallinfo.patch  | 93 ++++++++++++++++++++++
 .../eudev/0003-build-sys-check-for-strndupa.patch  | 69 ++++++++++++++++
 package/eudev/eudev.mk                             |  5 ++
 3 files changed, 167 insertions(+)
 create mode 100644 package/eudev/0002-build-sys-check-for-mallinfo.patch
 create mode 100644 package/eudev/0003-build-sys-check-for-strndupa.patch
package/eudev/0002-build-sys-check-for-mallinfo.patch new file +93 -0
new file mode 100644
index 0000000..c2fa2da
@@ -0,0 +1,93 @@
+From 1205e0b50067c5ebfa082f149f0996304aa04335 Mon Sep 17 00:00:00 2001
+From: Romain Naour <[email protected]>
+Date: Thu, 30 Jul 2015 16:55:45 +0200
+Subject: [PATCH] build-sys: check for mallinfo
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+mallinfo is not specified by POSIX or the C standards, therefore
+it's not available for all libc libraries (musl).
+
+Add the ability to disable mallinfo statistics.
+
+Fixes:
+selinux-util.c: In function ?mac_selinux_init?:
+selinux-util.c:70:25: error: storage size of ?before_mallinfo? isn?t known
+         struct mallinfo before_mallinfo, after_mallinfo;
+
+Signed-off-by: Romain Naour <[email protected]>
+---
+ configure.ac              |  3 +++
+ src/shared/selinux-util.c | 15 +++++++++++++++
+ 2 files changed, 18 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index ec23ab5..4a293b2 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -226,6 +226,9 @@ else
+ fi
+ AC_SUBST(sushell)
+ 
++# selinux-util.c uses struct mallinfo which is not available for all C libraries (musl).
++AC_CHECK_FUNCS([mallinfo])
++
+ # ------------------------------------------------------------------------------
+ 
+ AC_CHECK_DECL([unshare],
+diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c
+index 756215e..4e0866b 100644
+--- a/src/shared/selinux-util.c
++++ b/src/shared/selinux-util.c
+@@ -67,7 +67,10 @@ int mac_selinux_init(const char *prefix) {
+ 
+ #ifdef HAVE_SELINUX
+         usec_t before_timestamp, after_timestamp;
++
++#ifdef HAVE_MALLINFO
+         struct mallinfo before_mallinfo, after_mallinfo;
++#endif
+ 
+         if (!mac_selinux_use())
+                 return 0;
+@@ -75,7 +78,10 @@ int mac_selinux_init(const char *prefix) {
+         if (label_hnd)
+                 return 0;
+ 
++#ifdef HAVE_MALLINFO
+         before_mallinfo = mallinfo();
++#endif
++
+         before_timestamp = now(CLOCK_MONOTONIC);
+ 
+         if (prefix) {
+@@ -92,9 +98,14 @@ int mac_selinux_init(const char *prefix) {
+                 r = security_getenforce() == 1 ? -errno : 0;
+         } else  {
+                 char timespan[FORMAT_TIMESPAN_MAX];
++
++#ifdef HAVE_MALLINFO
+                 int l;
++#endif
+ 
+                 after_timestamp = now(CLOCK_MONOTONIC);
++
++#ifdef HAVE_MALLINFO
+                 after_mallinfo = mallinfo();
+ 
+                 l = after_mallinfo.uordblks > before_mallinfo.uordblks ? after_mallinfo.uordblks - before_mallinfo.uordblks : 0;
+@@ -102,6 +113,10 @@ int mac_selinux_init(const char *prefix) {
+                 log_debug("Successfully loaded SELinux database in %s, size on heap is %iK.",
+                           format_timespan(timespan, sizeof(timespan), after_timestamp - before_timestamp, 0),
+                           (l+1023)/1024);
++#else
++                log_debug("Successfully loaded SELinux database in %s",
++                          format_timespan(timespan, sizeof(timespan), after_timestamp - before_timestamp, 0));
++#endif
+         }
+ #endif
+ 
+-- 
+2.4.3
+
package/eudev/0003-build-sys-check-for-strndupa.patch new file +69 -0

69 lines not on this page · raw message

package/eudev/eudev.mk +5 -0
index f587acd..b916acd 100644
@@ -11,6 +11,11 @@ EUDEV_LICENSE = GPLv2+ (programs), LGPLv2.1+ (libraries)
 EUDEV_LICENSE_FILES = COPYING
 EUDEV_INSTALL_STAGING = YES
 
+# configure.ac is patched by:
+# 0002-build-sys-check-for-mallinfo.patch
+# 0003-build-sys-check-for-strndupa.patch
+EUDEV_AUTORECONF = YES
+
 # mq_getattr is in librt
 EUDEV_CONF_ENV += LIBS=-lrt
 
Signature · 1 line
2.4.3
#1 lore raw

PATCH v3 1/1 package/eudev: fix build with musl + libselinux

Dear Romain Naour,

Quoted 20 lines · Romain Naour

Add a patch to disable mallinfo statistics with musl toolchains which doesn't have struct mallinfo.

Fixes:
selinux-util.c: In function ?mac_selinux_init?:
selinux-util.c:70:25: error: storage size of ?before_mallinfo? isn?t known

         struct mallinfo before_mallinfo, after_mallinfo;

Add a second patch for strndupa() which is a GNU extension.

Fixes:
./.libs/libudev-core.a(selinux-util.o): In function `mac_selinux_bind':
selinux-util.c:(.text+0xd94): undefined reference to `strndupa'
collect2: error: ld returned 1 exit status

Cc Clayton Shotwell <[email protected]>

---
v3: Don't enclose the timestamp stuff inside HAVE_MALLINFO (ThomasP)
v2: new patch

Quoted 7 lines
---
 .../eudev/0002-build-sys-check-for-mallinfo.patch  | 93 ++++++++++++++++++++++
 .../eudev/0003-build-sys-check-for-strndupa.patch  | 69 ++++++++++++++++
 package/eudev/eudev.mk                             |  5 ++
 3 files changed, 167 insertions(+)
 create mode 100644 package/eudev/0002-build-sys-check-for-mallinfo.patch
 create mode 100644 package/eudev/0003-build-sys-check-for-strndupa.patch

I've applied the patch, with the hope that the patches will be merged upstream. Supporting musl+selinux is a fairly odd setup, so carrying around forever patches for this specific setup would be a bit annoying.

Can you make sure to keep pushing the patches upstream?

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH v3 1/1 package/eudev: fix build with musl + libselinux

Hi Thomas,

Le 06/08/2015 09:07, Thomas Petazzoni a ?crit :

Quoted 31 lines

Dear Romain Naour,

Quoted 20 lines · Romain Naour

Add a patch to disable mallinfo statistics with musl toolchains which doesn't have struct mallinfo.

Fixes:
selinux-util.c: In function ?mac_selinux_init?:
selinux-util.c:70:25: error: storage size of ?before_mallinfo? isn?t known

         struct mallinfo before_mallinfo, after_mallinfo;

Add a second patch for strndupa() which is a GNU extension.

Fixes:
./.libs/libudev-core.a(selinux-util.o): In function `mac_selinux_bind':
selinux-util.c:(.text+0xd94): undefined reference to `strndupa'
collect2: error: ld returned 1 exit status

Cc Clayton Shotwell <[email protected]>

---
v3: Don't enclose the timestamp stuff inside HAVE_MALLINFO (ThomasP)
v2: new patch

Quoted 7 lines
---
 .../eudev/0002-build-sys-check-for-mallinfo.patch  | 93 ++++++++++++++++++++++
 .../eudev/0003-build-sys-check-for-strndupa.patch  | 69 ++++++++++++++++
 package/eudev/eudev.mk                             |  5 ++
 3 files changed, 167 insertions(+)
 create mode 100644 package/eudev/0002-build-sys-check-for-mallinfo.patch
 create mode 100644 package/eudev/0003-build-sys-check-for-strndupa.patch
Quoted 5 lines

I've applied the patch, with the hope that the patches will be merged upstream. Supporting musl+selinux is a fairly odd setup, so carrying around forever patches for this specific setup would be a bit annoying.

Can you make sure to keep pushing the patches upstream?

A pull request is pending on github:
https://github.com/gentoo/eudev/pull/122

Best regards,
Romain

Quoted 5 lines

Thanks,

Thomas