[Rpm-maint] [PATCH] config: Detect major/minor warnings and include the correct system header.

Dmitry V. Levin ldv at altlinux.org
Thu Jul 20 14:06:48 UTC 2017


On Wed, Jul 19, 2017 at 02:49:38PM +0200, Mark Wielaard wrote:
> glibc 2.25 introduced (really long and annoying) warnings for each use
> of the major/minor macros from the wrong header:
> 
> lib/cpio.c: In function ‘rpmcpioHeaderWrite’:
> lib/cpio.c:245:13: warning: In the GNU C Library, "major" is defined
>  by <sys/sysmacros.h>. For historical compatibility, it is
>  currently defined by <sys/types.h> as well, but we plan to
>  remove this soon. To use "major", include <sys/sysmacros.h>
>  directly. If you did not intend to use a system-defined macro
>  "major", you should undefine it after including <sys/types.h>.
>      dev = major(st->st_dev); SET_NUM_FIELD(hdr->devMajor, dev, field);
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Adjust the configure check and undef the warning producing macros to get
> rid of the wrong definitions and use the macros from the right include.
> 
> Tested against RHEL7 (glibc 2.17) and Fedora 26 (glibc 2.25).
> 
> Signed-off-by: Mark Wielaard <mark at klomp.org>
> ---
>  configure.ac | 8 ++++++++
>  lib/cpio.c   | 6 ++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/configure.ac b/configure.ac
> index cc657ec..017a908 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -561,7 +561,15 @@ AM_ICONV
>  
>  dnl Checks for header files we can live without.
>  AC_HEADER_STDC
> +dnl glibc and autoconf don't really play well together.
> +dnl glibc will produce a warning when including the wrong header.
> +dnl but still define major and minor. Causing us to include the header
> +dnl that produces a giant warning for each major/minor use.
> +dnl Use -Werror to work around that.
> +old_CFLAGS=$CFLAGS
> +CFLAGS="$CFLAGS -Werror"
>  AC_HEADER_MAJOR
> +CFLAGS=$old_CFLAGS
>  AC_STRUCT_DIRENT_D_TYPE
>  
>  AC_CHECK_HEADERS(limits.h)
> diff --git a/lib/cpio.c b/lib/cpio.c
> index 57c9592..b7ba27d 100644
> --- a/lib/cpio.c
> +++ b/lib/cpio.c
> @@ -9,9 +9,15 @@
>  
>  #include "system.h"
>  
> +/* system.h might already have included the wrong header, undef major
> +   and minor and get the real definition from one of the correct headers. */
>  #if MAJOR_IN_MKDEV
> +#undef major
> +#undef minor
>  #include <sys/mkdev.h>
>  #elif MAJOR_IN_SYSMACROS
> +#undef major
> +#undef minor
>  #include <sys/sysmacros.h>
>  #else
>  #include <sys/types.h> /* already included from system.h */

I'm not sure what sys/mkdev.h does, but glibc's sys/sysmacros.h certainly
undefines major, minor, and makedev prior to defining its own versions of
these macros.

My guess is that these undefs are not needed.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20170720/3c3dccbc/attachment-0001.asc>


More information about the Rpm-maint mailing list