autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] AC_HEADER_MAJOR: port to glibc 2.25


From: Eric Blake
Subject: [PATCH] AC_HEADER_MAJOR: port to glibc 2.25
Date: Wed, 14 Sep 2016 08:26:25 -0500

glibc 2.25 is deprecating the namespace pollution of sys/types.h
injecting major(), minor(), and makedev() into the compilation
environment, with a warning that insists that users include
<sys/sysmacros.h> instead.  However, because the expansion of
AC_HEADER_MAJOR didn't bother checking sys/sysmacros.h until
after probing whether sys/types.h pollutes the namespace, it was
not defining MAJOR_IN_SYSMACROS, with the result that code
compiled with -Werror chokes on the deprecation warnings because
it was not including sysmacros.h.

In addition to fixing autoconf (which only benefits projects
that rebuild configure after this fix is released), we can also
give a hint to distros on how they can populate config.site with
a cache variable to force pre-existing configure scripts without
the updated macro to behave sanely in the presence of glibc 2.25.

* lib/autoconf/headers.m4 (AC_HEADER_MAJOR): Check for sysmacros.h
first, rather than after determining if sys/types.h pollutes the
namespace.
* doc/autoconf.texi (Particular Headers) <AC_HEADER_MAJOR>: Expand
details on usage, and on workarounds for non-updated projects.

Signed-off-by: Eric Blake <address@hidden>
---

I'd like a review on this patch before pushing it; meanwhile,
I'm in the middle of testing that the new definition of
AC_HEADER_MAJOR, when ported to gnulib, is sufficient to solve
the libvirt build failure.

For this patch, I kept the status quo of assuming that if
sys/sysmacros.h exists, then it probably defines major/minor/makedev;
if you want me to rework the patch to explicitly check that this
is the case, I can do that as well (probably best as a followup
patch, in case downstreams want to backport one idea without the
other).

 doc/autoconf.texi       | 21 +++++++++++++++++++++
 lib/autoconf/headers.m4 | 40 +++++++++++++++++++++-------------------
 2 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 029ddd6..f2494d8 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -5977,6 +5977,27 @@ Particular Headers
 @code{makedev}, but @file{sys/mkdev.h} does, define
 @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
 @code{MAJOR_IN_SYSMACROS}.
+
+To properly use any of these three functions, your code should contain
+something like:
+
address@hidden
+#include <sys/types.h>
+#ifdef MAJOR_IN_MKDEV
+# include <sys/mkdev.h>
+#elif MAJOR_IN_SYSMACROS
+# include <sys/sysmacros.h>
+#endif
address@hidden verbatim
+
+Note that glibc 2.25 issues a deprecation warning if these functions are
+used from @file{sys/types.h} without also using @file{sys/sysmacros.h},
+but that configure scripts built with versions of autoconf prior to 2.70
+did not correctly define @code{MAJOR_IN_SYSMACROS} in that scenario; on
+systems where that is a problem, you can use the workaround of priming
+the configure cache by setting @code{ac_cv_header_sys_types_h_makedev}
+to 'no', perhaps as part of a @file{config.site} site default file
+(@pxref{Site Defaults}).
 @end defmac

 @defmac AC_HEADER_RESOLV
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 0c44973..f1ed051 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -427,30 +427,32 @@ fi

 # AC_HEADER_MAJOR
 # ---------------
+# Thanks to glibc 2.25, we need the following logic:
+# If <sys/sysmacros.h> compiles, assume it provides the macros.
+# Otherwise, if <sys/types.h> provides them, nothing further to do.
+# Otherwise, if <sys/mkdev.h> exists, assume it provides the macros.
 AN_FUNCTION([major],     [AC_HEADER_MAJOR])
 AN_FUNCTION([makedev],   [AC_HEADER_MAJOR])
 AN_FUNCTION([minor],     [AC_HEADER_MAJOR])
 AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR])
 AC_DEFUN([AC_HEADER_MAJOR],
-[AC_CACHE_CHECK(whether sys/types.h defines makedev,
-               ac_cv_header_sys_types_h_makedev,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM(address@hidden:@include <sys/types.h>]],
-                                [[return makedev(0, 0);]])],
-               [ac_cv_header_sys_types_h_makedev=yes],
-               [ac_cv_header_sys_types_h_makedev=no])
-])
-
-if test $ac_cv_header_sys_types_h_makedev = no; then
-AC_CHECK_HEADER(sys/mkdev.h,
-               [AC_DEFINE(MAJOR_IN_MKDEV, 1,
-                          [Define to 1 if `major', `minor', and `makedev' are
-                           declared in <mkdev.h>.])])
-
-  if test $ac_cv_header_sys_mkdev_h = no; then
-    AC_CHECK_HEADER(sys/sysmacros.h,
-                   [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
-                              [Define to 1 if `major', `minor', and `makedev'
-                               are declared in <sysmacros.h>.])])
+[AC_CHECK_HEADER(sys/sysmacros.h,
+                [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
+                           [Define to 1 if `major', `minor', and `makedev'
+                            are declared in <sysmacros.h>.])])
+if test $ac_cv_header_sys_sysmacros_h = no; then
+  AC_CACHE_CHECK(whether sys/types.h defines makedev,
+                ac_cv_header_sys_types_h_makedev,
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM(address@hidden:@include <sys/types.h>]],
+                                  [[return makedev(0, 0);]])],
+                 [ac_cv_header_sys_types_h_makedev=yes],
+                 [ac_cv_header_sys_types_h_makedev=no])
+  ])
+  if test $ac_cv_header_sys_types_h_makedev = no; then
+  AC_CHECK_HEADER(sys/mkdev.h,
+                 [AC_DEFINE(MAJOR_IN_MKDEV, 1,
+                            [Define to 1 if `major', `minor', and `makedev'
+                             are declared in <mkdev.h>.])])
   fi
 fi
 ])# AC_HEADER_MAJOR
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]