<div dir="ltr">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&#39;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 &quot;defined&quot; 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<wbr>/i586-oe-linux/grub-efi/2.02-<wbr>r0 $ recipe-sysroot-native/usr/bin/<wbr>i586-oe-linux/i586-oe-linux-gc<wbr>c --help=warnings | grep expansion-to-defined</div><div>  -Wexpansion-to-defined      Warn if &quot;defined&quot; is used outside #if.</div><div>OE @ ~/build/oe-core/tmp-glibc/work<wbr>/i586-oe-linux/grub-efi/2.02-<wbr>r0 $ recipe-sysroot-native/usr/bin/<wbr>i586-oe-linux/i586-oe-linux-gc<wbr>c --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&#39;t seem good way forward and we don&#39;t have gcc-native recipes.<br></div><div><br></div><div>We can probably use gcc pragma to disable this warning (which IIRC doesn&#39;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&#39;ll check it.</div><div><br></div><div>The target grub-efi build doesn&#39;t fail probably because target gcc doesn&#39;t define _FORTIFY_SOURCE</div><div><br></div><div>I&#39;ve tried to compare native and target build and it&#39;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=\&quot;grub-core/lib/crypto.c\&quot; -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 &#39;grub-core/lib/crypto.c&#39; || echo &#39;../grub-2.02/&#39;`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__ &amp;&amp; __OPTIMIZE__ &gt; 0) ? 2 : 0)<br></div><div><br></div><div>while target build doesn&#39;t.</div><div><br></div><div>Just to confirm it&#39;s caused by this I&#39;ve added the same line:</div><div>#define _FORTIFY_SOURCE ((defined __OPTIMIZE__ &amp;&amp; __OPTIMIZE__ &gt; 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">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 dir="ltr">&lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Aug 21, 2017 at 1:57 PM, Martin Jansa &lt;<a href="mailto:martin.jansa@gmail.com">martin.jansa@gmail.com</a>&gt; wrote:<br>
&gt; * build with gcc-7 fails with:<br>
&gt;   | ./config-util.h:1504:48: error: this use of &quot;defined&quot; may not be   portable [-Werror=expansion-to-defined]<br>
&gt;   |              || (defined _FORTIFY_SOURCE &amp;&amp; 0 &lt; _FORTIFY_SOURCE \<br>
&gt;   |<br>
                                            ^~~~~~~~~~~~~~~<br>
&gt;   and we&#39;re not building on Apple or BSD, so we should be able<br>
&gt;   to just ignoreit until it&#39;s resolved properly in some newer gnulib<br>
&gt;   and imported from gnulib to grub-2<br>
&gt;<br>
&gt; Signed-off-by: Martin Jansa &lt;<a href="mailto:Martin.Jansa@gmail.com">Martin.Jansa@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt;  meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-<wbr>efi_2.02.bb</a> | 6 ++++++<br>
&gt;  1 file changed, 6 insertions(+)<br>
&gt;<br>
&gt; diff --git a/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-<wbr>efi_2.02.bb</a> b/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-<wbr>efi_2.02.bb</a><br>
&gt; index b949bebced..45f4c1ed34 100644<br>
&gt; --- a/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-<wbr>efi_2.02.bb</a><br>
&gt; +++ b/meta/recipes-bsp/grub/<a href="http://grub-efi_2.02.bb" rel="noreferrer" target="_blank">grub-<wbr>efi_2.02.bb</a><br>
&gt; @@ -36,6 +36,12 @@ EXTRA_OECONF += &quot;--enable-efiemu=no&quot;<br>
&gt;  # and many other places in the grub code when compiled with some native gcc compilers (specifically, gentoo)<br>
&gt;  CFLAGS_append_class-native = &quot; -Wno-error=trampolines&quot;<br>
&gt;<br>
&gt; +# this comes from gnulib and it&#39;s used only for Apple and BSD, so we can ignore it<br>
&gt; +# ./config-util.h:1504:48: error: this use of &quot;defined&quot; may not be portable [-Werror=expansion-to-defined]<br>
&gt; +#             || (defined _FORTIFY_SOURCE &amp;&amp; 0 &lt; _FORTIFY_SOURCE \<br>
&gt; +#                                                ^~~~~~~~~~~~~~~<br>
&gt; +CFLAGS_append_class-native = &quot; -Wno-error=expansion-to-<wbr>defined&quot;<br>
&gt; +<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="HOEnZb"><div class="h5"><br>
&gt;  do_install_class-native() {<br>
&gt;         install -d ${D}${bindir}<br>
&gt;         install -m 755 grub-mkimage ${D}${bindir}<br>
&gt; --<br>
&gt; 2.14.1<br>
&gt;<br>
</div></div><span class="HOEnZb"><font color="#888888">&gt; --<br>
&gt; ______________________________<wbr>_________________<br>
&gt; Openembedded-core mailing list<br>
&gt; <a href="mailto:Openembedded-core@lists.openembedded.org">Openembedded-core@lists.<wbr>openembedded.org</a><br>
&gt; <a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/<wbr>mailman/listinfo/openembedded-<wbr>core</a><br>
</font></span></blockquote></div><br></div>