So it looks like that for some reason, the QEMU linux-headers directory is not in the include search path for this compilation command, and that the system-or-sysroot provided <linux/vhost.h> is picked instead. Fixing this might be a better long-term fix than what I am proposing in this patch. I am not sure how to do that yet though. Do you have any recommendations?
On Fri, Apr 7, 2023 at 11:25 AM David Turner <di...@google.com> wrote: > I meant glibc-2.17, I am using a sysroot to ensure the generated binaries > run on older Linux distributions. > > On Fri, Apr 7, 2023 at 11:24 AM David Turner <di...@google.com> wrote: > >> The <linux/vhost.h> of glib-2.17 begins with: >> >> #ifndef _LINUX_VHOST_H >> #define _LINUX_VHOST_H >> /* Userspace interface for in-kernel virtio accelerators. */ >> /* vhost is used to reduce the number of system calls involved in virtio. >> * >> * Existing virtio net code is used in the guest without modification. >> * >> * This header includes interface used by userspace hypervisor for >> * device configuration. >> */ >> #include <linux/types.h> >> #include <linux/ioctl.h> >> #include <linux/virtio_config.h> >> #include <linux/virtio_ring.h> >> >> >> See >> https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/+/refs/heads/master/sysroot/usr/include/linux/vhost.h >> >> Here's the compilation error I get in this case: >> >> FAILED: subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o >> >> /src/prebuilts/clang/clang-r487747/bin/clang --sysroot=/out/sysroot -m64 >> -mcx16 -Isubprojects/libvhost-user/libvhost-user.a.p >> -Isubprojects/libvhost-user -I../../ >> src/third_party/qemu/subprojects/libvhost-user >> -I/out/dest-install/usr/include -fcolor-diagnostics -Wall -Winvalid-pch >> -std=gnu99 -O2 -g -Wsign-compare -Wdeclarat >> ion-after-statement -Wstrict-aliasing -fno-pie -D_FILE_OFFSET_BITS=64 >> -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -Wundef >> -Wwrite-strings -Wmissi >> ng-prototypes -Wstrict-prototypes -Wredundant-decls >> -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k >> -Winit-self -Wignored-qualifiers -Wempty-b >> ody -Wnested-externs -Wendif-labels -Wexpansion-to-defined >> -Wmissing-format-attribute -Wthread-safety -Wno-initializer-overrides >> -Wno-missing-include-dirs -Wno-sh >> ift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition >> -Wno-tautological-type-limit-compare -Wno-psabi >> -Wno-gnu-variable-sized-type-not-at-end -fstack- >> protector-strong -pthread -D_GNU_SOURCE -MD -MQ >> subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o -MF >> subprojects/libvhost-user/libvhost-user.a.p/libv >> host-user.c.o.d -o >> subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o -c >> ../../src/third_party/qemu/subprojects/libvhost-user/libvhost-user.c >> >> ../../src/third_party/qemu/subprojects/libvhost-user/libvhost-user.c:529:17: >> error: use of undeclared identifier 'VIRTIO_F_VERSION_1' >> >> 1ULL << VIRTIO_F_VERSION_1 | >> >> ^ >> ../../src/third_party/qemu/subprojects/libvhost-user/libvhost-user.c:563:30: >> error: use of undeclared identifier 'VIRTIO_F_VERSION_1' >> >> if (!vu_has_feature(dev, VIRTIO_F_VERSION_1)) { >> >> ^ >> ../../src/third_party/qemu/subprojects/libvhost-user/libvhost-user.c:632:22: >> warning: unused variable 'dev_region' [-Wunused-variable] >> >> VuDevRegion *dev_region = &dev->regions[i]; >> >> ^ >> ../../src/third_party/qemu/subprojects/libvhost-user/libvhost-user.c:633:13: >> warning: unused variable 'ret' [-Wunused-variable] >> >> int ret; >> >> ^ >> 2 warnings and 2 errors generated. >> >> >> On Fri, Apr 7, 2023 at 10:03 AM Michael S. Tsirkin <m...@redhat.com> >> wrote: >> >>> If you are reposting, please version patchsets, E.g. >>> -v2 flag for git format-patch will enerate [PATCH v2] for you. >>> >>> Repeating what I said on previous version: >>> >>> On Wed, Apr 05, 2023 at 07:21:07PM +0200, David 'Digit' Turner wrote: >>> > The source file uses VIRTIO_F_VERSION_1 which is >>> > not defined by <linux/virtio_config.h> on Debian 10. >>> > >>> > The system-provided <linux/virtio_config.h> which >>> > does not include the macro definition is included >>> > through <linux/vhost.h>, so fix the issue by including >>> > the standard-headers version before that. >>> > >>> > Signed-off-by: David 'Digit' Turner <di...@google.com> >>> >>> This happens to work usually but there's no guarantee >>> "standard-headers/linux/virtio_config.h" >>> and <linux/virtio_config.h> are interchangeable or >>> even do not conflict. >>> >>> But where is <linux/vhost.h> using <linux/virtio_config.h>? >>> Everyone should be using "standard-headers/linux/virtio_config.h". >>> >>> >>> > --- >>> > subprojects/libvhost-user/libvhost-user.c | 6 ++++++ >>> > 1 file changed, 6 insertions(+) >>> > >>> > diff --git a/subprojects/libvhost-user/libvhost-user.c >>> b/subprojects/libvhost-user/libvhost-user.c >>> > index 0200b78e8e..0a5768cb55 100644 >>> > --- a/subprojects/libvhost-user/libvhost-user.c >>> > +++ b/subprojects/libvhost-user/libvhost-user.c >>> > @@ -32,6 +32,12 @@ >>> > #include <sys/mman.h> >>> > #include <endian.h> >>> > >>> > +/* Necessary to provide VIRTIO_F_VERSION_1 on system >>> > + * with older linux headers. Must appear before >>> > + * <linux/vhost.h> below. >>> > + */ >>> > +#include "standard-headers/linux/virtio_config.h" >>> > + >>> > #if defined(__linux__) >>> > #include <sys/syscall.h> >>> > #include <fcntl.h> >>> > -- >>> > 2.40.0.348.gf938b09366-goog >>> >>>