2012-11-16 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* binutils/readelf.c (print_symbol) [__DJGPP__]:  Use mbtowc instead
	of mbrtowc.

	* gas/dw2gencfi.c (get_debugseg_name):  Pacify compiler.

	* gas/config/obj-coff-seh.c (get_pxdata_name):  Pacify compiler.

	* bfd/coff-go32.c: Define COFF_GO32 macro.
	Add _bfd_go32_mkobject prototype.
	Define coff_mkobject macro to _bfd_go32_mkobject.
	Define IMAGE_SCN_LNK_NRELOC_OVFL.  Signals that relocation counter
	has overflown.

	* bfd/coff-stgo32.c: Add _bfd_go32_mkobject prototype.
	Define coff_mkobject macro to _bfd_go32_mkobject.
	Add _bfd_go32_mkobject definition.
	Define IMAGE_SCN_LNK_NRELOC_OVFL.  Signals that relocation counter
	has overflown.

	* bfd/coffswap.h (coff_swap_scnhdr_in) [COFF_GO32_EXE, COFF_GO32]:
	Iff reading an executable file and iff it is the ".text" section
	header calculate the number of lines from the 16 bit field of the
	relocation counter and the 16 bit filed of the line counter.
	(coff_swap_scnhdr_out) [COFF_GO32_EXE, COFF_GO32]:
	Use the same Ansatz to identify a .text section of an executable like
	in coff_swap_scnhdr_in.
	- Iff building an executable file and iff it is the ".text" section
	header store the upper 16 bits of the line counter in the relocation
	counter.
	- Iff not building an executabe file or iff building an executable file
	but iff it is not the ".text" section header then:
	  1) if the relocation counter is greater the 65534 set the relocation
	     counter to 65535 and set the IMAGE_SCN_LNK_NRELOC_OVFL bit.
	     The relocation counter overflow is handled elsewhere.
	  2) if the line counter is greater than 65535 then abort.

	* bfd/coffcode.h [COFF_GO32_EXE, COFF_GO32, COFF_WITH_PE]: Define new
	macro COFF_WITH_EXTENDED_RELOC_COUNTER.
	(coff_write_relocs, coff_write_object_contents): Replace COFF_WITH_PE
	with COFF_WITH_EXTENDED_RELOC_COUNTER where appropriate and add
	obj_go32 to the check if relocation counter >= 0xFFFF.
	(coff_set_alignment_hook): Implementation for DJGPP.
	[COFF_GO32_EXE, COFF_GO32]:  Define COFF_PAD_SECTION_HEADERS.
	Taken from bnu219s2.zip.

	* bfd/libcoff-in.h: Define obj_go32 macro.
	Add go32 flag to struct coff_tdata.  1 if DJGPP else 0.

	* bfd/cofflink.c (_bfd_coff_final_link): If it is an obj_go32 allow
	relocations larger than 65535.

	* djgpp/build.sh:  DJGPP specific shell script to adjust, configure
	and compile progs and libs.

	* config.sub:  Use uname result to set basic_machine value
	instead of hardcoded one.

	* ld/scripttempl/i386go32.sc:  DJGPP specific adjustments to the
	linker script.
	Taken from djcross-binutils-2.19.1-10ap.src.rpm.

	* libiberty/make-relative-prefix.c:  DJGPP specific adjustments.
	Taken from bnu219s2.zip.

	* libiberty/make-temp-file.c:  DJGPP specific adjustments.
	Taken from bnu219s2.zip.

	* libiberty/pex-common.c (temp_file, pex_run_in_environment):  Pacify
	compiler.






diff -aprNU5 binutils-2.23.1.orig/bfd/coff-go32.c binutils-2.23.1/bfd/coff-go32.c
--- binutils-2.23.1.orig/bfd/coff-go32.c	2009-09-02 07:18:36 +0000
+++ binutils-2.23.1/bfd/coff-go32.c	2012-11-16 19:01:24 +0000
@@ -21,10 +21,11 @@
    MA 02110-1301, USA.  */
 
 #define TARGET_SYM		go32coff_vec
 #define TARGET_NAME		"coff-go32"
 #define TARGET_UNDERSCORE	'_'
+#define COFF_GO32
 #define COFF_LONG_SECTION_NAMES
 #define COFF_SUPPORT_GNU_LINKONCE
 #define COFF_LONG_FILENAMES
 
 #define COFF_SECTION_ALIGNMENT_ENTRIES \
