abumandour
abumandour

Reputation: 1369

Configuring qemu build results in an "Error: configure test passed without -Werror but failed with -Werror."

I'm trying to build qemu from sources, I use ./configure --enable-capstone --enable-tcg-plugin --target-list=x86_64-linux-user to configure it before building using make.

This results in the following error:

ERROR: configure test passed without -Werror but failed with -Werror.
       This is probably a bug in the configure script. The failing command
       will be at the bottom of config.log.
       You can run configure with --disable-werror to bypass this check.

This is the bottom of the config.log file:

config-temp/qemu-conf.c: In function ‘main’:
config-temp/qemu-conf.c:2:25: warning: null argument where non-null required (argument 1) [-Wnonnull]
    2 | int main(void) { return sem_timedwait(0, 0); }
      |                         ^~~~~~~~~~~~~
config-temp/qemu-conf.c:2:25: warning: null argument where non-null required (argument 2) [-Wnonnull]
cc -Werror -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wno-error=address-of-packed-member -Wexpansion-to-defined -Wendif-labels -Wno-shift-negative-value -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/include/capstone -o config-temp/qemu-conf.exe config-temp/qemu-conf.c -Wl,-z,relro -Wl,-z,now -pie -m64 -g
config-temp/qemu-conf.c: In function ‘main’:
config-temp/qemu-conf.c:2:25: error: null argument where non-null required (argument 1) [-Werror=nonnull]
    2 | int main(void) { return sem_timedwait(0, 0); }
      |                         ^~~~~~~~~~~~~
config-temp/qemu-conf.c:2:25: error: null argument where non-null required (argument 2) [-Werror=nonnull]
cc1: all warnings being treated as errors
~                                                                                                                                                                                                                  
~                                      

I also tried to --disable-werror, this configures well, but does not build. it gives the following errors while building:

/home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/syscall.c:256:16: error: static declaration of ‘gettid’ follows non-static declaration
  256 | _syscall0(int, gettid)
      |                ^~~~~~
/home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/syscall.c:187:13: note: in definition of macro ‘_syscall0’
  187 | static type name (void)   \
      |             ^~~~
In file included from /usr/include/unistd.h:1170,
                 from /home/p/Desktop/qemu-plugins-tutorial/qemu/include/qemu/osdep.h:90,
                 from /home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/syscall.c:20:
/usr/include/x86_64-linux-gnu/bits/unistd_ext.h:34:16: note: previous declaration of ‘gettid’ was here
   34 | extern __pid_t gettid (void) __THROW;
      |                ^~~~~~
/home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/ioctls.h:224:9: error: ‘SIOCGSTAMP’ undeclared here (not in a function); did you mean ‘SIOCSRARP’?
  224 |   IOCTL(SIOCGSTAMP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timeval)))
      |         ^~~~~~~~~~
/home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/syscall.c:4756:23: note: in definition of macro ‘IOCTL’
 4756 |     { TARGET_ ## cmd, cmd, #cmd, access, 0, {  __VA_ARGS__ } },
      |                       ^~~
/home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/ioctls.h:225:9: error: ‘SIOCGSTAMPNS’ undeclared here (not in a function); did you mean ‘SIOCGSTAMP_OLD’?
  225 |   IOCTL(SIOCGSTAMPNS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_timespec)))
      |         ^~~~~~~~~~~~
/home/p/Desktop/qemu-plugins-tutorial/qemu/linux-user/syscall.c:4756:23: note: in definition of macro ‘IOCTL’
 4756 |     { TARGET_ ## cmd, cmd, #cmd, access, 0, {  __VA_ARGS__ } },
      |                       ^~~
  CC      x86_64-linux-user/linux-user/strace.o
make[1]: *** [/home/p/Desktop/qemu-plugins-tutorial/qemu/rules.mak:69: linux-user/syscall.o] Error 1
make[1]: *** Waiting for unfinished jobs....
  LINK    qemu-img
make: *** [Makefile:484: subdir-x86_64-linux-user] Error 2

What would be a possible fix for this?

Upvotes: 0

Views: 1511

Answers (1)

Peter Maydell
Peter Maydell

Reputation: 11383

The reason for this is that you're trying to build a pretty old version of QEMU against a more recent glibc. Occasionally glibc header changes cause errors in QEMU code that used to compile, and so QEMU is changed to avoid the problem. In this specific case, when glibc 2.29 (or thereabouts) added a gettid() function, this broke the bit of QEMU code that was defining its own function of that name. QEMU commit 71ba74f67eaca21b, from March 2019, is the upstream fix for that.

The simple fix though is: don't try to build really old QEMU: build the most recent version.

If you do have for some reason to build an old QEMU on a newer distro, you should be prepared to have to fix up or work around a few build errors of this form. A couple of techniques for making this easier:

  • if you have a choice of host distro, avoid bleeding-edge ones (eg an older Ubuntu LTS is going to have fewer problems than most-recent Fedora)
  • if you don't care about the feature in the bit of code that is falling over, use configure options to disable it (in this case unless you need the user-mode emulators you could disable them with a suitable --target-list setting)
  • search the upstream QEMU git commit logs and the qemu-devel mailing list archives for the error messages you see: usually you will find the fix, and you can then cherry-pick or adapt it for the version you're having to build

Upvotes: 1

Related Questions