[OE-core] [PATCH 2/2] grub2: fix build with gcc-7

Martin Jansa martin.jansa at gmail.com
Tue Aug 22 17:21:10 UTC 2017


Nothing special on my build host, just gcc 7.1 from gentoo. But the option
was introduced probably only in gcc-7, on 5.4.0 used in Ubuntu 16.04 it's
also missing:

OE qemux86@ ~/oe/world/shr-core $ gcc --help=warnings | grep
expansion-to-defined
OE qemux86@ ~/oe/world/shr-core $ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

OE @ ~ $ gcc --help=warnings | grep expansion-to-defined
  -Wexpansion-to-defined      Warn if "defined" is used outside #if.
OE @ ~ $ gcc --version
gcc (Gentoo 7.1.0-r1 p1.1) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

OE @ ~/build/oe-core/tmp-glibc/work/i586-oe-linux/grub-efi/2.02-r0 $
recipe-sysroot-native/usr/bin/i586-oe-linux/i586-oe-linux-gcc
--help=warnings | grep expansion-to-defined
  -Wexpansion-to-defined      Warn if "defined" is used outside #if.
OE @ ~/build/oe-core/tmp-glibc/work/i586-oe-linux/grub-efi/2.02-r0 $
recipe-sysroot-native/usr/bin/i586-oe-linux/i586-oe-linux-gcc --version
i586-oe-linux-gcc (GCC) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Applying the flags based on `gcc --version` output also doesn't seem good
way forward and we don't have gcc-native recipes.

We can probably use gcc pragma to disable this warning (which IIRC doesn't
test if the disabled warning is supported or not), but that might be a bit
complicated as this file is generated in configure. I'll check it.

The target grub-efi build doesn't fail probably because target gcc doesn't
define _FORTIFY_SOURCE

I've tried to compare native and target build and it's reproducible e.g.
with this command:

gcc  -DHAVE_CONFIG_H -I. -I../grub-2.02  -Wall -W -DGRUB_UTIL=1
-D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/lib/crypto.c\"
-I. -I../grub-2.02 -I. -I../grub-2.02 -I../grub-2.02/include -I./include
-I../grub-2.02/grub-core/lib/libgcrypt-grub/src/  -I./grub-core/gnulib
-I../grub-2.02/grub-core/gnulib -D_FILE_OFFSET_BITS=64 -fno-builtin-gettext
-Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment
-Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero
-Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit
-Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces
-Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type
-Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs
-Wunknown-pragmas -Wunused -Wunused-function -Wunused-label
-Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings
-Wnested-externs -Wstrict-prototypes -Wcast-align  -Wextra -Wattributes
-Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch
-Wmissing-field-initializers -Wnonnull -Woverflow -Wvla
-Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros
-Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs
-Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror  -Wno-undef
-Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls
-Wno-unreachable-code -Wno-conversion -Wno-error=trampolines -c -o
grub-core/lib/libgrubkern_a-crypto.o `test -f 'grub-core/lib/crypto.c' ||
echo '../grub-2.02/'`grub-core/lib/crypto.c

After adding -dM -E and comparing the output between target and native I
can see that my native gcc defines _FORTIFY_SOURCE as:
#define _FORTIFY_SOURCE ((defined __OPTIMIZE__ && __OPTIMIZE__ > 0) ? 2 : 0)

while target build doesn't.

Just to confirm it's caused by this I've added the same line:
#define _FORTIFY_SOURCE ((defined __OPTIMIZE__ && __OPTIMIZE__ > 0) ? 2 : 0)
at the top of grub-2.02/grub-core/lib/crypto.c and the target build fails
the same.

And the  _FORTIFY_SOURCE in native gcc comes from gentoo gcc patches, this
one:
https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/gcc/7.1.0/gentoo/10_all_default-fortify-source.patch?view=markup

PATCHv2 with #pragma coming soon.



On Tue, Aug 22, 2017 at 1:52 AM, Khem Raj <raj.khem at gmail.com> wrote:

> On Mon, Aug 21, 2017 at 1:57 PM, Martin Jansa <martin.jansa at gmail.com>
> wrote:
> > * build with gcc-7 fails with:
> >   | ./config-util.h:1504:48: error: this use of "defined" may not be
>  portable [-Werror=expansion-to-defined]
> >   |              || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
> >   |
>                                             ^~~~~~~~~~~~~~~
> >   and we're not building on Apple or BSD, so we should be able
> >   to just ignoreit until it's resolved properly in some newer gnulib
> >   and imported from gnulib to grub-2
> >
> > Signed-off-by: Martin Jansa <Martin.Jansa at gmail.com>
> > ---
> >  meta/recipes-bsp/grub/grub-efi_2.02.bb | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/meta/recipes-bsp/grub/grub-efi_2.02.bb
> b/meta/recipes-bsp/grub/grub-efi_2.02.bb
> > index b949bebced..45f4c1ed34 100644
> > --- a/meta/recipes-bsp/grub/grub-efi_2.02.bb
> > +++ b/meta/recipes-bsp/grub/grub-efi_2.02.bb
> > @@ -36,6 +36,12 @@ EXTRA_OECONF += "--enable-efiemu=no"
> >  # and many other places in the grub code when compiled with some native
> gcc compilers (specifically, gentoo)
> >  CFLAGS_append_class-native = " -Wno-error=trampolines"
> >
> > +# this comes from gnulib and it's used only for Apple and BSD, so we
> can ignore it
> > +# ./config-util.h:1504:48: error: this use of "defined" may not be
> portable [-Werror=expansion-to-defined]
> > +#             || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
> > +#                                                ^~~~~~~~~~~~~~~
> > +CFLAGS_append_class-native = " -Wno-error=expansion-to-defined"
> > +
>
> This workaround seems reasonable but I wonder why it fails on build host
> for you. how is your build hosts toolchain configured to generate this
> warning. Since you mentioned gcc7 then why doesnt it fail for OE
> targets
> in same way.
>
> An upstreamable fix would be to break this define into another #if ..
> #else macros and define the new macro to 1 or 0 depending upon the
> conditions
> being tested.
>
> >  do_install_class-native() {
> >         install -d ${D}${bindir}
> >         install -m 755 grub-mkimage ${D}${bindir}
> > --
> > 2.14.1
> >
> > --
> > _______________________________________________
> > Openembedded-core mailing list
> > Openembedded-core at lists.openembedded.org
> > http://lists.openembedded.org/mailman/listinfo/openembedded-core
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/openembedded-core/attachments/20170822/64d0d663/attachment-0002.html>


More information about the Openembedded-core mailing list