@@ -41,6 +42,16 @@
 { COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
+/* Section contains extended relocations. */
+#define IMAGE_SCN_LNK_NRELOC_OVFL  0x01000000
+
+#include "sysdep.h"
+#include "bfd.h"
+
+bfd_boolean _bfd_go32_mkobject (bfd *abfd);
+
+#define coff_mkobject  _bfd_go32_mkobject
+
 #include "coff-i386.c"
diff -aprNU5 binutils-2.23.1.orig/bfd/coff-stgo32.c binutils-2.23.1/bfd/coff-stgo32.c
--- binutils-2.23.1.orig/bfd/coff-stgo32.c	2012-07-13 14:22:44 +0000
+++ binutils-2.23.1/bfd/coff-stgo32.c	2012-11-16 19:01:24 +0000
@@ -52,10 +52,13 @@
 { COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
+/* Section contains extended relocations. */
+#define IMAGE_SCN_LNK_NRELOC_OVFL  0x01000000
+
 #include "sysdep.h"
 #include "bfd.h"
 
 /* All that ..._PRE and ...POST functions are called from the corresponding
    coff_swap... functions. The ...PRE functions are called at the beginning
@@ -101,10 +104,14 @@ static const bfd_target *go32_check_form
 static bfd_boolean
   go32_stubbed_coff_bfd_copy_private_bfd_data (bfd *, bfd *);
 
 #define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data
 
+bfd_boolean _bfd_go32_mkobject (bfd *abfd);
+
+#define coff_mkobject  _bfd_go32_mkobject
+
 #include "coff-i386.c"
 
 /* This macro is used, because I cannot assume the endianness of the
    host system.  */
 #define _H(index) (H_GET_16 (abfd, (header + index * 2)))
@@ -421,5 +428,29 @@ go32_check_format (bfd *abfd)
   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
     return NULL;
 
   return coff_object_p (abfd);
 }
+
+/*  This function is not static because it is used
+    by both targets coff-go32 and coff-go32-exe.  */
+
+bfd_boolean
+_bfd_go32_mkobject (bfd *abfd)
+{
+  coff_data_type *coff;
+  bfd_size_type amt = sizeof (coff_data_type);
+
+  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
+  if (abfd->tdata.coff_obj_data == NULL)
+    return FALSE;
+  coff = coff_data (abfd);
+  coff->symbols = NULL;
+  coff->conversion_table = NULL;
+  coff->raw_syments = NULL;
+  coff->relocbase = 0;
+  coff->local_toc_sym_map = 0;
+
+  coff->go32 = 1;
+
+  return TRUE;
+}
diff -aprNU5 binutils-2.23.1.orig/bfd/coffcode.h binutils-2.23.1/bfd/coffcode.h
--- binutils-2.23.1.orig/bfd/coffcode.h	2011-09-27 16:03:48 +0000
+++ binutils-2.23.1/bfd/coffcode.h	2012-11-16 19:01:24 +0000
@@ -374,10 +374,14 @@ CODE_FRAGMENT
 #define DOT_DEBUG	".debug"
 #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
 #define GNU_LINKONCE_WT ".gnu.linkonce.wt."
 #define DOT_RELOC	".reloc"
 
+#if defined(COFF_WITH_PE) || defined(COFF_GO32_EXE) || defined(COFF_GO32)
+# define COFF_WITH_EXTENDED_RELOC_COUNTER
+#endif
+
 #if defined (COFF_LONG_SECTION_NAMES)
 /* Needed to expand the inputs to BLANKOR1TOODD.  */
 #define COFFLONGSECTIONCATHELPER(x,y)    x ## y
 /* If the input macro Y is blank or '1', return an odd number; if it is
    '0', return an even number.  Result undefined in all other cases.  */
@@ -1947,13 +1951,50 @@ coff_set_alignment_hook (bfd *abfd, asec
     }
 }
 
 #else /* ! RS6000COFF_C */
 
+#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
+
+static void
+coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
+			 asection * section,
+			 void * scnhdr)
+{
+  struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
+
+  /* Check for extended relocs.  */
+  if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
+    {
+      struct external_reloc dst;
+      struct internal_reloc n;
+      file_ptr oldpos = bfd_tell (abfd);
+      bfd_size_type relsz = bfd_coff_relsz (abfd);
+
+      if (bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0) != 0)
+	return;
+      if (bfd_bread (& dst, relsz, abfd) != relsz)
+	return;
+
+      coff_swap_reloc_in (abfd, &dst, &n);
+      if (bfd_seek (abfd, oldpos, 0) != 0)
+	return;
+      section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
+      section->rel_filepos += relsz;
+    }
+  else if (hdr->s_nreloc == 0xffff)
+    (*_bfd_error_handler)
+      ("%s: warning: claims to have 0xffff relocs, without overflow",
+       bfd_get_filename (abfd));
+}
+
+#else /* ! COFF_GO32_EXE && ! COFF_GO32 */
+
 #define coff_set_alignment_hook \
   ((void (*) (bfd *, asection *, void *)) bfd_void)
 
+#endif /* ! COFF_GO32_EXE && ! COFF_GO32 */
 #endif /* ! RS6000COFF_C */
 #endif /* ! COFF_WITH_PE */
 #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
 
 #ifndef coff_mkobject
