This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Silence gcc-8 warnings


On 04/23/2018 03:48 AM, Alan Modra wrote:
> All of these warnings were false positives.  -Wstringop-truncation is
> particularly annoying when it warns about strncpy used quite correctly.
> Changing strncpy to memcpy in the bfd files would be wrong.
> 
> bfd/
> 	* elf-linux-core.h (swap_linux_prpsinfo32_ugid32_out): Disable
> 	gcc-8 string truncation warning.
> 	(swap_linux_prpsinfo32_ugid16_out): Likewise.
> 	(swap_linux_prpsinfo64_ugid32_out): Likewise.
> 	(swap_linux_prpsinfo64_ugid16_out): Likewise.
> 	* elf.c (elfcore_write_prpsinfo): Likewise.
> gas/
> 	* stabs.c (generate_asm_file): Use memcpy rather than strncpy.
> 	Remove call to strlen inside loop.
> 	* config/tc-cr16.c (getreg_image): Warning fix.
> 	* config/tc-crx.c (getreg_image): Warning fix.
> 
> diff --git a/bfd/elf-linux-core.h b/bfd/elf-linux-core.h
> index 0a5d76f..25d33f6 100644
> --- 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

Two comments here:

* The FSF version of gcc should be identified here in an easy to understand way.
  For example in glibc we do this:


1533                       /* wcdigits_extended[] is fully set in the loop
1534                          above, but the test for "map != NULL" is done
1535                          inside the loop here and outside the loop there.  */
1536                       DIAG_PUSH_NEEDS_COMMENT;
1537                       DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
...                        <Code with warning>
1546                       DIAG_POP_NEEDS_COMMENT;

(see glibc/include/libc-diag.h for the macro definitions).

The point is that "4.7" is the version of gcc, easily understand, and when we no
longer support building with this version of gcc we will *cleanup* the pragmas.

The key thing to remember when adding such pragma's as you have added is we need a
way to know when we might remove them. Making that very clear is important IMO.
Your last patch downthread has enough information.

* Consider abstracting away some of the verbose GCC_VERSION checking behind
  some helper macros.

For example:

 67 #ifdef __OPTIMIZE_SIZE__
 68 # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option) \
 69   _Pragma (_DIAG_STR (GCC diagnostic ignored option))
 70 #else
 71 # define DIAG_IGNORE_Os_NEEDS_COMMENT(version, option)
 72 #endif

In glibc we only added a conditional for -Os vs. default, because that makes the
biggest difference in the runtime. Bintuils isn't a runtime (unless you consider
libbfd.a) per-se and so your choices and requirements will be different.

-- 
Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]