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]

[PATCH] dwarf.c: Fix build with non-GCC compilers


Hi!

I tried to build Binutils with IBM AIX's XL C compiler, which results
in something like this:

$ make all-binutils
[...]
        source='/home/jbglaw/repos/binutils/binutils/dwarf.c' object='dwarf.o' libtool=no  DEPDIR=.deps depmode=aix /bin/sh /home/jbglaw/repos/binutils
/binutils/../depcomp  /usr/bin/xlC -DHAVE_CONFIG_H -I. -I/home/jbglaw/repos/binutils/binutils  -I. -I/home/jbglaw/repos/binutils/binutils -I../bfd -I/h
ome/jbglaw/repos/binutils/binutils/../bfd -I/home/jbglaw/repos/binutils/binutils/../include    -DLOCALEDIR="\"/home/jbglaw/build/vax-linux/_install_/sh
are/locale\""  -Dbin_dummy_emulation=bin_vanilla_emulation    -g -c /home/jbglaw/repos/binutils/binutils/dwarf.c
"/home/jbglaw/repos/binutils/binutils/dwarf.c", line 881.11: 1506-131 (S) Explicit dimension specification or initializer required for an auto or stati
c array.
"/home/jbglaw/repos/binutils/binutils/dwarf.c", line 889.11: 1506-131 (S) Explicit dimension specification or initializer required for an auto or stati
c array.
"/home/jbglaw/repos/binutils/binutils/dwarf.c", line 897.11: 1506-131 (S) Explicit dimension specification or initializer required for an auto or stati
c array.
"/home/jbglaw/repos/binutils/binutils/dwarf.c", line 905.11: 1506-131 (S) Explicit dimension specification or initializer required for an auto or stati
c array.
[...]

This is SAFE_BYTE_GET(), called by SAFE_BYTE_GET_AND_INC(), which has
a nice sanity check for it's "VAL" argument being large enough to hold
the amount of data requested.

However, the trick used relys on zero-sized arrays:

      int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 0] ATTRIBUTE_UNUSED ; \

Depending on the C standard in use, zero-sized arrays are a no-go, or
indirectly accepted with no size argument at all in some
circumstances. I propose to simply declare it with size 1:



2013-10-01  Jan-Benedict Glaw  <jbglaw@lug-owl.de>

	* dwarf.c (SAFE_BYTE_GET): Fix argument check.

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index bd73647..283aceb 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -288,7 +288,7 @@ read_uleb128 (unsigned char * data,
 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END)	\
   do						\
     {						\
-      int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 0] ATTRIBUTE_UNUSED ; \
+      int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
       unsigned int amount = (AMOUNT);		\
       if (((PTR) + amount) >= (END))		\
 	{					\


Ok?

MfG, JBG

-- 
      Jan-Benedict Glaw      jbglaw@lug-owl.de              +49-172-7608481
 Signature of:                      http://perl.plover.com/Questions.html
 the second  :

Attachment: signature.asc
Description: Digital signature


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