@@ -2659,12 +2700,12 @@ coff_write_relocs (bfd * abfd, int first
 #endif
 
       if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
 	return FALSE;
 
-#ifdef COFF_WITH_PE
-      if (obj_pe (abfd) && s->reloc_count >= 0xffff)
+#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
+      if ((obj_pe (abfd) || obj_go32 (abfd)) && s->reloc_count >= 0xffff)
 	{
 	  /* Encode real count here as first reloc.  */
 	  struct internal_reloc n;
 
 	  memset (& n, 0, sizeof (n));
@@ -3564,10 +3605,14 @@ coff_apply_checksum (bfd *abfd)
   return TRUE;
 }
 
 #endif /* COFF_IMAGE_WITH_PE */
 
+#if defined (COFF_GO32_EXE) || defined (COFF_GO32)
+# define COFF_PAD_SECTION_HEADERS
+#endif
+
 static bfd_boolean
 coff_write_object_contents (bfd * abfd)
 {
   asection *current;
   bfd_boolean hasrelocs = FALSE;
@@ -3608,13 +3653,13 @@ coff_write_object_contents (bfd * abfd)
   /* Work out the size of the reloc and linno areas.  */
 
   for (current = abfd->sections; current != NULL; current =
        current->next)
     {
-#ifdef COFF_WITH_PE
+#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
       /* We store the actual reloc count in the first reloc's addr.  */
-      if (obj_pe (abfd) && current->reloc_count >= 0xffff)
+      if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
 	reloc_count ++;
 #endif
       reloc_count += current->reloc_count;
     }
 
@@ -3638,13 +3683,13 @@ coff_write_object_contents (bfd * abfd)
 
       if (current->reloc_count)
 	{
 	  current->rel_filepos = reloc_base;
 	  reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
-#ifdef COFF_WITH_PE
+#ifdef COFF_WITH_EXTENDED_RELOC_COUNTER
 	  /* Extra reloc to hold real count.  */
-	  if (obj_pe (abfd) && current->reloc_count >= 0xffff)
+	  if ((obj_pe (abfd) || obj_go32 (abfd)) && current->reloc_count >= 0xffff)
 	    reloc_base += bfd_coff_relsz (abfd);
 #endif
 	}
       else
 	current->rel_filepos = 0;
@@ -3961,10 +4006,22 @@ coff_write_object_contents (bfd * abfd)
 	}
     }
 #endif
 #endif
 
+#ifdef COFF_PAD_SECTION_HEADERS
+  if (abfd->flags & EXEC_P)
+  {
+    file_ptr cur_ptr = scn_base + abfd->section_count * bfd_coff_scnhsz(abfd);
+    long fill_size = (abfd->sections->filepos - cur_ptr);
+    bfd_byte *b = bfd_zmalloc(fill_size);
+    if (b)
+      bfd_bwrite ((PTR)b, fill_size, abfd);
+    free (b);
+  }
+#endif
+
   /* OK, now set up the filehdr...  */
 
   /* Don't include the internal abs section in the section count */
 
   /* We will NOT put a fucking timestamp in the header here. Every time you
diff -aprNU5 binutils-2.23.1.orig/bfd/cofflink.c binutils-2.23.1/bfd/cofflink.c
--- binutils-2.23.1.orig/bfd/cofflink.c	2012-07-13 14:22:44 +0000
+++ binutils-2.23.1/bfd/cofflink.c	2012-11-16 19:01:24 +0000
@@ -761,11 +761,11 @@ _bfd_coff_final_link (bfd *abfd,
 	  o->flags |= SEC_RELOC;
 	  o->rel_filepos = rel_filepos;
 	  rel_filepos += o->reloc_count * relsz;
 	  /* In PE COFF, if there are at least 0xffff relocations an
 	     extra relocation will be written out to encode the count.  */
-	  if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+	  if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff)
 	    rel_filepos += relsz;
 	}
 
       if (bfd_coff_long_section_names (abfd)
 	  && strlen (o->name) > SCNNMLEN)
@@ -1150,11 +1150,11 @@ _bfd_coff_final_link (bfd *abfd,
 	      bfd_coff_swap_reloc_out (abfd, irel, erel);
 	    }
 
 	  if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0)
 	    goto error_return;
