Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | From b859ab1b211d348b46eca9158b7742f050c8115e Mon Sep 17 00:00:00 2001 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | From: Eric Blake <eblake@redhat.com> |
| 3 | Date: Wed, 14 Sep 2016 08:17:06 -0500 |
| 4 | Subject: [PATCH] AC_HEADER_MAJOR: port to glibc 2.25 |
| 5 | |
| 6 | glibc 2.25 is deprecating the namespace pollution of <sys/types.h> |
| 7 | injecting major(), minor(), and makedev() into the compilation |
| 8 | environment, with a warning that insists that users include |
| 9 | <sys/sysmacros.h> instead. However, because the expansion of |
| 10 | AC_HEADER_MAJOR didn't bother checking sys/sysmacros.h until |
| 11 | after probing whether sys/types.h pollutes the namespace, it was |
| 12 | not defining MAJOR_IN_SYSMACROS, with the result that code |
| 13 | compiled with -Werror chokes on the deprecation warnings because |
| 14 | it was not including sysmacros.h. |
| 15 | |
| 16 | In addition to fixing autoconf (which only benefits projects |
| 17 | that rebuild configure after this fix is released), we can also |
| 18 | give a hint to distros on how they can populate config.site with |
| 19 | a cache variable to force pre-existing configure scripts without |
| 20 | the updated macro to behave sanely in the presence of glibc 2.25 |
| 21 | (the documentation is especially useful since that cache variable |
| 22 | is no longer present in autoconf after this patch). |
| 23 | |
| 24 | Note that mingw lacks major/minor/makedev in any of its standard |
| 25 | headers; for that platform, the behavior of this macro is unchanged |
| 26 | (code using the recommended include formula will get a compile error |
| 27 | when trying to use major(), whether before or after this patch); but |
| 28 | for now, it is assumed that programs actually concerned with |
| 29 | creating devices are not worried about portability to mingw. If |
| 30 | desired, a later patch could tighten AC_HEADER_MAJOR to fail at |
| 31 | configure time if the macros are unavailable in any of the three |
| 32 | system headers, but that semantic change is not worth mixing into |
| 33 | this patch. |
| 34 | |
| 35 | * lib/autoconf/headers.m4 (AC_HEADER_MAJOR): Drop check for |
| 36 | major within sys/types.h; it interferes with the need to check |
| 37 | sysmacros.h first. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | |
| 39 | Signed-off-by: Eric Blake <eblake@redhat.com> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 40 | |
| 41 | Remove the documentation change from the patch |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | Upstream-Status: Backport |
| 43 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 44 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> |
| 45 | --- |
| 46 | lib/autoconf/headers.m4 | 30 ++++++++++++++---------------- |
| 47 | 1 file changed, 14 insertions(+), 16 deletions(-) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 49 | diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4 |
| 50 | index 81a7fa2..a57d0d3 100644 |
| 51 | --- a/lib/autoconf/headers.m4 |
| 52 | +++ b/lib/autoconf/headers.m4 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | @@ -502,31 +502,29 @@ fi |
| 54 | |
| 55 | # AC_HEADER_MAJOR |
| 56 | # --------------- |
| 57 | +# Thanks to glibc 2.25 deprecating macros in sys/types.h, coupled with |
| 58 | +# back-compat to autoconf 2.69, we need the following logic: |
| 59 | +# Check whether <sys/types.h> compiles. |
| 60 | +# If <sys/mkdev.h> compiles, assume it provides major/minor/makedev. |
| 61 | +# Otherwise, if <sys/sysmacros.h> compiles, assume it provides the macros. |
| 62 | +# Otherwise, either the macros were provided by <sys/types.h>, or do |
| 63 | +# not exist on the platform. Code trying to use these three macros is |
| 64 | +# assumed to not care about platforms that lack the macros. |
| 65 | AN_FUNCTION([major], [AC_HEADER_MAJOR]) |
| 66 | AN_FUNCTION([makedev], [AC_HEADER_MAJOR]) |
| 67 | AN_FUNCTION([minor], [AC_HEADER_MAJOR]) |
| 68 | AN_HEADER([sys/mkdev.h], [AC_HEADER_MAJOR]) |
| 69 | AC_DEFUN([AC_HEADER_MAJOR], |
| 70 | -[AC_CACHE_CHECK(whether sys/types.h defines makedev, |
| 71 | - ac_cv_header_sys_types_h_makedev, |
| 72 | -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <sys/types.h>]], |
| 73 | - [[return makedev(0, 0);]])], |
| 74 | - [ac_cv_header_sys_types_h_makedev=yes], |
| 75 | - [ac_cv_header_sys_types_h_makedev=no]) |
| 76 | -]) |
| 77 | - |
| 78 | -if test $ac_cv_header_sys_types_h_makedev = no; then |
| 79 | +[AC_CHECK_HEADERS_ONCE([sys/types.h]) |
| 80 | AC_CHECK_HEADER(sys/mkdev.h, |
| 81 | [AC_DEFINE(MAJOR_IN_MKDEV, 1, |
| 82 | [Define to 1 if `major', `minor', and `makedev' are |
| 83 | declared in <mkdev.h>.])]) |
| 84 | - |
| 85 | - if test $ac_cv_header_sys_mkdev_h = no; then |
| 86 | - AC_CHECK_HEADER(sys/sysmacros.h, |
| 87 | - [AC_DEFINE(MAJOR_IN_SYSMACROS, 1, |
| 88 | - [Define to 1 if `major', `minor', and `makedev' |
| 89 | - are declared in <sysmacros.h>.])]) |
| 90 | - fi |
| 91 | +if test $ac_cv_header_sys_mkdev_h = no; then |
| 92 | + AC_CHECK_HEADER(sys/sysmacros.h, |
| 93 | + [AC_DEFINE(MAJOR_IN_SYSMACROS, 1, |
| 94 | + [Define to 1 if `major', `minor', and `makedev' |
| 95 | + are declared in <sysmacros.h>.])]) |
| 96 | fi |
| 97 | ])# AC_HEADER_MAJOR |
| 98 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 99 | -- |
| 100 | 2.7.4 |
| 101 | |