Discussion:
getopt broken when building with glibc 2.25.90
Daniel P. Berrange
2017-06-02 16:25:20 UTC
Permalink
Fedora rawhide is now shipping with glibc 2.25.90 and when trying to
build libvirt with gnulib's getopt module, it crashes & burns

CC getopt.lo
In file included from ./getopt.h:57:0,
from ../../../gnulib/lib/getopt.c:26:
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c: In function 'process_long_option':
../../../gnulib/lib/getopt.c:213:38: error: dereferencing pointer to incomplete type 'const struct rpl_option'
for (p = longopts, n_options = 0; p->name; p++, n_options++)
^~
../../../gnulib/lib/getopt.c:213:47: error: increment of pointer to an incomplete type 'const struct rpl_option'
for (p = longopts, n_options = 0; p->name; p++, n_options++)
^~
../../../gnulib/lib/getopt.c:231:54: error: increment of pointer to an incomplete type 'const struct rpl_option'
for (p = longopts, option_index = 0; p->name; p++, option_index++)
^~
../../../gnulib/lib/getopt.c:291:27: error: invalid use of undefined type 'struct rpl_option'
prefix, longopts[option_index].name);
^
../../../gnulib/lib/getopt.c:291:27: error: dereferencing pointer to incomplete type 'const struct rpl_option'
In file included from ./getopt.h:57:0,
from ../../../gnulib/lib/getopt.c:26:
../../../gnulib/lib/getopt.c: At top level:
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c:472:1: error: conflicting types for '_getopt_internal_r'
_getopt_internal_r (int argc, char **argv, const char *optstring,
^~~~~~~~~~~~~~~~~~
In file included from ../../../gnulib/lib/getopt.c:82:0:
../../../gnulib/lib/getopt_int.h:100:12: note: previous declaration of '_getopt_internal_r' was here
extern int _getopt_internal_r (int ___argc, char **___argv,
^~~~~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c: In function '_getopt_internal_r':
../../../gnulib/lib/getopt.c:575:59: warning: passing argument 4 of 'process_long_option' from incompatible pointer type [-Wincompatible-pointer-types]
return process_long_option (argc, argv, optstring, longopts,
^~~~~~~~
../../../gnulib/lib/getopt.c:195:1: note: expected 'const struct rpl_option *' but argument is of type 'const struct rpl_option *'
process_long_option (int argc, char **argv, const char *optstring,
^~~~~~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c:597:59: warning: passing argument 4 of 'process_long_option' from incompatible pointer type [-Wincompatible-pointer-types]
code = process_long_option (argc, argv, optstring, longopts,
^~~~~~~~
../../../gnulib/lib/getopt.c:195:1: note: expected 'const struct rpl_option *' but argument is of type 'const struct rpl_option *'
process_long_option (int argc, char **argv, const char *optstring,
^~~~~~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c:652:53: warning: passing argument 4 of 'process_long_option' from incompatible pointer type [-Wincompatible-pointer-types]
return process_long_option (argc, argv, optstring, longopts, longind,
^~~~~~~~
../../../gnulib/lib/getopt.c:195:1: note: expected 'const struct rpl_option *' but argument is of type 'const struct rpl_option *'
process_long_option (int argc, char **argv, const char *optstring,
^~~~~~~~~~~~~~~~~~~
In file included from ./getopt.h:57:0,
from ../../../gnulib/lib/getopt.c:26:
../../../gnulib/lib/getopt.c: At top level:
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
^~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c:704:1: error: conflicting types for '_getopt_internal'
_getopt_internal (int argc, char **argv, const char *optstring,
^~~~~~~~~~~~~~~~
In file included from ../../../gnulib/lib/getopt.c:82:0:
../../../gnulib/lib/getopt_int.h:24:12: note: previous declaration of '_getopt_internal' was here
extern int _getopt_internal (int ___argc, char **___argv,
^~~~~~~~~~~~~~~~
../../../gnulib/lib/getopt.c: In function '_getopt_internal':
../../../gnulib/lib/getopt.c:713:55: warning: passing argument 4 of '_getopt_internal_r' from incompatible pointer type [-Wincompatible-pointer-types]
result = _getopt_internal_r (argc, argv, optstring, longopts,
^~~~~~~~
../../../gnulib/lib/getopt.c:472:1: note: expected 'const struct rpl_option *' but argument is of type 'const struct rpl_option *'
_getopt_internal_r (int argc, char **argv, const char *optstring,
^~~~~~~~~~~~~~~~~~



If I remove the include_next call that pulls in the system getopt.h
header file, it all works fine. ie edit gnulib/lib/getopt.in.h to
remove:

# include_next <getopt.h>

The same gnulib code works fine on previous glibc - eg 2.24 version.

Alternatively, if I roll back gnulib to before:

commit e7207fdf6ac20e8228d99248a73816f99ba8ce78 (HEAD)
Author: Zack Weinberg <***@panix.com>
Date: Thu Apr 6 11:14:14 2017 -0700

getopt: split up getopt.in.h and eliminate __need_getopt

then it also works fine.

It appears that the getopt header in glibc 2.25.90 has changed
quite a bit and somehow that's conflicting with gnulib's recent
getopt changes.

Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Paul Eggert
2017-06-02 18:18:04 UTC
Permalink
Post by Daniel P. Berrange
Fedora rawhide is now shipping with glibc 2.25.90 and when trying to
build libvirt with gnulib's getopt module, it crashes & burns
CC getopt.lo
In file included from ./getopt.h:57:0,
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
There is no file getopt_pfx_core.h in current Gnulib, so it sounds like
you have some sort of mixture of old and new Gnulib imported into
libvirt's source directory. suggest ripping out all the old stuff and
importing the latest Gnulib version.

To help debug this, you might try getting the latest Gnulib sources and
running "./gnulib-tool --test getopt" on your rawhide development
platform. If that command doesn't work, it's probably a Gnulib bug; if
the command does work, it's probably something else wrong with your setup.
Daniel P. Berrange
2017-06-05 09:49:16 UTC
Permalink
Post by Daniel P. Berrange
Fedora rawhide is now shipping with glibc 2.25.90 and when trying to
build libvirt with gnulib's getopt module, it crashes & burns
CC getopt.lo
In file included from ./getopt.h:57:0,
../../config.h:2934:25: warning: 'struct rpl_option' declared inside parameter list will not be visible outside of this definition or declaration
#define __GETOPT_PREFIX rpl_
^
../../../gnulib/lib/getopt_pfx_core.h:38:44: note: in expansion of macro '__GETOPT_PREFIX'
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
There is no file getopt_pfx_core.h in current Gnulib, so it sounds like you
have some sort of mixture of old and new Gnulib imported into libvirt's
source directory. suggest ripping out all the old stuff and importing the
latest Gnulib version.
Sorry, these error messages from the point at which I had git bisected the
failure, down to e7207fdf6ac20e8228d99248a73816f99ba8ce78, which is just
before you renamed all the files to use '-' instead of "_". You get the
same compile failure with very latest gnulib. The problem is the header
file conditionals are clashing with system headers, and is fixed by this
patch:

From f574a594b70d1111590949f8ac82d4bc10bc13c6 Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <***@redhat.com>
Date: Mon, 5 Jun 2017 10:41:05 +0100
Subject: [PATCH] getopt: avoid header conditional clash with system headers

The getopt-core.h and getopt-ext.h files are synchronized with
the same files present in glibc. This means they also share the
same "#ifndef _GETOPT_*_H" conditional protection. While the
gnulib header and the glibc header contain the same definitions,
the functional effect of including them is different, because
gnulib arranges for a 'rpl_' prefix to be added to every symbol
in the header.

When compiling gnulib against glibc >= 2.25.90, the system
copy of getopt-core.h and getopt-ext.h will be pulled in first,
via the "#include_next <getopt.h>" statement. When gnulib tries
to include its local getopt-core.h & getopt-ext.h, while applying
symbol renaming, the '#ifndef _GETOPT_*_H' protection causes
the include to be a no-op. Thus when compiling getopt.c, all
of the getopt symbols with a 'rpl_' prefix are missing.

Signed-off-by: Daniel P. Berrange <***@redhat.com>
---
lib/getopt-core.h | 6 +++---
lib/getopt-ext.h | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/getopt-core.h b/lib/getopt-core.h
index 8c9eb51..cab3412 100644
--- a/lib/getopt-core.h
+++ b/lib/getopt-core.h
@@ -17,8 +17,8 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */

-#ifndef _GETOPT_CORE_H
-#define _GETOPT_CORE_H 1
+#ifndef _GL_GETOPT_CORE_H
+#define _GL_GETOPT_CORE_H 1

/* This header should not be used directly; include getopt.h or
unistd.h instead. Unlike most bits headers, it does not have
@@ -93,4 +93,4 @@ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)

__END_DECLS

-#endif /* _GETOPT_CORE_H */
+#endif /* _GL_GETOPT_CORE_H */
diff --git a/lib/getopt-ext.h b/lib/getopt-ext.h
index 94190df..0ded089 100644
--- a/lib/getopt-ext.h
+++ b/lib/getopt-ext.h
@@ -17,8 +17,8 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */

-#ifndef _GETOPT_EXT_H
-#define _GETOPT_EXT_H 1
+#ifndef _GL_GETOPT_EXT_H
+#define _GL_GETOPT_EXT_H 1

/* This header should not be used directly; include getopt.h instead.
Unlike most bits headers, it does not have a protective #error,
@@ -74,4 +74,4 @@ extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,

__END_DECLS

-#endif /* _GETOPT_EXT_H */
+#endif /* _GL_GETOPT_EXT_H */
--
2.9.3




Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Paul Eggert
2017-06-11 22:57:12 UTC
Permalink
Post by Daniel P. Berrange
-#ifndef _GETOPT_CORE_H
-#define _GETOPT_CORE_H 1
+#ifndef _GL_GETOPT_CORE_H
+#define _GL_GETOPT_CORE_H 1
Thanks, but getopt-core.h is supposed to be identical in the glibc version and
the gnulib version, and changes like the above would make it differ. Instead,
how about the attached patch, which I've installed into Gnulib? It affects only
the Gnulib-specific files.

Loading...