-	  if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+	  if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff)
 	    {
 	      /* In PE COFF, write the count of relocs as the first
 		 reloc.  The header overflow bit will be set
 		 elsewhere. */
 	      struct internal_reloc incount;
diff -aprNU5 binutils-2.23.1.orig/bfd/coffswap.h binutils-2.23.1/bfd/coffswap.h
--- binutils-2.23.1.orig/bfd/coffswap.h	2009-09-05 07:56:22 +0000
+++ binutils-2.23.1/bfd/coffswap.h	2012-11-16 19:01:24 +0000
@@ -767,10 +767,23 @@ coff_swap_scnhdr_in (bfd * abfd, void *
   scnhdr_int->s_relptr = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
   scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
   scnhdr_int->s_flags = GET_SCNHDR_FLAGS (abfd, scnhdr_ext->s_flags);
   scnhdr_int->s_nreloc = GET_SCNHDR_NRELOC (abfd, scnhdr_ext->s_nreloc);
   scnhdr_int->s_nlnno = GET_SCNHDR_NLNNO (abfd, scnhdr_ext->s_nlnno);
+#if defined (COFF_GO32_EXE) || defined(COFF_GO32)
+  /* DJGPP follows the same strategy than PE COFF.
+     Iff the file is an executable then the higher 16 bits
+     of the line number have been stored in the relocation
+     counter field.  */
+  if (abfd->flags & EXEC_P
+      && (strcmp(scnhdr_ext->s_name, ".text") == 0))
+  {
+    scnhdr_int->s_nlnno = (GET_SCNHDR_NRELOC(abfd, scnhdr_ext->s_nreloc) << 16)
+                          + GET_SCNHDR_NLNNO(abfd, scnhdr_ext->s_nlnno);
+    scnhdr_int->s_nreloc = 0;
+  }
+#endif
 #ifdef I960
   scnhdr_int->s_align = GET_SCNHDR_ALIGN (abfd, scnhdr_ext->s_align);
 #endif
 #ifdef COFF_ADJUST_SCNHDR_IN_POST
   COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in);
@@ -797,10 +810,60 @@ coff_swap_scnhdr_out (bfd * abfd, void *
   PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr, scnhdr_ext->s_lnnoptr);
   PUT_SCNHDR_FLAGS (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags);
 #if defined(M88)
   H_PUT_32 (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno);
   H_PUT_32 (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc);
+#elif defined (COFF_GO32_EXE) || defined(COFF_GO32)
+  if (abfd->flags & EXEC_P
+      && (strcmp(scnhdr_int->s_name, ".text") == 0))
+    {
+      /* DJGPP follows the same strategy than PE COFF.
+	 By inference from looking at MS output, the 32 bit field
+	 which is the combination of the number_of_relocs and
+	 number_of_linenos is used for the line number count in
+	 executables.  A 16-bit field won't do for cc1.  The MS
+	 document says that the number of relocs is zero for
+	 executables, but the 17-th bit has been observed to be there.
+	 Overflow is not an issue: a 4G-line program will overflow a
+	 bunch of other fields long before this!  */
+      PUT_SCNHDR_NLNNO (abfd, (scnhdr_int->s_nlnno & 0xffff), scnhdr_ext->s_nlnno);
+      PUT_SCNHDR_NRELOC (abfd, (scnhdr_int->s_nlnno >> 16), scnhdr_ext->s_nreloc);
+    }
+  else
+    {
+      /* DJGPP follows the same strategy than PE COFF. */
+      if (scnhdr_int->s_nlnno <= MAX_SCNHDR_NLNNO)
+	PUT_SCNHDR_NLNNO (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno);
+      else
+	{
+	  char buf[sizeof (scnhdr_int->s_name) + 1];
+
+	  memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
+	  buf[sizeof (scnhdr_int->s_name)] = '\0';
+	  (*_bfd_error_handler)
+	   (_("%s: %s: line number overflow: 0x%lx > 0xffff"),
+	    bfd_get_filename (abfd),
+	    buf, scnhdr_int->s_nlnno);
+	  bfd_set_error (bfd_error_file_truncated);
+	  PUT_SCNHDR_NLNNO (abfd, 0xffff, scnhdr_ext->s_nlnno);
+	  ret = 0;
+	}
+
+      /* Although we could encode 0xffff relocs here, we do not, to be
+         consistent with other parts of bfd. Also it lets us warn, as
+         we should never see 0xffff here w/o having the overflow flag
+         set.  */
+      if (scnhdr_int->s_nreloc < MAX_SCNHDR_NRELOC)
+	PUT_SCNHDR_NRELOC (abfd, scnhdr_int->s_nreloc, scnhdr_ext->s_nreloc);
+      else
+	{
+	  /* DJGPP can deal with large #s of relocs, but not here.  */
+	  PUT_SCNHDR_NRELOC (abfd, 0xffff, scnhdr_ext->s_nreloc);
+	  scnhdr_int->s_flags |= IMAGE_SCN_LNK_NRELOC_OVFL;
+	  PUT_SCNHDR_FLAGS (abfd, scnhdr_int->s_flags, scnhdr_ext->s_flags);
+	}
+    }
 #else
   if (scnhdr_int->s_nlnno <= MAX_SCNHDR_NLNNO)
     PUT_SCNHDR_NLNNO (abfd, scnhdr_int->s_nlnno, scnhdr_ext->s_nlnno);
   else
     {
diff -aprNU5 binutils-2.23.1.orig/bfd/libcoff-in.h binutils-2.23.1/bfd/libcoff-in.h
--- binutils-2.23.1.orig/bfd/libcoff-in.h	2011-11-02 14:53:04 +0000
+++ binutils-2.23.1/bfd/libcoff-in.h	2012-11-16 19:01:24 +0000
@@ -25,10 +25,11 @@
 
 /* Object file tdata; access macros.  */
 
 #define coff_data(bfd)		      ((bfd)->tdata.coff_obj_data)
 #define obj_pe(bfd)                   (coff_data (bfd)->pe)
+#define obj_go32(bfd)                 (coff_data (bfd)->go32)
 #define obj_symbols(bfd)	      (coff_data (bfd)->symbols)
 #define	obj_sym_filepos(bfd)	      (coff_data (bfd)->sym_filepos)
 #define obj_relocbase(bfd)	      (coff_data (bfd)->relocbase)
 #define obj_raw_syments(bfd)	      (coff_data (bfd)->raw_syments)
 #define obj_raw_syment_count(bfd)     (coff_data (bfd)->raw_syment_count)
@@ -103,10 +104,12 @@ typedef struct coff_tdata
 
   /* Copy of some of the f_flags bits in the COFF filehdr structure,
      used by ARM code.  */
   flagword flags;
 
+  /* Is this a GO32 coff file?  */
+  int go32;
   /* coff-stgo32 EXE stub header after BFD tdata has been allocated.  Its data
      is kept in internal_filehdr.go32stub beforehand.  */
   char *go32stub;
 } coff_data_type;
 
diff -aprNU5 binutils-2.23.1.orig/binutils/readelf.c binutils-2.23.1/binutils/readelf.c
--- binutils-2.23.1.orig/binutils/readelf.c	2012-11-05 16:27:34 +0000
+++ binutils-2.23.1/binutils/readelf.c	2012-11-16 19:04:50 +0000
@@ -464,11 +464,16 @@ print_symbol (int width, const char *sym
 
 #ifdef HAVE_MBSTATE_T
 	  /* Try to find out how many bytes made up the character that was
 	     just printed.  Advance the symbol pointer past the bytes that
 	     were displayed.  */
+#ifdef __DJGPP__
+	  /* DJGPP does not provide mbrtowc.  */
+	  n = mbtowc (& w, symbol - 1, MB_CUR_MAX);
+#else
 	  n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
+#endif
 #else
 	  n = 1;
 #endif
 	  if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
 	    symbol += (n - 1);
diff -aprNU5 binutils-2.23.1.orig/config.sub binutils-2.23.1/config.sub
--- binutils-2.23.1.orig/config.sub	2012-04-25 15:53:24 +0000
+++ binutils-2.23.1/config.sub	2012-11-16 19:01:24 +0000
@@ -615,11 +615,19 @@ case $basic_machine in
 	dicos)
 		basic_machine=i686-pc
 		os=-dicos
 		;;
 	djgpp)
