This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Fix COFF section header macros for gcc 4.3 compilation
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Tue, 17 Jun 2008 16:57:05 +0100
- Subject: PATCH: Fix COFF section header macros for gcc 4.3 compilation
Hi Guys,
I am applying the patch below to fix some compile time warnings
generated by the v4.3 gcc compiler shipped with Fedora Core 9 when
compiling the tic40/tic80 coff targets. The problem was that the
macros were using negative offsets for fixed size arrays, which
triggers the array bounds warning from gcc.
Cheers
Nick
include/coff
2008-06-17 Nick Clifton <nickc@redhat.com>
* ti.h (GET_SCNHDR_NLNNO): Provide an alternative version of this
macro which does not trigger an array bounds warning in gcc.
(PUT_SCNHDR_NLNNO): Likewise.
(GET_SCNHDR_FLAGS): Likewise.
(PUT_SCNHDR_FLAGS): Likewise.
(GET_SCNHDR_PAGE): Likewise.
(PUT_SCNHDR_PAGE): Likewise.
Index: include/coff/ti.h
===================================================================
RCS file: /cvs/src/src/include/coff/ti.h,v
retrieving revision 1.17
diff -c -3 -p -r1.17 ti.h
*** include/coff/ti.h 10 May 2005 10:21:09 -0000 1.17
--- include/coff/ti.h 17 Jun 2008 15:43:52 -0000
*************** struct external_scnhdr {
*** 213,224 ****
/* COFF2 changes the offsets and sizes of these fields
Assume we're dealing with the COFF2 scnhdr structure, and adjust
! accordingly
! */
#define GET_SCNHDR_NRELOC(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, LOC))
#define PUT_SCNHDR_NRELOC(ABFD, VAL, LOC) \
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, LOC))
#define GET_SCNHDR_NLNNO(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 2))
#define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
--- 213,293 ----
/* COFF2 changes the offsets and sizes of these fields
Assume we're dealing with the COFF2 scnhdr structure, and adjust
! accordingly. Note: The GNU C versions of some of these macros
! are necessary in order to avoid compile time warnings triggered
! gcc's array bounds checking. The PUT_SCNHDR_PAGE macro also has
! the advantage on not evaluating LOC twice. */
!
#define GET_SCNHDR_NRELOC(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, LOC))
#define PUT_SCNHDR_NRELOC(ABFD, VAL, LOC) \
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, LOC))
+ #ifdef __GNUC__
+ #define GET_SCNHDR_NLNNO(ABFD, LOC) \
+ ({ \
+ int nlnno; \
+ char * ptr = (LOC); \
+ if (COFF2_P (ABFD)) \
+ nlnno = H_GET_32 (ABFD, ptr); \
+ else \
+ nlnno = H_GET_16 (ABFD, ptr - 2); \
+ nlnno; \
+ })
+ #define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
+ do \
+ { \
+ char * ptr = (LOC); \
+ if (COFF2_P (ABFD)) \
+ H_PUT_32 (ABFD, VAL, ptr); \
+ else \
+ H_PUT_16 (ABFD, VAL, ptr - 2); \
+ } \
+ while (0)
+ #define GET_SCNHDR_FLAGS(ABFD, LOC) \
+ ({ \
+ int flags; \
+ char * ptr = (LOC); \
+ if (COFF2_P (ABFD)) \
+ flags = H_GET_32 (ABFD, ptr); \
+ else \
+ flags = H_GET_16 (ABFD, ptr - 4); \
+ flags; \
+ })
+ #define PUT_SCNHDR_FLAGS(ABFD, VAL, LOC) \
+ do \
+ { \
+ char * ptr = (LOC); \
+ if (COFF2_P (ABFD)) \
+ H_PUT_32 (ABFD, VAL, ptr); \
+ else \
+ H_PUT_16 (ABFD, VAL, ptr - 4); \
+ } \
+ while (0)
+ #define GET_SCNHDR_PAGE(ABFD, LOC) \
+ ({ \
+ unsigned page; \
+ char * ptr = (LOC); \
+ if (COFF2_P (ABFD)) \
+ page = H_GET_16 (ABFD, ptr); \
+ else \
+ page = (unsigned) H_GET_8 (ABFD, ptr - 7); \
+ page; \
+ })
+ /* On output, make sure that the "reserved" field is zero. */
+ #define PUT_SCNHDR_PAGE(ABFD, VAL, LOC) \
+ do \
+ { \
+ char * ptr = (LOC); \
+ if (COFF2_P (ABFD)) \
+ H_PUT_16 (ABFD, VAL, ptr); \
+ else \
+ { \
+ H_PUT_8 (ABFD, VAL, ptr - 7); \
+ H_PUT_8 (ABFD, 0, ptr - 8); \
+ } \
+ } \
+ while (0)
+ #else
#define GET_SCNHDR_NLNNO(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 2))
#define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
*************** struct external_scnhdr {
*** 229,239 ****
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 4))
#define GET_SCNHDR_PAGE(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_16 (ABFD, LOC) : (unsigned) H_GET_8 (ABFD, (LOC) - 7))
! /* on output, make sure that the "reserved" field is zero */
#define PUT_SCNHDR_PAGE(ABFD, VAL, LOC) \
(COFF2_P (ABFD) \
? H_PUT_16 (ABFD, VAL, LOC) \
: H_PUT_8 (ABFD, VAL, (LOC) - 7), H_PUT_8 (ABFD, 0, (LOC) - 8))
/* TI COFF stores section size as number of bytes (address units, not octets),
so adjust to be number of octets, which is what BFD expects */
--- 298,310 ----
(COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 4))
#define GET_SCNHDR_PAGE(ABFD, LOC) \
(COFF2_P (ABFD) ? H_GET_16 (ABFD, LOC) : (unsigned) H_GET_8 (ABFD, (LOC) - 7))
! /* On output, make sure that the "reserved" field is zero. */
#define PUT_SCNHDR_PAGE(ABFD, VAL, LOC) \
(COFF2_P (ABFD) \
? H_PUT_16 (ABFD, VAL, LOC) \
: H_PUT_8 (ABFD, VAL, (LOC) - 7), H_PUT_8 (ABFD, 0, (LOC) - 8))
+ #endif
+
/* TI COFF stores section size as number of bytes (address units, not octets),
so adjust to be number of octets, which is what BFD expects */