Silence gcc-8 warnings
H.J. Lu
hjl.tools@gmail.com
Mon Apr 23 12:03:00 GMT 2018
On Mon, Apr 23, 2018 at 4:55 AM, Alan Modra <amodra@gmail.com> wrote:
> On Mon, Apr 23, 2018 at 02:54:42AM -0600, Jan Beulich wrote:
>> >>> On 23.04.18 at 10:48, <amodra@gmail.com> wrote:
>> > --- a/bfd/elf-linux-core.h
>> > +++ b/bfd/elf-linux-core.h
>> > @@ -69,8 +69,12 @@ swap_linux_prpsinfo32_ugid32_out
>> > bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
>> > bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
>> > bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
>> > +#pragma GCC diagnostic push
>> > +#pragma GCC diagnostic ignored "-Wpragmas"
>> > +#pragma GCC diagnostic ignored "-Wstringop-truncation"
>> > strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
>> > strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
>> > +#pragma GCC diagnostic pop
>> > }
>>
>> We've tried to use this approach in the Xen hypervisor sources too in at least
>> one place: Older gcc isn't happy about such #pragma-s inside functions. Sadly
>> we haven't found a neat alternative (yet).
>
> I did try with a few older gcc versions.. Obviously didn't try enough.
> What versions fail?
>
> I wanted to avoid adding -Wno-stringop-truncation to the default build
> flags (with a configure test for gcc-8), but that seems to be the most
> reasonable option if my patch is going to make things worse.
>
In glibc, we have some macros to silence false positive from GCC
warning on a case-by-case basis, depending on version of GCC.
Please see:
https://sourceware.org/git/?p=glibc.git;a=patch;h=8e57c9432a2b68c8a1e7f4df28f0e8c7acc04753
as an example. We can do something similar.
--
H.J.
More information about the Binutils
mailing list