-		basic_machine=i586-pc
+		UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+		case $UNAME_MACHINE in
+			*386*) basic_machine=i386-pc;;
+			*486*) basic_machine=i486-pc;;
+			*586*) basic_machine=i586-pc;;
+			*686*) basic_machine=i686-pc;;
+			*786*) basic_machine=i786-pc;;
+			*)     basic_machine=i586-pc;;
+		esac
 		os=-msdosdjgpp
 		;;
 	dpx20 | dpx20-*)
 		basic_machine=rs6000-bull
 		os=-bosx
diff -aprNU5 binutils-2.23.1.orig/djgpp/build.sh binutils-2.23.1/djgpp/build.sh
--- binutils-2.23.1.orig/djgpp/build.sh	1970-01-01 00:00:00 +0000
+++ binutils-2.23.1/djgpp/build.sh	2012-11-16 19:01:24 +0000
@@ -0,0 +1,226 @@
+#  This script only works in the ./djgpp directory.
+
+export HOME=.
+export PATH_SEPARATOR=:
+export PATH_EXPAND=y
+export TEST_FINDS_EXE=y
+export LD=ld
+export NM=nm
+export LN_S="cp -p"
+export ac_cv_prog_LN_S="cp -p"
+export ac_cv_func_fork=no
+export ac_cv_func_mkfifo=no
+export ac_cv_func_mknod=no
+export ac_cv_func_mmap=no
+export ac_cv_func_pipe=no
+export ac_cv_func_vfork=no
+
+# Do not allow that the BFD's configure script determine the
+# host dependant file_ptr a.k.a. off_t type as BFD_HOST_64_BIT.
+# This is the case if ftello64 and fseeko64 are found.  But DJGPP
+# does not provide the full set of 64 bit file functions required
+# for a working 64 bit BFD.
+export ac_cv_func_fseeko64=${ac_cv_func_fseeko64=no}
+export ac_cv_func_ftello64=${ac_cv_func_ftello64=no}
+export ac_cv_have_decl_fseeko64=${ac_cv_have_decl_fseeko64=no}
+export ac_cv_have_decl_ftello64=${ac_cv_have_decl_ftello64=no}
+
+
+
+#
+#  1: Adjust the configure scripts.
+#
+
+cat > script.sed << EOF
+# For some reason the function does not work with bash 2.05b.
+/^func_lalib_p/,/^}$/ {
+  /test/ i\\
+    case \$1 in\\
+    *.la | *.lo)
+  /GREP/ {
+    s/$/;;/
+    a\\
+    *) false;;\\
+    esac
+  }
+}
+
+# The CR test for awk does not work for DJGPP.
+/^ac_cs_awk_cr=/,/^$/ {
+  /^fi$/ a\\
+ac_cs_awk_cr=\$ac_cr
+}
+
+# AWK program above erroneously prepends '/' to C:/dos/paths
+/# AWK program above erroneously prepends/,/esac/ {
+  s/mingw/*djgpp* | mingw/
+}
+
+# Force the test for 'ln -s' to report 'cp -pf'.
+/as_ln_s='ln -s'/ s/ln -s/cp -pf/
+EOF
+
+
+for file in ../ltmain.sh ../configure ../bfd/configure ../binutils/configure ../gas/configure ../gprof/configure ../ld/configure ../opcodes/configure; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+rm -vf ./file.out ./script.sed
+
+
+
+#
+#  2: Adjust the Makefile.ins and other files.
+#
+
+cat > script.sed << EOF
+# Fix for ./bfd/Makefile.in
+# Force the regenaration of libcoff.h
+# to define obj_go32
+/^\\\$(BFD_H):/ s/:/: stmp-lcoff-h/
+
+# For html docs.
+/^MAKEINFOHTML[ 	]*=/ s/$/ --no-split/
+
+# Fixes for ./libiberty/Makefile.in
+# ps support for libiberty docs.
+/dvi-subdir[ 	]\\{1,\\}pdf-subdir/ s/dvi-subdir[ 	]\\{1,\\}pdf-subdir/& ps-subdir/
+
+/^LIBIBERTY_PDFFILES[ 	]*=/ i\\
+LIBIBERTY_PSFILES = libiberty.ps\\
+\\
+ps: \\\$(LIBIBERTY_PSFILES) ps-subdir\\
+
+
+/^libiberty.pdf[ 	]*:/ i\\
+libiberty.ps : ./libiberty.dvi \\\$(srcdir)/libiberty.texi \\\$(TEXISRC)\\
+	dvips -o ./libiberty.ps ./libiberty.dvi\\
+
+# Fixes for ./etc/Makefile.in.
+/^HTMLFILES =.*configure.html$/ i\\
+PSFILES = standards.ps configure.ps
+/epstopdf/ s/[ 	]\\{1,\\}-outfile/ --outfile/
+EOF
+
+
+for file in ./../bfd/Makefile.in ./../bfd/doc/Makefile.in ./../binutils/doc/Makefile.in ./../etc/Makefile.in ./../gas/doc/Makefile.in ./../gprof/Makefile.in ./../ld/Makefile.in ./../libiberty/Makefile.in; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+
+rm -vf ./file.out ./script.sed
+
+
+
+#
+#  3: Adjust the config.in headers.
+#
+
+cat > script.sed << EOF
+# DJGPP 2.03 needs the snprintf prototype.
+/^#undef HAVE_DECL_SNPRINTF$/ c\\
+#include <sys/version.h>\\
+#if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4\\
+# define HAVE_DECL_SNPRINTF 0\\
+#else\\
+#undef HAVE_DECL_SNPRINTF\\
+#endif
+EOF
+
+
+for file in ../bfd/config.in ../binutils/config.in ../gold/config.in ../libiberty/config.in; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+rm -vf ./file.out ./script.sed
+
+
+cat > script.sed << EOF
+# DJGPP 2.03 needs the snprintf prototype.
+$ a\\
+\\
+#include <sys/version.h>\\
+#if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4\\
+/* Define to 1 if you have the declaration of snprintf, and to 0 if you\\
+   do not. */\\
+# define HAVE_DECL_SNPRINTF 0\\
+#endif
+EOF
+
+
+for file in ../gas/config.in ../gprof/gconfig.in ../ld/config.in ../opcodes/config.in; do
+  if test ! -f ${file}.orig; then
+    cp -vf ${file} ${file}.orig
+    touch ${file}.orig -r ${file}
+  fi
+  sed -f ./script.sed ${file}.orig > ./file.out
+  update ./file.out ${file}
+  touch ${file} -r ${file}.orig
+done
+rm -vf ./file.out ./script.sed
+
+
+
+#
+#  4: Configure and build the libs and programs.
+#
+
+touch start_build.txt
+
+echo
+echo Configuring the progs and libs.
+echo See build_log.txt file for output.
+
+
+echo Using: > build_log.txt
+gcc --version >> build_log.txt
+as --version >> build_log.txt
+echo >> build_log.txt
+ld --version >> build_log.txt
+echo >> build_log.txt
+echo >> build_log.txt
+echo >> build_log.txt
+
+echo Configuring the progs and libs for DJGPP. >> build_log.txt
+echo >>build_log.txt
+
+../configure  --disable-dependency-tracking --disable-nls \
+              --enable-install-bfd --enable-install-libiberty \
+              --with-mpc='/dev/env/DJDIR' --with-mpfr='/dev/env/DJDIR' --with-gmp='/dev/env/DJDIR' \
+              --enable-build-warnings=-Wimplicit,-Wcomment,-Wformat,-Wparentheses,-Wpointer-arith >> build_log.txt  2>&1
+
+echo >> build_log.txt
+echo ################################################################################ >> build_log.txt
+echo >> build_log.txt
+
+
+# Remove target alias from tooldir and scriptdir paths so
+# that the linker scripts and binaries are installed in
+# their DJGPP specific canonical places.
+sed "/^.*tooldir = /s|/.*$||" ./Makefile > file.out
+mv -vf ./file.out ./Makefile
+
+
+echo
+echo Building the progs and libs.
+echo See build_log.txt file for output.
+echo Building the progs and libs for DJGPP. >> build_log.txt
+echo >> build_log.txt
+make >> build_log.txt  2>&1
+
+touch stop_build.txt
diff -aprNU5 binutils-2.23.1.orig/gas/config/obj-coff-seh.c binutils-2.23.1/gas/config/obj-coff-seh.c
--- binutils-2.23.1.orig/gas/config/obj-coff-seh.c	2010-09-15 19:48:52 +0000
+++ binutils-2.23.1/gas/config/obj-coff-seh.c	2012-11-16 19:01:24 +0000
@@ -63,11 +63,11 @@ get_pxdata_name (segT seg, const char *b
   else if (dot < dollar)
     name = dot;
   else
     name = dollar;
 
-  sname = concat (base_name, name, NULL);
+  sname = concat (base_name, name, (char *)NULL);
 
   return sname;
 }
 
 /* Allocate a seh_seg_list structure.  */
