Fix build with -Werror (which turns out -Wbounded).

With and ok nicm@
This commit is contained in:
jasper 2011-10-02 18:26:32 +00:00
parent dc4f6bf048
commit bcf412c2be
4 changed files with 76 additions and 5 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile.inc,v 1.8 2011/09/16 10:24:46 jasper Exp $
# $OpenBSD: Makefile.inc,v 1.9 2011/10/02 18:26:32 jasper Exp $
TARGET= msp430
@ -41,8 +41,6 @@ CONFIGURE_STYLE?= gnu
CONFIGURE_ARGS+= --target=msp430 \
--disable-nls \
--disable-shared
# XXX: Breaks with -Wbounded
CONFIGURE_ARGS+= --disable-werror
USE_LIBTOOL?= Yes
USE_GROFF?= Yes

View File

@ -1,11 +1,11 @@
# $OpenBSD: Makefile,v 1.5 2011/09/27 19:20:25 jasper Exp $
# $OpenBSD: Makefile,v 1.6 2011/10/02 18:26:32 jasper Exp $
COMMENT= GNU binutils for msp430
V= 2.21.1
R= 20110716
DISTNAME= binutils-$V
REVISION= 0
REVISION= 1
PKGNAME= ${TARGET}-${DISTNAME}
MASTER_SITES= ${MASTER_SITE_GNU:=binutils/}

View File

@ -0,0 +1,37 @@
$OpenBSD: patch-binutils_elfedit_c,v 1.1 2011/10/02 18:26:32 jasper Exp $
Fix -Wbounded warnings by using correct casts.
--- binutils/elfedit.c.orig Fri Sep 30 16:29:00 2011
+++ binutils/elfedit.c Fri Sep 30 16:33:14 2011
@@ -169,6 +169,10 @@ update_elf_header (const char *file_name, FILE *file)
static int
get_file_header (FILE * file)
{
+ /* Temporary var to prevent the GCC -Wbounded checker from firing. */
+ void *tmp32 = &ehdr32.e_type[0];
+ void *tmp64 = &ehdr64.e_type[0];
+
/* Read in the identity array. */
if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
return 0;
@@ -198,8 +202,7 @@ get_file_header (FILE * file)
return 0;
case ELFCLASS32:
- if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT,
- 1, file) != 1)
+ if (fread (tmp32, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
return 0;
elf_header.e_type = BYTE_GET (ehdr32.e_type);
@@ -231,8 +234,7 @@ get_file_header (FILE * file)
return 0;
}
- if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT,
- 1, file) != 1)
+ if (fread (tmp64, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
return 0;
elf_header.e_type = BYTE_GET (ehdr64.e_type);

View File

@ -0,0 +1,36 @@
$OpenBSD: patch-binutils_readelf_c,v 1.1 2011/10/02 18:26:32 jasper Exp $
Fix -Wbounded warnings by using correct casts.
--- binutils/readelf.c.orig Fri Sep 30 16:24:11 2011
+++ binutils/readelf.c Fri Sep 30 16:28:53 2011
@@ -12202,8 +12202,10 @@ get_file_header (FILE * file)
if (is_32bit_elf)
{
Elf32_External_Ehdr ehdr32;
+ /* Temporary var to prevent the GCC -Wbounded checker from firing. */
+ void *tmp = &ehdr32.e_type[0];
- if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
+ if (fread (tmp, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
return 0;
elf_header.e_type = BYTE_GET (ehdr32.e_type);
@@ -12223,6 +12225,8 @@ get_file_header (FILE * file)
else
{
Elf64_External_Ehdr ehdr64;
+ /* Temporary var to prevent the GCC -Wbounded checker from firing. */
+ void *tmp = &ehdr64.e_type[0];
/* If we have been compiled with sizeof (bfd_vma) == 4, then
we will not be able to cope with the 64bit data found in
@@ -12235,7 +12239,7 @@ get_file_header (FILE * file)
return 0;
}
- if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
+ if (fread (tmp, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
return 0;
elf_header.e_type = BYTE_GET (ehdr64.e_type);