This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Silence gcc-8 warnings
Hi,
On Tue, 24 Apr 2018, Alan Modra wrote:
> On Tue, Apr 24, 2018 at 12:41:31AM +0930, Alan Modra wrote:
> > Yeah, really curious. I failed to mention that gcc build was on
> > hppa-linux, whereas the one that didn't show any error was on
> > x86_64-linux. I have a little sleuthing to do to figure out what made
> > the difference. It doesn't seem likely that it was any of the more
> > recent gcc patches.
>
> Oh wow, I don't see the first error on x86_64-linux (for
> swap_linux_prpsinfo32_ugid32_out) when the preprocessed source looks
> like the following. However, take out the file/line directives and
> the problem appears!
The elf-linux-core.h header is regarded as system header with the #line
directives, and that disables the warning. I've looked at this somewhat
further, and actually the warning is correct (!), but subtle:
> static inline void
> swap_linux_prpsinfo32_ugid32_out
> (bfd *obfd,
> const struct elf_internal_linux_prpsinfo *from,
> struct elf_external_linux_prpsinfo32_ugid32 *to)
So, FROM has different type from TO (xxx vs xxx_ugid32):
from (from elf-bfd.h):
struct elf_internal_linux_prpsinfo
{
...
char pr_fname[16 + 1];
char pr_psargs[80 + 1];
};
and to (from elf-linux-core.h):
struct elf_external_linux_prpsinfo32_ugid32
{
...
char pr_fname[16];
char pr_psargs[80];
};
So, the strncpy was:
__builtin_strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname))
sizeof(to->prfname) is 16, but sizeof(from->prfname) is 17, so it is
indeed conceivable that the from string has 16 characters plus null
terminator, which would not fit terminated into to->pr_fname, and this is
what is warned about. I think this is a genuine bug in bfd (even though
possibly a harmless one with non-fuzzed prpsinfo structs in core files).
Ciao,
Michael.