diff -aprNU5 binutils-2.23.1.orig/gas/dw2gencfi.c binutils-2.23.1/gas/dw2gencfi.c
--- binutils-2.23.1.orig/gas/dw2gencfi.c	2011-08-07 16:32:20 +0000
+++ binutils-2.23.1/gas/dw2gencfi.c	2012-11-16 19:01:24 +0000
@@ -138,11 +138,11 @@ get_debugseg_name (segT seg, const char
 	name = dot;
       else
 	name = dollar;
     }
 
-  return concat (base_name, name, NULL);
+  return concat (base_name, name, (char *)NULL);
 }
 
 /* Allocate a dwcfi_seg_list structure.  */
 
 static struct dwcfi_seg_list *
diff -aprNU5 binutils-2.23.1.orig/ld/scripttempl/i386go32.sc binutils-2.23.1/ld/scripttempl/i386go32.sc
--- binutils-2.23.1.orig/ld/scripttempl/i386go32.sc	2012-06-29 07:58:46 +0000
+++ binutils-2.23.1/ld/scripttempl/i386go32.sc	2012-11-16 19:01:24 +0000
@@ -33,18 +33,27 @@ SECTIONS
   }
   .data ${RELOCATING+ ${DATA_ALIGNMENT}} : {
     ${RELOCATING+djgpp_first_ctor = . ;
     *(SORT(.ctors.*))
     *(.ctor)
+    *(.ctors)
     djgpp_last_ctor = . ;}
     ${RELOCATING+djgpp_first_dtor = . ;
     *(SORT(.dtors.*))
     *(.dtor)
+    *(.dtors)
     djgpp_last_dtor = . ;}
+    __environ = . ;
+    PROVIDE(_environ = .) ;
+    LONG(0) ;
     *(.data)
     ${RELOCATING+*(.data.*)}
 
+    /* Ugly workaround to prevent entire .bss to have attribute CONTENT */
+    /* for C++ executables. */
+    *(${RELOCATING+ .bss.*})
+
     ${RELOCATING+*(.gcc_exc*)}
     ${RELOCATING+___EH_FRAME_BEGIN__ = . ;}
     ${RELOCATING+*(.eh_fram*)}
     ${RELOCATING+___EH_FRAME_END__ = . ;}
     ${RELOCATING+LONG(0);}
@@ -55,11 +64,11 @@ SECTIONS
   }
   ${CONSTRUCTING+${RELOCATING-$CTOR}}
   ${CONSTRUCTING+${RELOCATING-$DTOR}}
   .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} :
   { 					
-    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
+    *(.bss${RELOCATING+ .gnu.linkonce.b.*})
     *(COMMON)
     ${RELOCATING+ end = . ; PROVIDE(_end = .) ;}
     ${RELOCATING+ . = ALIGN(${SEGMENT_SIZE});}
   }
   /* Stabs debugging sections.  */
