[PATCH 1/2] Use -isystem for linux-headers dir

Eduardo Habkost posted 2 patches 5 years, 11 months ago
There is a newer version of this series
[PATCH 1/2] Use -isystem for linux-headers dir
Posted by Eduardo Habkost 5 years, 11 months ago
glibc and Linux-provided headers are known to generate macro
redefinition warnings when used together.  For example:
<linux/mman.h> and <sys/mman.h> duplicate some macro definitions.

We normally never see those warnings because GCC suppresses
warnings generated by system headers.  We carry our own copy of
Linux header files, though, and this makes those warnings not be
suppressed when glibc headers are included before Linux headers
(e.g. if <sys/mman.h> is included before <linux/mman.h>).

Use -isystem instead of -I for linux-headers.  This makes the
compiler treat our linux-headers directory the same way it treats
system-provided Linux headers, and suppress warnings generated by
them.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 Makefile.target | 2 +-
 configure       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 2d43dc586a..934a9f7431 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -12,7 +12,7 @@ endif
 
 $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
 ifdef CONFIG_LINUX
-QEMU_CFLAGS += -I../linux-headers
+QEMU_CFLAGS += -isystem ../linux-headers
 endif
 QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
 
diff --git a/configure b/configure
index cbf864bff1..04a2a7f2dd 100755
--- a/configure
+++ b/configure
@@ -899,7 +899,7 @@ Linux)
   linux="yes"
   linux_user="yes"
   kvm="yes"
-  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
+  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
   supported_os="yes"
   libudev="yes"
 ;;
-- 
2.24.1


Re: [PATCH 1/2] Use -isystem for linux-headers dir
Posted by Michael S. Tsirkin 5 years, 11 months ago
On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> glibc and Linux-provided headers are known to generate macro
> redefinition warnings when used together.  For example:
> <linux/mman.h> and <sys/mman.h> duplicate some macro definitions.
> 
> We normally never see those warnings because GCC suppresses
> warnings generated by system headers.  We carry our own copy of
> Linux header files, though, and this makes those warnings not be
> suppressed when glibc headers are included before Linux headers
> (e.g. if <sys/mman.h> is included before <linux/mman.h>).
> 
> Use -isystem instead of -I for linux-headers.  This makes the
> compiler treat our linux-headers directory the same way it treats
> system-provided Linux headers, and suppress warnings generated by
> them.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  Makefile.target | 2 +-
>  configure       | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile.target b/Makefile.target
> index 2d43dc586a..934a9f7431 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -12,7 +12,7 @@ endif
>  
>  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
>  ifdef CONFIG_LINUX
> -QEMU_CFLAGS += -I../linux-headers
> +QEMU_CFLAGS += -isystem ../linux-headers
>  endif
>  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
>  
> diff --git a/configure b/configure
> index cbf864bff1..04a2a7f2dd 100755
> --- a/configure
> +++ b/configure
> @@ -899,7 +899,7 @@ Linux)
>    linux="yes"
>    linux_user="yes"
>    kvm="yes"
> -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"

Shouldn't both be -isystem?

>    supported_os="yes"
>    libudev="yes"
>  ;;
> -- 
> 2.24.1


Re: [PATCH 1/2] Use -isystem for linux-headers dir
Posted by Eduardo Habkost 5 years, 11 months ago
On Wed, Mar 11, 2020 at 07:05:45PM -0400, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> > glibc and Linux-provided headers are known to generate macro
> > redefinition warnings when used together.  For example:
> > <linux/mman.h> and <sys/mman.h> duplicate some macro definitions.
> > 
> > We normally never see those warnings because GCC suppresses
> > warnings generated by system headers.  We carry our own copy of
> > Linux header files, though, and this makes those warnings not be
> > suppressed when glibc headers are included before Linux headers
> > (e.g. if <sys/mman.h> is included before <linux/mman.h>).
> > 
> > Use -isystem instead of -I for linux-headers.  This makes the
> > compiler treat our linux-headers directory the same way it treats
> > system-provided Linux headers, and suppress warnings generated by
> > them.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  Makefile.target | 2 +-
> >  configure       | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/Makefile.target b/Makefile.target
> > index 2d43dc586a..934a9f7431 100644
> > --- a/Makefile.target
> > +++ b/Makefile.target
> > @@ -12,7 +12,7 @@ endif
> >  
> >  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
> >  ifdef CONFIG_LINUX
> > -QEMU_CFLAGS += -I../linux-headers
> > +QEMU_CFLAGS += -isystem ../linux-headers
> >  endif
> >  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
> >  
> > diff --git a/configure b/configure
> > index cbf864bff1..04a2a7f2dd 100755
> > --- a/configure
> > +++ b/configure
> > @@ -899,7 +899,7 @@ Linux)
> >    linux="yes"
> >    linux_user="yes"
> >    kvm="yes"
> > -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> > +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> 
> Shouldn't both be -isystem?

I haven't noticed we had both.

This line looks weird, does anybody know why we have
$PWD/linux-headers here?

-- 
Eduardo


