]> granicus.if.org Git - zfs/commitdiff
glibc 2.5 compat: use correct header for makedev() et al.
authorOlaf Faaland <faaland1@llnl.gov>
Fri, 31 Mar 2017 16:32:00 +0000 (09:32 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 31 Mar 2017 16:32:00 +0000 (09:32 -0700)
In glibc 2.5, makedev(), major(), and minor() are defined in
sys/sysmacros.h.  They are also defined in types.h for backward
compatability, but using these definitions triggers a compile warning.
This breaks the ZFS build, as it builds with -Werror.

autoconf email threads indicate these macros may be defined in
sys/mkdev.h in some cases.

This commit adds configure checks to detect where makedev() is defined:
  sys/sysmacros.h
  sys/mkdev.h

It assumes major() and minor() are defined in the same place.

The libspl types.h then includes
sys/sysmacros.h (preferred) or
sys/mkdev.h (2nd choice)
if one of those defines makedev().

This is done before including the system types.h.

An alternative would be to remove uses of major, minor, and makedev,
instead comparing the st_dev returned from stat64.  These configure
checks would then be unnecessary.

This change revealed that __NORETURN was being defined unnecessarily in
libspl/include/sys/sysmacros.h.  That definition is removed.

The files in which __NORETURN are used all include types.h, and so all
will get the definition provided by feature_tests.h

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #5945

config/user-makedev.m4 [new file with mode: 0644]
config/user.m4
lib/libspl/include/sys/sysmacros.h
lib/libspl/include/sys/types.h

diff --git a/config/user-makedev.m4 b/config/user-makedev.m4
new file mode 100644 (file)
index 0000000..4383681
--- /dev/null
@@ -0,0 +1,39 @@
+dnl #
+dnl # glibc 2.25
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_MAKEDEV_IN_SYSMACROS], [
+       AC_MSG_CHECKING([makedev() is declared in sys/sysmacros.h])
+       AC_TRY_COMPILE(
+       [
+               #include <sys/sysmacros.h>
+       ],[
+               int k;
+               k = makedev(0,0);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_MAKEDEV_IN_SYSMACROS, 1,
+                   [makedev() is declared in sys/sysmacros.h])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
+
+dnl #
+dnl # glibc X < Y < 2.25
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV], [
+       AC_MSG_CHECKING([makedev() is declared in sys/mkdev.h])
+       AC_TRY_COMPILE(
+       [
+               #include <sys/mkdev.h>
+       ],[
+               int k;
+               k = makedev(0,0);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_MAKEDEV_IN_MKDEV, 1,
+                   [makedev() is declared in sys/mkdev.h])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
index f70ab635fa5b464bc749e7b6d2b55f7ebbb26872..0e3430757ee09e8b79dcd1fc167520f74bad0cae 100644 (file)
@@ -15,6 +15,8 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
        ZFS_AC_CONFIG_USER_LIBUDEV
        ZFS_AC_CONFIG_USER_FRAME_LARGER_THAN
        ZFS_AC_CONFIG_USER_RUNSTATEDIR
+       ZFS_AC_CONFIG_USER_MAKEDEV_IN_SYSMACROS
+       ZFS_AC_CONFIG_USER_MAKEDEV_IN_MKDEV
 
        ZFS_AC_CONFIG_USER_COMMANDS
        ZFS_AC_TEST_FRAMEWORK
index f99b4d68649bb95e90ea204b6fd89af22af5afd7..31f347c6fd5a26876d1a37c4cc77c5d191e394c7 100644 (file)
@@ -48,7 +48,6 @@
 
 #define        makedevice(maj, min)    makedev(maj, min)
 #define        _sysconf(a)             sysconf(a)
-#define        __NORETURN              __attribute__((noreturn))
 
 /*
  * Compatibility macros/typedefs needed for Solaris -> Linux port
index c58b2d56600f13c281e8cbc5a2dc506a3aa1d885..7fb53730f850f8490d22944de4e1c4c657050d9d 100644 (file)
 #ifndef _LIBSPL_SYS_TYPES_H
 #define        _LIBSPL_SYS_TYPES_H
 
+#if defined(HAVE_MAKEDEV_IN_SYSMACROS)
+#include <sys/sysmacros.h>
+#elif defined(HAVE_MAKEDEV_IN_MKDEV)
+#include <sys/mkdev.h>
+#endif
+
 #include <sys/isa_defs.h>
 #include <sys/feature_tests.h>
 #include_next <sys/types.h>