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]

small diffs to fix -enable-targets=all


> From: jayk123@hotmail.com
> To: binutils@gnu.org
> Subject: small diffs to fix -enable-targets=all
> Date: Sat, 26 Jul 2008 09:00:32 +0000
>
>
>
> Here are small diffs to let binutils 2.18 build with configure -enable-targets=all.
>
> The bin2c.c code is copied from its neighbor strings.c.
> I agree it seems like BeOS and DJGPP are negatively affected.
> I have not tested them.
> Again, copied verbatim from strings.c.
>
> That bin2c.c fails is Cygwin specific.
>
> For the ti.h case, nobody builds with -enable-targets=all?
> And nobody builds for these targets?
> They should be removed like how gcc has been removing old/dead/unmaintained targets?????
> I don't know, just asking.
>
> The ti.h code is not imho ideal but probably ok.
> Really, possibly ignoring 16 bit systems:
> sizeof(size_t) == sizeof(void*) ?
> sizeof(ptrdiff_t) == sizeof(void*) ?
> size_t == uintptr_t, but size_t way more portable (older) ?
> ptrdiff_t == intptr_t, but ptrdiff_t way more portable (older) ?
>
> Right? It makes me wonder why those types were even added..
> Or is there some hypothetical case where objects cannot span
> arbitrary ranges of address space, so therefore sizeof(size_t) can be
> smaller than sizeof(void*)??
>
> Maybe a way to quash the warning instead?
>
> In both cases, I have only possibly built the changes.
> I have not necessarily run them.
>
> After this I'd like to "fix" gas and ld to work with -enable-targets=all.
> Gas should have a command parameter to indicate the output format.
> Then, binutils can be built just once per host, instead of per host/target combination.
> Good idea? Patches will be accepted (with usual conditions)?
> It'd be nice to have for gcc too, but probably more difficult.
>
>
> - Jay

diff -ur gcc.orig/binutils/bin2c.c gcc.mine/binutils/bin2c.c

--- gcc.orig/binutils/bin2c.c	2007-08-06 12:55:09.000000000 -0700
+++ gcc.mine/binutils/bin2c.c	2008-07-25 17:11:58.906250000 -0700
@@ -22,30 +22,22 @@
 #include "bfd.h"
 #include "bucomm.h"
 
-#if !defined O_BINARY && defined _O_BINARY
-  /* For MSC-compatible compilers.  */
-# define O_BINARY _O_BINARY
-# define O_TEXT _O_TEXT
-#endif
-
-#ifdef __BEOS__
-  /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
-# undef O_BINARY
-# undef O_TEXT
-#endif
-
-#if O_BINARY
-# ifndef __DJGPP__
-#  define setmode _setmode
-#  define fileno(_fp) _fileno (_fp)
-# endif /* not DJGPP */
-# define SET_BINARY(_f) \
-  do { if (!isatty (_f)) setmode (_f, O_BINARY); } while (0)
-#else
-# define SET_BINARY(f) (void) 0
-# define O_BINARY 0
-# define O_TEXT 0
-#endif /* O_BINARY */
+/* Some platforms need to put stdin into binary mode, to read
+    binary files.  */
+#ifdef HAVE_SETMODE
+#ifndef O_BINARY
+#ifdef _O_BINARY
+#define O_BINARY _O_BINARY
+#define setmode _setmode
+#else
+#define O_BINARY 0
+#endif
+#endif
+#if O_BINARY
+#include 
+#define SET_BINARY(f) do { if (!isatty (f)) setmode (f,O_BINARY); } while (0)
+#endif
+#endif
 
 int
 main (int argc, char *argv[])


diff -ur gcc.orig/include/coff/ti.h gcc.mine/include/coff/ti.h
--- gcc.orig/include/coff/ti.h	2005-05-10 03:21:09.000000000 -0700
+++ gcc.mine/include/coff/ti.h	2008-07-25 18:59:40.078125000 -0700
@@ -214,26 +214,45 @@
 /* COFF2 changes the offsets and sizes of these fields 
    Assume we're dealing with the COFF2 scnhdr structure, and adjust
    accordingly 
- */
+
+gcc is very smart about enforcing array bounds and if we don't cast through size_t, we get:
+/src/gcc/bfd/coffswap.h: In function 'coff_swap_scnhdr_in':
+/src/gcc/bfd/coffswap.h:767: error: array subscript is below array bounds
+/src/gcc/bfd/coffswap.h:769: error: array subscript is below array bounds
+/src/gcc/bfd/coffswap.h: In function 'coff_swap_scnhdr_out':
+/src/gcc/bfd/coffswap.h:796: error: array subscript is below array bounds
+/src/gcc/bfd/coffswap.h:802: error: array subscript is below array bounds
+/src/gcc/bfd/coffswap.h:813: error: array subscript is below array bounds
+/src/gcc/bfd/coffswap.h:837: error: array subscript is below array bounds
+/src/gcc/bfd/coffswap.h:837: error: array subscript is below array bounds
+make: *** [coff-tic4x.o] Error 1
+
+Another solution might be cast the base to the v1 struct type and then
+access the field, but that requires much more change.
+*/
+
+#define COFF_TI_ADJUST(base, offset) \
+    (((char*) (size_t) base) - offset)
+
 #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))
+  (COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, COFF_TI_ADJUST(LOC, 2)))
 #define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
-  (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 2))
+  (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, COFF_TI_ADJUST(LOC, 2)))
 #define GET_SCNHDR_FLAGS(ABFD, LOC) \
-  (COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 4))
+  (COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, COFF_TI_ADJUST(LOC, 4)))
 #define PUT_SCNHDR_FLAGS(ABFD, VAL, LOC) \
-  (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 4))
+  (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, COFF_TI_ADJUST(LOC, 4)))
 #define GET_SCNHDR_PAGE(ABFD, LOC) \
-  (COFF2_P (ABFD) ? H_GET_16 (ABFD, LOC) : (unsigned) H_GET_8 (ABFD, (LOC) - 7))
+  (COFF2_P (ABFD) ? H_GET_16 (ABFD, LOC) : (unsigned) H_GET_8 (ABFD, COFF_TI_ADJUST(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))
+   : H_PUT_8 (ABFD, VAL, COFF_TI_ADJUST(LOC, 7)), H_PUT_8 (ABFD, 0, COFF_TI_ADJUST(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 */ 


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