diff -aprNU5 binutils-2.23.1.orig/libiberty/make-relative-prefix.c binutils-2.23.1/libiberty/make-relative-prefix.c
--- binutils-2.23.1.orig/libiberty/make-relative-prefix.c	2012-01-26 14:28:30 +0000
+++ binutils-2.23.1/libiberty/make-relative-prefix.c	2012-11-16 19:01:24 +0000
@@ -80,10 +80,11 @@ relative prefix can be found, return @co
 #if defined (_WIN32) || defined (__MSDOS__) \
     || defined (__DJGPP__) || defined (__OS2__)
 #  define HAVE_DOS_BASED_FILE_SYSTEM
 #  define HAVE_HOST_EXECUTABLE_SUFFIX
 #  define HOST_EXECUTABLE_SUFFIX ".exe"
+#  define FILENAME_COMPARE strcasecmp
 #  ifndef DIR_SEPARATOR_2 
 #    define DIR_SEPARATOR_2 '\\'
 #  endif
 #  define PATH_SEPARATOR ';'
 #else
@@ -95,10 +96,13 @@ relative prefix can be found, return @co
 #else
 #  define IS_DIR_SEPARATOR(ch) \
 	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
 #endif
 
+#ifndef FILENAME_COMPARE
+#  define FILENAME_COMPARE strcmp
+#endif
 #define DIR_UP ".."
 
 static char *save_string (const char *, int);
 static char **split_directories	(const char *, int *);
 static void free_split_directories (char **);
