[3/3] Use DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION to silence GCC 8

Message ID 20180521121557.16535-3-hjl.tools@gmail.com
State New, archived
Headers

Commit Message

H.J. Lu May 21, 2018, 12:15 p.m. UTC
  GCC 8 warns about destination size with -Wstringop-truncation:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643

Use DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION to silence it.

	PR binutils/23146
	* bfd-in.h: Include "diagnostics.h".
	* bfd-in2.h: Regenerated.
	* elf32-arm.c (elf32_arm_nabi_write_core_note): Use
	DIAGNOSTIC_PUSH, DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION and
	DIAGNOSTIC_POP to silence GCC 8 warnings with
	-Wstringop-truncation.
	* elf32-ppc.c (ppc_elf_write_core_note): Likewse.
	* elf32-s390.c (elf_s390_write_core_note): Likewse.
	* elf64-ppc.c (ppc64_elf_write_core_note): Likewse.
	* elf64-s390.c (elf_s390_write_core_note): Likewse.
	* elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewse.
---
 bfd/bfd-in.h        | 1 +
 bfd/bfd-in2.h       | 1 +
 bfd/elf32-arm.c     | 7 +++++++
 bfd/elf32-ppc.c     | 7 +++++++
 bfd/elf32-s390.c    | 7 +++++++
 bfd/elf64-ppc.c     | 7 +++++++
 bfd/elf64-s390.c    | 7 +++++++
 bfd/elfxx-aarch64.c | 7 +++++++
 8 files changed, 44 insertions(+)
  

Comments

Nick Clifton June 1, 2018, 7:59 a.m. UTC | #1
Hi H.J. 

> 	PR binutils/23146
> 	* bfd-in.h: Include "diagnostics.h".
> 	* bfd-in2.h: Regenerated.
> 	* elf32-arm.c (elf32_arm_nabi_write_core_note): Use
> 	DIAGNOSTIC_PUSH, DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION and
> 	DIAGNOSTIC_POP to silence GCC 8 warnings with
> 	-Wstringop-truncation.
> 	* elf32-ppc.c (ppc_elf_write_core_note): Likewse.
> 	* elf32-s390.c (elf_s390_write_core_note): Likewse.
> 	* elf64-ppc.c (ppc64_elf_write_core_note): Likewse.
> 	* elf64-s390.c (elf_s390_write_core_note): Likewse.
> 	* elfxx-aarch64.c (_bfd_aarch64_elf_write_core_note): Likewse.

Approved - please apply.

Cheers
  Nick
  

Patch

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 481587e458..1d477c3f5f 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -34,6 +34,7 @@  extern "C" {
 
 #include "ansidecl.h"
 #include "symcat.h"
+#include "diagnostics.h"
 #include <stdarg.h>
 #include <sys/stat.h>
 
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index c64eee1fe1..4a5c51fdf8 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -41,6 +41,7 @@  extern "C" {
 
 #include "ansidecl.h"
 #include "symcat.h"
+#include "diagnostics.h"
 #include <stdarg.h>
 #include <sys/stat.h>
 
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 5a3b58ff0d..4e04a2f699 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -2174,7 +2174,14 @@  elf32_arm_nabi_write_core_note (bfd *abfd, char *buf, int *bufsiz,
 	va_start (ap, note_type);
 	memset (data, 0, sizeof (data));
 	strncpy (data + 28, va_arg (ap, const char *), 16);
+	DIAGNOSTIC_PUSH;
+	/* GCC 8 warns about 80 equals destination size with
+	   -Wstringop-truncation:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+	 */
+	DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
 	strncpy (data + 44, va_arg (ap, const char *), 80);
+	DIAGNOSTIC_POP;
 	va_end (ap);
 
 	return elfcore_write_note (abfd, buf, bufsiz,
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 462c8af311..b5cb14ecbf 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -2411,7 +2411,14 @@  ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
 	va_start (ap, note_type);
 	memset (data, 0, sizeof (data));
 	strncpy (data + 32, va_arg (ap, const char *), 16);
+	DIAGNOSTIC_PUSH;
+	/* GCC 8 warns about 80 equals destination size with
+	   -Wstringop-truncation:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+	 */
+	DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
 	strncpy (data + 48, va_arg (ap, const char *), 80);
+	DIAGNOSTIC_POP;
 	va_end (ap);
 	return elfcore_write_note (abfd, buf, bufsiz,
 				   "CORE", note_type, data, sizeof (data));
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index b3603bd865..b9e1602aa2 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -3951,7 +3951,14 @@  elf_s390_write_core_note (bfd *abfd, char *buf, int *bufsiz,
 	va_end (ap);
 
 	strncpy (data + 28, fname, 16);
+	DIAGNOSTIC_PUSH;
+	/* GCC 8 warns about 80 equals destination size with
+	   -Wstringop-truncation:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+	 */
+	DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
 	strncpy (data + 44, psargs, 80);
+	DIAGNOSTIC_POP;
 	return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
 				   &data, sizeof (data));
       }
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index b166558945..bf314b3571 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -3041,7 +3041,14 @@  ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
 	va_start (ap, note_type);
 	memset (data, 0, sizeof (data));
 	strncpy (data + 40, va_arg (ap, const char *), 16);
+	DIAGNOSTIC_PUSH;
+	/* GCC 8 warns about 80 equals destination size with
+	   -Wstringop-truncation:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+	 */
+	DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
 	strncpy (data + 56, va_arg (ap, const char *), 80);
+	DIAGNOSTIC_POP;
 	va_end (ap);
 	return elfcore_write_note (abfd, buf, bufsiz,
 				   "CORE", note_type, data, sizeof (data));
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index bfa02340ca..4552bd6ee8 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -3760,7 +3760,14 @@  elf_s390_write_core_note (bfd *abfd, char *buf, int *bufsiz,
 	va_end (ap);
 
 	strncpy (data + 40, fname, 16);
+	DIAGNOSTIC_PUSH;
+	/* GCC 8 warns about 80 equals destination size with
+	   -Wstringop-truncation:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+	 */
+	DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
 	strncpy (data + 56, psargs, 80);
+	DIAGNOSTIC_POP;
 	return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
 				   &data, sizeof (data));
       }
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index 45a732db2b..f418581048 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -659,7 +659,14 @@  _bfd_aarch64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_ty
 	va_start (ap, note_type);
 	memset (data, 0, sizeof (data));
 	strncpy (data + 40, va_arg (ap, const char *), 16);
+	DIAGNOSTIC_PUSH;
+	/* GCC 8 warns about 80 equals destination size with
+	   -Wstringop-truncation:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+	 */
+	DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
 	strncpy (data + 56, va_arg (ap, const char *), 80);
+	DIAGNOSTIC_POP;
 	va_end (ap);
 
 	return elfcore_write_note (abfd, buf, bufsiz, "CORE",