<div><div dir="auto">I have sent few patches to meta oe to fix similar issues earlier found with clang I think changes to code to define the macros in compliant way are better and upstreamable</div><br><div class="gmail_quote"><div>On Tue, Aug 22, 2017 at 10:21 AM Martin Jansa <<a href="mailto:martin.jansa@gmail.com">martin.jansa@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>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:<div><br></div><div><div>OE qemux86@ ~/oe/world/shr-core $ gcc --help=warnings | grep expansion-to-defined</div><div>OE qemux86@ ~/oe/world/shr-core $ gcc --version</div><div>gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609</div><div>Copyright (C) 2015 Free Software Foundation, Inc.</div><div>This is free software; see the source for copying conditions. There is NO</div><div>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</div></div><div><br></div><div><div>OE @ ~ $ gcc --help=warnings | grep expansion-to-defined</div><div> -Wexpansion-to-defined Warn if "defined" is used outside #if.</div><div>OE @ ~ $ gcc --version</div><div>gcc (Gentoo 7.1.0-r1 p1.1) 7.1.0</div><div>Copyright (C) 2017 Free Software Foundation, Inc.</div><div>This is free software; see the source for copying conditions. There is NO</div><div>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</div></div><div><br></div><div><div>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</div><div> -Wexpansion-to-defined Warn if "defined" is used outside #if.</div><div>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</div><div>i586-oe-linux-gcc (GCC) 7.2.0</div><div>Copyright (C) 2017 Free Software Foundation, Inc.</div><div>This is free software; see the source for copying conditions. There is NO</div><div>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</div></div><div><br></div><div>Applying the flags based on `gcc --version` output also doesn't seem good way forward and we don't have gcc-native recipes.<br></div><div><br></div><div>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.</div><div><br></div><div>The target grub-efi build doesn't fail probably because target gcc doesn't define _FORTIFY_SOURCE</div><div><br></div><div>I've tried to compare native and target build and it's reproducible e.g. with this command:</div><div><br></div><div><div>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</div></div><div><br></div><div>After adding -dM -E and comparing the output between target and native I can see that my native gcc defines _FORTIFY_SOURCE as:</div><div>#define _FORTIFY_SOURCE ((defined __OPTIMIZE__ && __OPTIMIZE__ > 0) ? 2 : 0)<br></div><div><br></div><div>while target build doesn't.</div><div><br></div><div>Just to confirm it's caused by this I've added the same line:</div><div>#define _FORTIFY_SOURCE ((defined __OPTIMIZE__ && __OPTIMIZE__ > 0) ? 2 : 0)<br></div><div>at the top of grub-2.02/grub-core/lib/crypto.c and the target build fails the same.</div><div><br></div><div>And the _FORTIFY_SOURCE in native gcc comes from gentoo gcc patches, this one:</div><div><a href="https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/gcc/7.1.0/gentoo/10_all_default-fortify-source.patch?view=markup" target="_blank">https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/gcc/7.1.0/gentoo/10_all_default-fortify-source.patch?view=markup</a><br></div><div><br></div><div>PATCHv2 with #pragma coming soon.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 22, 2017 at 1:52 AM, Khem Raj <span><<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_4829099699774669584HOEnZb"><div class="m_4829099699774669584h5">On Mon, Aug 21, 2017 at 1:57 PM, Martin Jansa <<a href="mailto:martin.jansa@gmail.com" target="_blank">martin.jansa@gmail.com</a>> wrote:<br>
> * build with gcc-7 fails with:<br>
> | ./config-util.h:1504:48: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]<br>
> | || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \<br>
> |<br>
^~~~~~~~~~~~~~~<br>
> and we're not building on Apple or BSD, so we should be able<br>
> to just ignoreit until it's resolved properly in some newer gnulib<br>
> and imported from gnulib to grub-2<br>
><br>
> Signed-off-by: Martin Jansa <<a href="mailto:Martin.Jansa@gmail.com" target="_blank">Martin.Jansa@gmail.com</a>><br>
> ---<br>
> meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-efi_2.02.bb</a> | 6 ++++++<br>
> 1 file changed, 6 insertions(+)<br>
><br>
> diff --git a/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-efi_2.02.bb</a> b/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-efi_2.02.bb</a><br>
> index b949bebced..45f4c1ed34 100644<br>
> --- a/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-efi_2.02.bb</a><br>
> +++ b/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-efi_2.02.bb</a><br>
> @@ -36,6 +36,12 @@ EXTRA_OECONF += "--enable-efiemu=no"<br>
> # and many other places in the grub code when compiled with some native gcc compilers (specifically, gentoo)<br>
> CFLAGS_append_class-native = " -Wno-error=trampolines"<br>
><br>
> +# this comes from gnulib and it's used only for Apple and BSD, so we can ignore it<br>
> +# ./config-util.h:1504:48: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]<br>
> +# || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \<br>
> +# ^~~~~~~~~~~~~~~<br>
> +CFLAGS_append_class-native = " -Wno-error=expansion-to-defined"<br>
> +<br>
<br>
</div></div>This workaround seems reasonable but I wonder why it fails on build host<br>
for you. how is your build hosts toolchain configured to generate this<br>
warning. Since you mentioned gcc7 then why doesnt it fail for OE<br>
targets<br>
in same way.<br>
<br>
An upstreamable fix would be to break this define into another #if ..<br>
#else macros and define the new macro to 1 or 0 depending upon the<br>
conditions<br>
being tested.<br>
<div class="m_4829099699774669584HOEnZb"><div class="m_4829099699774669584h5"><br>
> do_install_class-native() {<br>
> install -d ${D}${bindir}<br>
> install -m 755 grub-mkimage ${D}${bindir}<br>
> --<br>
> 2.14.1<br>
><br>
</div></div><span class="m_4829099699774669584HOEnZb"><font color="#888888">> --<br>
> _______________________________________________<br>
> Openembedded-core mailing list<br>
> <a href="mailto:Openembedded-core@lists.openembedded.org" target="_blank">Openembedded-core@lists.openembedded.org</a><br>
> <a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</font></span></blockquote></div><br></div>
</blockquote></div></div>