Skip to contentSkip to conversation

libnfs: fix build of applications like mpd on musl

PATCH New Fabrice Fontaine 2 participants 3 messages Sep 22, 2018 – Sep 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnfs: fix build of applications like mpd on musl

Include sys/time.h if __linux__ is defined otherwise applications including libnfs.h (such as mpd) will fail to build on musl:

/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/x86_64-linux-g++ -DHAVE_CONFIG_H -I. -DNDEBUG -I./src -DSYSTEM_CONFIG_FILE_LOCATION='"/etc/mpd.conf"' -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -pthread -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -fvisibility=hidden -fno-threadsafe-statics -fmerge-all-constants -ffast-math -ftree-vectorize -ffunction-sections -fdata-sections -Wall -Wextra -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wsign-compare -Wno-noexcept-type -c -o src/lib/nfs/libstorage_a-Error.o test -f 'src/lib/nfs/Error.cxx' || echo './'src/lib/nfs/Error.cxx
In file included from src/lib/nfs/Error.cxx:37:0:
/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:23: error: field 'atime' has incomplete type 'timeval'

        struct timeval atime;
                       ^~~~~
/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:15: note: forward declaration of 'struct timeval'
        struct timeval atime;

Fixes:
- http://autobuild.buildroot.org/results/892469e34cb2f7e8fac4a79f8c51ca8e7235aef3

---
 ...nally-include-sys-time.h-in-libnfs.h.patch | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 package/libnfs/0001-conditionally-include-sys-time.h-in-libnfs.h.patch
package/libnfs/0001-conditionally-include-sys-time.h-in-libnfs.h.patch new file +40 -0
new file mode 100644
index 0000000000..80b4fdca70
@@ -0,0 +1,40 @@
+From e2b7bcfbc38336d12dfdd4e36af87be4352a16a9 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <[email protected]>
+Date: Sat, 22 Sep 2018 13:27:18 +0200
+Subject: [PATCH] conditionally include sys/time.h in libnfs.h
+
+Include sys/time.h if __linux__ is defined otherwise applications
+including libnfs.h (such as mpd) will fail to build on musl:
+
+/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/x86_64-linux-g++ -DHAVE_CONFIG_H -I.  -DNDEBUG -I./src  -DSYSTEM_CONFIG_FILE_LOCATION='"/etc/mpd.conf"'  -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include   -I/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/bin/../x86_64-buildroot-linux-musl/sysroot/usr/include    -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -pthread -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os   -fvisibility=hidden -fno-threadsafe-statics -fmerge-all-constants -ffast-math -ftree-vectorize -ffunction-sections -fdata-sections -Wall -Wextra -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wsign-compare -Wno-noexcept-type -c -o src/lib/nfs/libstorage_a-Error.o `test -f 'src/lib/nfs/Error.cxx' || echo './'`src/lib/nfs/Error.cxx
+In file included from src/lib/nfs/Error.cxx:37:0:
+/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:23: error: field 'atime' has incomplete type 'timeval'
+        struct timeval atime;
+                       ^~~~~
+/home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include/nfsc/libnfs.h:965:15: note: forward declaration of 'struct timeval'
+        struct timeval atime;
+
+Fixes:
+ - http://autobuild.buildroot.org/results/892469e34cb2f7e8fac4a79f8c51ca8e7235aef3
+
+Signed-off-by: Fabrice Fontaine <[email protected]>
+---
+ include/nfsc/libnfs.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h
+index 09dcf1c..23dcc98 100755
+--- a/include/nfsc/libnfs.h
++++ b/include/nfsc/libnfs.h
+@@ -24,7 +24,7 @@
+ #define _LIBNFS_H_
+ 
+ #include <stdint.h>
+-#if defined(__ANDROID__) || defined(AROS) \
++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \
+  || ( defined(__APPLE__) && defined(__MACH__) )
+ #include <sys/time.h>
+ #else
+-- 
+2.17.1
+
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 libnfs: fix build of applications like mpd on musl

Hello,

Quoted 6 lines · Fabrice Fontaine

+ #include <stdint.h>

+-#if defined(__ANDROID__) || defined(AROS) \
++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \
+  || ( defined(__APPLE__) && defined(__MACH__) )

+ #include <sys/time.h>
+ #else

I think the proper fix would be to use the AC_HEADER_TIME macro
(https://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Headers).
First need to add:

AC_HEADER_TIME
AC_CHECK_HEADERS([sys/time.h])

And then in the code, do:

#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif

Instead of the mess that is currently done based on the system on which the stuff is being compiled.

Could you try to do this, and upstream the corresponding patch ?

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 libnfs: fix build of applications like mpd on musl

Dear Thomas,

Le dim. 23 sept. 2018 ? 16:52, Thomas Petazzoni <
[email protected]> a ?crit :

Quoted 33 lines

Hello,

Quoted 6 lines · Fabrice Fontaine

+ #include <stdint.h>

+-#if defined(__ANDROID__) || defined(AROS) \
++#if defined(__ANDROID__) || defined(AROS) || defined(__linux__) \
+  || ( defined(__APPLE__) && defined(__MACH__) )

+ #include <sys/time.h>
+ #else

I think the proper fix would be to use the AC_HEADER_TIME macro (
https://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Headers
).
First need to add:

AC_HEADER_TIME
AC_CHECK_HEADERS([sys/time.h])

And then in the code, do:

#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif

Quoted 5 lines

Instead of the mess that is currently done based on the system on which the stuff is being compiled.

Could you try to do this, and upstream the corresponding patch ?

Actually, that's what has been done upstream for libnfs.c (
https://github.com/sahlberg/libnfs/commit/5c1444f391f8c29cc18fd644ab282b5a037e5798)
but this will not fix our issue.
Indeed, the build is not failing on libnfs but on mpd because mpd includes libnfs.h which is a public header.
We can't enforce that all applications that use libnfs.h such as mpd should make a call to AC_HEADER_TIME or AC_CHECK_HEADERS([sys/time.h]), do we?

Quoted 8 lines

Thanks,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Best Regards,

Fabrice
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20180923/1d229520/attachment.html>