Re: [PATCH 1/2] Use -isystem for linux-headers dir
Posted by Michael S. Tsirkin 5 years, 11 months ago
On Wed, Mar 11, 2020 at 07:08:06PM -0400, Eduardo Habkost wrote:
> On Wed, Mar 11, 2020 at 07:05:45PM -0400, Michael S. Tsirkin wrote:
> > On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> > > glibc and Linux-provided headers are known to generate macro
> > > redefinition warnings when used together.  For example:
> > > <linux/mman.h> and <sys/mman.h> duplicate some macro definitions.
> > > 
> > > We normally never see those warnings because GCC suppresses
> > > warnings generated by system headers.  We carry our own copy of
> > > Linux header files, though, and this makes those warnings not be
> > > suppressed when glibc headers are included before Linux headers
> > > (e.g. if <sys/mman.h> is included before <linux/mman.h>).
> > > 
> > > Use -isystem instead of -I for linux-headers.  This makes the
> > > compiler treat our linux-headers directory the same way it treats
> > > system-provided Linux headers, and suppress warnings generated by
> > > them.
> > > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  Makefile.target | 2 +-
> > >  configure       | 2 +-
> > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/Makefile.target b/Makefile.target
> > > index 2d43dc586a..934a9f7431 100644
> > > --- a/Makefile.target
> > > +++ b/Makefile.target
> > > @@ -12,7 +12,7 @@ endif
> > >  
> > >  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
> > >  ifdef CONFIG_LINUX
> > > -QEMU_CFLAGS += -I../linux-headers
> > > +QEMU_CFLAGS += -isystem ../linux-headers
> > >  endif
> > >  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
> > >  
> > > diff --git a/configure b/configure
> > > index cbf864bff1..04a2a7f2dd 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -899,7 +899,7 @@ Linux)
> > >    linux="yes"
> > >    linux_user="yes"
> > >    kvm="yes"
> > > -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> > > +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> > 
> > Shouldn't both be -isystem?
> 
> I haven't noticed we had both.
> 
> This line looks weird, does anybody know why we have
> $PWD/linux-headers here?

Look at the build directory and you'll figure it out:

$ ls -l $PWD/linux-headers/
total 0
lrwxrwxrwx. 1 mst mst 31 Mar 10 05:59 asm -> /scm/qemu/linux-headers/asm-x86


Introduced here:

commit a585140dd546ffb606ec506b362ab9decf1ab14e
Author: Alexey Kardashevskiy <aik@ozlabs.ru>
Date:   Wed May 29 23:30:43 2013 +1000

    qemu: fix out of tree cross compile
    
    The symlink to "asm" platform linux headers is made in the build tree by
    the configure script but gcc is not told to look for them there.
    
    The patch fixes this.
    
    Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
    Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

-- 
MST


Re: [PATCH 1/2] Use -isystem for linux-headers dir
Posted by Eduardo Habkost 5 years, 11 months ago
On Wed, Mar 11, 2020 at 07:08:06PM -0400, Eduardo Habkost wrote:
> On Wed, Mar 11, 2020 at 07:05:45PM -0400, Michael S. Tsirkin wrote:
> > On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> > > glibc and Linux-provided headers are known to generate macro
> > > redefinition warnings when used together.  For example:
> > > <linux/mman.h> and <sys/mman.h> duplicate some macro definitions.
> > > 
> > > We normally never see those warnings because GCC suppresses
> > > warnings generated by system headers.  We carry our own copy of
> > > Linux header files, though, and this makes those warnings not be
> > > suppressed when glibc headers are included before Linux headers
> > > (e.g. if <sys/mman.h> is included before <linux/mman.h>).
> > > 
> > > Use -isystem instead of -I for linux-headers.  This makes the
> > > compiler treat our linux-headers directory the same way it treats
> > > system-provided Linux headers, and suppress warnings generated by
> > > them.
> > > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  Makefile.target | 2 +-
> > >  configure       | 2 +-
> > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/Makefile.target b/Makefile.target
> > > index 2d43dc586a..934a9f7431 100644
> > > --- a/Makefile.target
> > > +++ b/Makefile.target
> > > @@ -12,7 +12,7 @@ endif
> > >  
> > >  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
> > >  ifdef CONFIG_LINUX
> > > -QEMU_CFLAGS += -I../linux-headers
> > > +QEMU_CFLAGS += -isystem ../linux-headers
> > >  endif
> > >  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
> > >  
> > > diff --git a/configure b/configure
> > > index cbf864bff1..04a2a7f2dd 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -899,7 +899,7 @@ Linux)
> > >    linux="yes"
> > >    linux_user="yes"
> > >    kvm="yes"
> > > -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> > > +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES"
> > 
> > Shouldn't both be -isystem?
> 
> I haven't noticed we had both.
> 
> This line looks weird, does anybody know why we have
> $PWD/linux-headers here?

This is why:

commit a585140dd546ffb606ec506b362ab9decf1ab14e
Author: Alexey Kardashevskiy <aik@ozlabs.ru>
Date:   Wed May 29 23:30:43 2013 +1000

   qemu: fix out of tree cross compile

   The symlink to "asm" platform linux headers is made in the build tree by
   the configure script but gcc is not told to look for them there.

   The patch fixes this.

   Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
   Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

-- 
Eduardo