@@ -332,11 +336,11 @@ make_relative_prefix_1 (const char *prog
      we can do.  */
   if (prog_num == bin_num)
     {
       for (i = 0; i < bin_num; i++)
 	{
-	  if (strcmp (prog_dirs[i], bin_dirs[i]) != 0)
+	  if (FILENAME_COMPARE (prog_dirs[i], bin_dirs[i]) != 0)
 	    break;
 	}
 
       if (prog_num <= 0 || i == bin_num)
 	goto bailout;
@@ -348,11 +352,11 @@ make_relative_prefix_1 (const char *prog
 
   /* Find how many directories are in common between bin_prefix & prefix.  */
   n = (prefix_num < bin_num) ? prefix_num : bin_num;
   for (common = 0; common < n; common++)
     {
-      if (strcmp (bin_dirs[common], prefix_dirs[common]) != 0)
+      if (FILENAME_COMPARE (bin_dirs[common], prefix_dirs[common]) != 0)
 	break;
     }
 
   /* If there are no common directories, there can be no relative prefix.  */
   if (common == 0)
diff -aprNU5 binutils-2.23.1.orig/libiberty/make-temp-file.c binutils-2.23.1/libiberty/make-temp-file.c
--- binutils-2.23.1.orig/libiberty/make-temp-file.c	2011-01-03 21:05:58 +0000
+++ binutils-2.23.1/libiberty/make-temp-file.c	2012-11-16 19:01:24 +0000
@@ -53,16 +53,31 @@ extern int mkstemps (char *, int);
 /* '/' works just fine on MS-DOS based systems.  */
 #ifndef DIR_SEPARATOR
 #define DIR_SEPARATOR '/'
 #endif
 
+#if defined (_WIN32) || defined (__MSDOS__) \
+    || defined (__DJGPP__) || defined (__OS2__)
+#  define HAVE_DOS_BASED_FILE_SYSTEM
+#  ifndef DIR_SEPARATOR_2 
+#    define DIR_SEPARATOR_2 '\\'
+#  endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+#  define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else
+#  define IS_DIR_SEPARATOR(ch) \
+     (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif
+
 /* Name of temporary file.
    mktemp requires 6 trailing X's.  */
 #define TEMP_FILE "ccXXXXXX"
 #define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1)
 
-#if !defined(_WIN32) || defined(__CYGWIN__)
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__DJGPP__)
 
 /* Subroutine of choose_tmpdir.
    If BASE is non-NULL, return it.
    Otherwise it checks if DIR is a usable directory.
    If success, DIR is returned.
@@ -105,11 +120,11 @@ files in.
 char *
 choose_tmpdir (void)
 {
   if (!memoized_tmpdir)
     {
-#if !defined(_WIN32) || defined(__CYGWIN__)
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__DJGPP__)
       const char *base = 0;
       char *tmpdir;
       unsigned int len;
       
 #ifdef VMS
@@ -141,11 +156,12 @@ choose_tmpdir (void)
       /* Append DIR_SEPARATOR to the directory we've chosen
 	 and return it.  */
       len = strlen (base);
       tmpdir = XNEWVEC (char, len + 2);
       strcpy (tmpdir, base);
-      tmpdir[len] = DIR_SEPARATOR;
+      if (len > 0 && !IS_DIR_SEPARATOR(tmpdir[len - 1]))
+        tmpdir[len] = DIR_SEPARATOR;
       tmpdir[len+1] = '\0';
       memoized_tmpdir = tmpdir;
 #else /* defined(_WIN32) && !defined(__CYGWIN__) */
       DWORD len;
 
diff -aprNU5 binutils-2.23.1.orig/libiberty/pex-common.c binutils-2.23.1/libiberty/pex-common.c
--- binutils-2.23.1.orig/libiberty/pex-common.c	2011-04-20 19:06:46 +0000
+++ binutils-2.23.1/libiberty/pex-common.c	2012-11-16 19:01:24 +0000
@@ -115,11 +115,11 @@ temp_file (struct pex_obj *obj, int flag
 
           if (len >= 6
               && strcmp (obj->tempbase + len - 6, "XXXXXX") == 0)
             name = xstrdup (obj->tempbase);
           else
-            name = concat (obj->tempbase, "XXXXXX", NULL);
+            name = concat (obj->tempbase, "XXXXXX", (char *)NULL);
 
           out = mkstemps (name, 0);
           if (out < 0)
             {
               free (name);
@@ -136,11 +136,11 @@ temp_file (struct pex_obj *obj, int flag
   else if ((flags & PEX_SUFFIX) != 0)
     {
       if (obj->tempbase == NULL)
         name = make_temp_file (name);
       else
-        name = concat (obj->tempbase, name, NULL);
+        name = concat (obj->tempbase, name, (char *)NULL);
     }
 
   return name;
 }
 
@@ -220,11 +220,11 @@ pex_run_in_environment (struct pex_obj *
     {
       if (outname == NULL)
 	out = STDOUT_FILE_NO;
       else if ((flags & PEX_SUFFIX) != 0)
 	{
-	  outname = concat (obj->tempbase, outname, NULL);
+	  outname = concat (obj->tempbase, outname, (char *)NULL);
 	  outname_allocated = 1;
 	}
       obj->next_input = -1;
     }
   else if ((obj->flags & PEX_USE_PIPES) == 0)
