diff -c ./ar.c c:\emx\gnu\binutils/ar.c
*** ./ar.c	Wed Jun 13 06:47:50 1990
--- c:/emx/gnu/binutils/ar.c	Mon Nov 14 20:12:16 1994
***************
*** 1,3 ****
--- 1,5 ----
+ /* ar.c -- changed for emx by Eberhard Mattes -- Nov 1994 */
+ 
  /* ar.c - Archive modify and extract.
     Copyright (C) 1988 Free Software Foundation, Inc.
  
***************
*** 20,25 ****
--- 22,30 ----
  #include <errno.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #ifdef __EMX__
+ #include <stdlib.h>
+ #endif /* __EMX__ */
  
  #if !defined(A_OUT) && !defined(MACH_O)
  #define A_OUT
***************
*** 29,35 ****
--- 34,44 ----
  #ifdef COFF_ENCAPSULATE
  #include "a.out.encap.h"
  #else
+ #ifdef __EMX__
+ #include <a_out.h>
+ #else /* not __EMX__ */
  #include <a.out.h>
+ #endif /* not __EMX__ */
  #endif
  #endif
  
***************
*** 142,147 ****
--- 151,164 ----
  
  int preserve_dates;
  
+ #ifdef EMX
+ /* Nonzero means remove directory names from members when replacing
+    members.  */
+ 
+ int junk_paths;
+ 
+ #endif /* EMX */
+ 
  /* Operation to be performed.  */
  
  #define DELETE 1
***************
*** 298,303 ****
--- 315,324 ----
    files = 0;
    lock_indesc = -1;
  
+ #ifdef __EMX__
+   _response (&argc, &argv);
+   _wildcard (&argc, &argv);
+ #endif /* __EMX__ */
    if (argc < 2)
      usage ("too few command arguments", 0);
  
***************
*** 388,393 ****
--- 409,420 ----
  	      two_operations ();
  	    operation = EXTRACT;
  	    break;
+ 
+ #ifdef EMX
+ 	  case 'J':
+ 	    junk_paths = 1;
+ 	    break;
+ #endif /* EMX */
  	  }
        }
    
***************
*** 470,476 ****
--- 497,507 ----
       void (*function) ();
       int crflag;
  {
+ #ifdef __EMX__
+   FILE *arcstream = fopen (archive, "rb");
+ #else /* not __EMX__ */
    FILE *arcstream = fopen (archive, "r");
+ #endif /* not __EMX__ */
  
    if (arcstream == 0 && crflag)
      /* Creation-warning, if desired, will happen later.  */
***************
*** 591,597 ****
--- 622,632 ----
    FILE *ostream;
  
    fseek (istream, member.data_offset, 0);
+ #ifdef __EMX__
+   ostream = fopen (member.name, "wb");
+ #else /* not __EMX__ */
    ostream = fopen (member.name, "w");
+ #endif /* not __EMX__ */
    if (!ostream)
      {
        perror_with_name (member.name);
***************
*** 614,624 ****
--- 649,663 ----
        ncopied += tocopy;
      }
  
+ #ifdef __EMX__
+   chmod (member.name, member.mode);
+ #else /* not __EMX__ */
  #ifdef USG
    chmod (member.name, member.mode);
  #else
    fchmod (fileno (ostream), member.mode);
  #endif
+ #endif /* not __EMX__ */
    if (ferror (ostream) || fclose (ostream) != 0)
      error ("%s: I/O error", member.name);
  
***************
*** 776,782 ****
--- 815,825 ----
  {
    /* Open the existing archive file; if that fails, create an empty one.  */
  
+ #ifdef __EMX__
+   lock_indesc = open (archive, O_RDWR | O_BINARY, 0);
+ #else /* not __EMX__ */
    lock_indesc = open (archive, O_RDWR, 0);
+ #endif /* __EMX__ */
  
    if (lock_indesc < 0)
      {
***************
*** 784,790 ****
--- 827,837 ----
  
        if (!silent_create)
  	printf ("Creating archive file `%s'\n", archive);
+ #ifdef __EMX__
+       outdesc = open (archive, O_WRONLY | O_APPEND | O_CREAT | O_BINARY, 0666);
+ #else /* not __EMX__ */
        outdesc = open (archive, O_WRONLY | O_APPEND | O_CREAT, 0666);
+ #endif /* not __EMX__ */
        if (outdesc < 0)
  	pfatal_with_name (archive);
        mywrite (outdesc, ARMAG, SARMAG, archive);
***************
*** 792,798 ****
--- 839,849 ----
  
        /* Now we had better be able to open for update!  */
  
+ #ifdef __EMX__
+       lock_indesc = open (archive, O_RDWR | O_BINARY, 0);
+ #else /* not __EMX__ */
        lock_indesc = open (archive, O_RDWR, 0);
+ #endif /* not __EMX__ */
        if (lock_indesc < 0)
  	pfatal_with_name (archive);
      }
***************
*** 894,900 ****
--- 945,955 ----
  	 There can never be two invocations trying to do this at once,
  	 because of the lock made on the old archive file.  */
  
+ #ifdef __EMX__
+       outdesc = open (tempname, O_WRONLY | O_CREAT | O_BINARY, 0666);
+ #else /* not __EMX__ */
        outdesc = open (tempname, O_WRONLY | O_CREAT, 0666);
+ #endif /* not __EMX__ */
        if (outdesc < 0)
  	pfatal_with_name (tempname);
        outname = tempname;
***************
*** 904,910 ****
--- 959,969 ----
      {
        /* Fast-append to existing archive.  */
  
+ #ifdef __EMX__
+       outdesc = open (archive, O_WRONLY | O_APPEND | O_BINARY, 0);
+ #else /* not __EMX__ */
        outdesc = open (archive, O_WRONLY | O_APPEND, 0);
+ #endif /* not __EMX__ */
        if (outdesc < 0)
  	pfatal_with_name (archive);
        outname = archive;
***************
*** 992,1002 ****
--- 1051,1071 ----
  #endif
    close (outdesc);
  
+ #ifdef __EMX__
+   close_archive ();
+   if (!appendflag)
+     {
+     remove (archive);
+     if (rename (tempname, archive))
+       pfatal_with_name (tempname);
+     }
+ #else /* not __EMX__ */
    if (!appendflag)
      if (rename (tempname, archive))
        pfatal_with_name (tempname);
  
    close_archive ();
+ #endif /* not __EMX__ */
  }
  
  void
***************
*** 1005,1020 ****
--- 1074,1103 ----
       struct mapelt *mapelt;
  {
    unsigned int namelen;
+ #ifdef EMX
+   char *name;
+ #endif /* EMX */
  
    /* Zero the header, then store in the data as text.  */
    bzero ((char *) header, sizeof (*header));
  
+ #ifdef EMX
+   name = mapelt->info.name;
+   if (junk_paths) name = _getname (name);
+   strncpy (header->ar_name, name, sizeof (header->ar_name));
+   namelen = strlen (name);
+ #else /* not EMX */
    strncpy (header->ar_name, mapelt->info.name, sizeof (header->ar_name));
    namelen = strlen (mapelt->info.name);
+ #endif /* not EMX */
    if (namelen >= sizeof (header->ar_name))
      {
+ #ifdef EMX
+       if (name[namelen - 2] == '.' && name[namelen - 1] == 'o')
+ #else /* not EMX */
        if (mapelt->info.name[namelen - 2] == '.' &&
  	  mapelt->info.name[namelen - 1] == 'o')
+ #endif /* not EMX */
  	{
  	  header->ar_name[sizeof (header->ar_name) - 3] = '.';
  	  header->ar_name[sizeof (header->ar_name) - 2] = 'o';
***************
*** 1064,1070 ****
--- 1147,1157 ----
      }
    else
      {
+ #ifdef __EMX__
+       indesc = open (mapelt->info.name, O_BINARY, 0);
+ #else /* not __EMX__ */
        indesc = open (mapelt->info.name, 0, 0);
+ #endif /* not __EMX__ */
        if (indesc < 0)
  	{
  	  perror_with_name (mapelt->info.name);
***************
*** 1128,1134 ****
--- 1215,1225 ----
  make_tempname (name)
       char *name;
  {
+ #ifdef __EMX__
+   return concat (name, "", "$!");
+ #else /* not __EMX__ */
    return concat (name, "", "_supersede");
+ #endif /* not __EMX__ */
  }
  
  void
***************
*** 1380,1386 ****
--- 1471,1481 ----
        return;
      }
  
+ #ifdef __EMX__
+   arcstream = fopen (archive, "rb");
+ #else /* not __EMX__ */
    arcstream = fopen (archive, "r");
+ #endif /* not __EMX__ */
    if (!arcstream)
      fatal ("failure opening archive %s for the second time", archive);
    map = make_map (0);
***************
*** 1498,1509 ****
--- 1593,1618 ----
  	*syms_offset = N_SYMOFF (hdr);
  	*syms_size = hdr.a_syms;
  	*strs_offset = N_STROFF (hdr);
+ #ifdef __EMX__
+ 	if (hdr.a_syms == 0)
+ 	  *strs_size = sizeof *strs_size;
+ 	else
+ 	  {
+ 	    lseek (desc, N_STROFF (hdr) + offset, 0);
+ 	    if (read (desc, (char *) strs_size, sizeof *strs_size) != sizeof *strs_size)
+ 	      {
+ 		error_with_file ("failure reading string table size in ", mapelt);
+ 		return 0;
+ 	      }
+ 	  }
+ #else /* not __EMX__ */
  	lseek (desc, N_STROFF (hdr) + offset, 0);
  	if (read (desc, (char *) strs_size, sizeof *strs_size) != sizeof *strs_size)
  	  {
  	    error_with_file ("failure reading string table size in ", mapelt);
  	    return 0;
  	  }
+ #endif /* not __EMX__ */
  	return 1;
        }
    }
***************
*** 1584,1590 ****
--- 1693,1703 ----
      }
    else
      {
+ #ifdef __EMX__
+       indesc = open (mapelt->info.name, O_BINARY, 0);
+ #else /* not __EMX__ */
        indesc = open (mapelt->info.name, 0, 0);
+ #endif /* not __EMX__ */
        if (indesc < 0)
  	{
  	  perror_with_name (mapelt->info.name);
***************
*** 1603,1609 ****
--- 1716,1726 ----
    /* Number of symbol entries in the file.  */
    symcount = syms_size / sizeof (struct nlist);
    /* Allocate temporary space for the symbol entries.  */
+ #ifdef __EMX__
+   symbols = (struct nlist *) xmalloc (syms_size);
+ #else /* not __EMX__ */
    symbols = (struct nlist *) alloca (syms_size);
+ #endif /* not __EMX__ */
    /* Read in the symbols.  */
    lseek (indesc, syms_offset + offset, 0);
    if (read (indesc, (char *) symbols, syms_size) != syms_size)
***************
*** 1611,1616 ****
--- 1728,1736 ----
        error_with_file ("premature end of file in symbols of ", mapelt);
        if (mapelt->info.offset == 0)
  	(void) close (indesc);
+ #ifdef __EMX__
+       free (symbols);
+ #endif /* __EMX__ */
        return;
      }
  
***************
*** 1620,1625 ****
--- 1740,1748 ----
        error_with_file ("bad string table size in ", mapelt);
        if (mapelt->info.offset == 0)
  	(void) close (indesc);
+ #ifdef __EMX__
+       free (symbols);
+ #endif /* __EMX__ */
        return;
      }
    strs_size -= sizeof (strs_size);
***************
*** 1634,1639 ****
--- 1757,1765 ----
        error_with_file ("premature end of file in strings of ", mapelt);
        if (mapelt->info.offset == 0)
  	(void) close (indesc);
+ #ifdef __EMX__
+       free (symbols);
+ #endif /* __EMX__ */
        return;
      }
  
***************
*** 1658,1668 ****
--- 1784,1800 ----
  	  sprintf (buf, "ridiculous string offset %lu in symbol %u of ",
  		   stroff + sizeof (strs_size), i);
  	  error_with_file (buf, mapelt);
+ #ifdef __EMX__
+ 	  free (symbols);
+ #endif /* __EMX__ */
  	  return;
  	}
        mapelt->info.symdefs[i].s.name = symname;
        mapelt->info.string_size += strlen (symname) + 1;
      }
+ #ifdef __EMX__
+ free (symbols);
+ #endif /* __EMX__ */
  }
  
  /* Choose which symbol entries to mention in __.SYMDEF;
***************
*** 1906,1913 ****
--- 2038,2047 ----
  perror_with_name (name)
       char *name;
  {
+ #ifndef __EMX__
    extern int errno, sys_nerr;
    extern char *sys_errlist[];
+ #endif /* not __EMX__ */
    char *s;
  
    if (errno < sys_nerr)
***************
*** 1921,1928 ****
--- 2055,2064 ----
  pfatal_with_name (name)
       char *name;
  {
+ #ifndef __EMX__
    extern int errno, sys_nerr;
    extern char *sys_errlist[];
+ #endif /* not __EMX__ */
    char *s;
  
    if (errno < sys_nerr)
diff -c ./getopt.c c:\emx\gnu\binutils/getopt.c
*** ./getopt.c	Sat Jun 16 16:19:42 1990
--- c:/emx/gnu/binutils/getopt.c	Sun Nov 27 22:15:24 1994
***************
*** 1,3 ****
--- 1,5 ----
+ /* getopt.c -- changed for emx by Eberhard Mattes -- Nov 1994 */
+ 
  /* Getopt for GNU.
     Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  
***************
*** 20,25 ****
--- 22,31 ----
  #else
  #define CONST
  #endif
+ 
+ #ifdef __EMX__
+ #include <strings.h>
+ #endif /* __EMX__ */
  
  /* This version of `getopt' appears to the caller like standard Unix `getopt'
     but it behaves differently for the user, since it allows the user
diff -c ./getopt1.c c:\emx\gnu\binutils/getopt1.c
*** ./getopt1.c	Mon Apr 16 18:51:20 1990
--- c:/emx/gnu/binutils/getopt1.c	Sun Nov 27 22:15:30 1994
***************
*** 1,3 ****
--- 1,5 ----
+ /* getopt1.c -- changed for emx by Eberhard Mattes -- Nov 1994 */
+ 
  /* Getopt for GNU.
     Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  
***************
*** 15,20 ****
--- 17,26 ----
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  
+ #ifdef __EMX__
+ #include <strings.h>
+ #endif /* __EMX__ */
+ 
  #include "getopt.h"
  
  #ifdef __STDC__
diff -c ./ld.c c:\emx\gnu\binutils/ld.c
*** ./ld.c	Fri Jul 06 12:48:52 1990
--- c:/emx/gnu/binutils/ld.c	Sun Nov 27 22:24:18 1994
***************
*** 1,3 ****
--- 1,5 ----
+ /* ld.c -- changed for emx by Eberhard Mattes -- Nov 1994 */
+ 
  /* Linker `ld' for GNU
     Copyright (C) 1988 Free Software Foundation, Inc.
  
***************
*** 20,25 ****
--- 22,31 ----
  
  #include <ar.h>
  #include <stdio.h>
+ #ifdef EMX /* host */
+ #include <stdlib.h>
+ #include <process.h>        /* for running emxbind */
+ #endif /* EMX */
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/file.h>
***************
*** 39,45 ****
--- 45,55 ----
  #ifdef COFF_ENCAPSULATE
  #include "a.out.encap.h"
  #else
+ #ifdef EMX /* host */
+ #include <a_out.h>
+ #else /* !EMX */
  #include <a.out.h>
+ #endif /* !EMX */
  #endif
  #endif
  
***************
*** 56,61 ****
--- 66,84 ----
  #include <sys/loader.h>
  #endif
  
+ #ifdef EMX /* fix bugs */
+ 
+ /* Fix two bugs in processing of set vectors:
+ 
+    o  The size of the set vector section is not correctly computed
+ 
+    o  References to set vectors can be wrong by up to sizeof (double) - 1
+       bytes because padding occurs at the wrong place */
+ 
+ #define FIXSETBUG
+ 
+ #endif /* EMX */
+ 
  #ifndef N_SET_MAGIC
  #define N_SET_MAGIC(exec, val)  ((exec).a_magic = val)
  #endif
***************
*** 493,498 ****
--- 516,525 ----
  #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
  #endif				/* This is output from LD.  */
  
+ #ifdef EMX /* import */
+ #define N_IMP1  0x68            /* Import definition symbol */
+ #endif /* EMX */
+ 
  /* If a this type of symbol is encountered, its name is a warning
     message to print each time the symbol referenced by the next symbol
     table entry is referenced.
***************
*** 587,598 ****
--- 614,634 ----
  
  /* Demangler for C++.  */
  extern char *cplus_demangle ();
+ #ifdef EMX /* demangling */
+ #include "demangle.h"
+ static char *my_cplus_demangle ();
+ int demangle_options;
+ #endif /* EMX */
  
  /* Demangler function to use.  We unconditionally enable the C++ demangler
     because we assume any name it successfully demangles was probably produced
     by the C++ compiler.  Enabling it only if -lg++ was specified seems too
     much of a kludge.  */
+ #ifdef EMX /* demangling */
+ char *(*demangler)() = my_cplus_demangle;
+ #else /* !EMX */
  char *(*demangler)() = cplus_demangle;
+ #endif /* !EMX */
  
  /* Number of buckets in symbol hash table */
  #define	TABSIZE	1009
***************
*** 835,840 ****
--- 871,888 ----
  /* The name of the file to write; "a.out" by default.  */
  
  char *output_filename;
+ #ifdef EMX /* emxbind, relocatable */
+ char *exe_filename;
+ char *def_filename = NULL;
+ char *res_filename = NULL;
+ char *map_filename = NULL;
+ int reloc_flag = 0;
+ int dll_flag = 0;
+ int exe_flag = 0;
+ int map_flag = 0;
+ int stack_size = 0;
+ int emxbind_strip = 0;
+ #endif /* EMX */
  
  /* What kind of output file to write.  */
  
***************
*** 914,919 ****
--- 962,972 ----
  
  int text_pad;
  
+ #ifdef FIXSETBUG
+ /* Amount of padding between data segment and set vectors. */
+ int set_sect_pad;
+ #endif /* FIXSETBUG */
+ 
  /* Amount of padding at end of data segment.  This has two parts:
     That which is before the bss segment, and that which overlaps
     with the bss segment.  */
***************
*** 979,985 ****
--- 1032,1042 ----
  #ifdef NON_NATIVE
    {"/usr/local/lib/gnu"};
  #else
+ #ifdef EMX /* host */
+   {"/emx/lib"};
+ #else /* !EMX */
    {"/lib", "/usr/lib", "/usr/local/lib"};
+ #endif /* !EMX */
  #endif
  #endif
  
***************
*** 1010,1017 ****
--- 1067,1076 ----
  #ifndef bcopy
  void bcopy (), bzero ();
  #endif
+ #ifndef EMX /* host */
  char *malloc (), *realloc ();
  void free ();
+ #endif /* !EMX */
  
  char *xmalloc ();
  char *xrealloc ();
***************
*** 1045,1056 ****
--- 1104,1121 ----
  char *concat ();
  char *get_file_name ();
  symbol *getsym (), *getsym_soft ();
+ #ifdef EMX /* emxbind */
+ void check_exe (void);
+ #endif /* EMX */
  
  int
  main (argc, argv)
       char **argv;
       int argc;
  {
+ #ifdef EMX /* host */
+   _response (&argc, &argv);
+ #endif /* EMX */
    page_size = getpagesize ();
    progname = argv[0];
  
***************
*** 1073,1078 ****
--- 1138,1146 ----
    text_reloc_size = 0;
    data_reloc_size = 0;
  
+ #ifdef FIXSETBUG
+   set_sect_pad = 0;
+ #endif /* FIXSETBUG */
    data_pad = 0;
    text_pad = 0;
  
***************
*** 1116,1121 ****
--- 1184,1193 ----
  
    decode_command (argc, argv);
  
+ #ifdef EMX /* emxbind */
+   check_exe ();
+ #endif /* EMX */
+ 
    /* Load symbols of all input files.
       Also search all libraries and decide which library members to load.  */
  
***************
*** 1172,1177 ****
--- 1244,1257 ----
    {"D", 1, 0, 'D'},
    {"M", 0, 0, 'M'},
    {"N", 0, 0, 'N'},
+ #ifdef EMX /* emxbind, relocatable, demangling */
+   {"R", 0, 0, 'R'},             /* Create relocatable executable */
+   {"Zexe", 0, 0, 135},          /* Create .exe file, touch `output file' */
+   {"Zstack", 1, 0, 136},        /* Set stack size */
+   {"Zmap", 2, 0, 137},          /* Create .map file */
+   {"Zno-demangle", 0, 0, 138},  /* Don't demangle symbols */
+   {"Zdemangle-proto", 0, 0, 139},  /* Demangle symbols complete */
+ #endif /* EMX */
    {"S", 0, 0, 'S'},
    {"T", 1, 0, 'T'},
    {"Ttext", 1, 0, 'T'},
***************
*** 1331,1336 ****
--- 1411,1443 ----
  	  output_style = OUTPUT_WRITABLE_TEXT;
  	  break;
  
+ #ifdef EMX /* emxbind, relocatable, demangling */
+         case 135:               /* -Zexe */
+           exe_flag = 1;
+           break;
+ 
+         case 136:               /* -Zstack */
+ 	  stack_size = parse (optarg, "%i", "invalid argument to -Zstack");
+ 	  break;
+ 
+         case 137:               /* -Zmap */
+ 	  map_filename = optarg;
+ 	  map_flag = 1;
+ 	  break;
+ 
+         case 138:               /* -Zno-demangle */
+           demangler = 0;
+           break;
+ 
+         case 139:               /* -Zdemangle-proto */
+           demangle_options = DMGL_PARAMS | DMGL_ANSI;
+           break;
+ 
+         case 'R':
+ 	  reloc_flag = 1;
+ 	  break;
+ #endif /* EMX */
+ 
  	case 'S':
  	  strip_symbols = STRIP_DEBUGGER;
  	  break;
***************
*** 1384,1389 ****
--- 1491,1515 ----
  	{
  	case 1:
  	  /* Non-option argument. */
+ #ifdef EMX /* emxbind */
+ 	  {
+ 	    char *ext = _getext (optarg);
+ 	    if (ext != NULL && stricmp (ext, ".def") == 0
+ 		&& def_filename == NULL)
+ 	      {
+ 		def_filename = optarg;
+ 		--number_of_files;
+ 		break;
+ 	      }
+             else if (ext != NULL && stricmp (ext, ".res") == 0
+                      && res_filename == NULL)
+ 	      {
+ 		res_filename = optarg;
+ 		--number_of_files;
+ 		break;
+ 	      }
+ 	  }
+ #endif /* EMX */
  	  p->filename = optarg;
  	  p->local_sym_name = optarg;
  	  p++;
***************
*** 1399,1405 ****
--- 1525,1535 ----
  	  break;
  
  	case 'l':
+ #ifdef EMX /* host */
+ 	  p->filename = concat ("", optarg, ".a");
+ #else /* !EMX */
  	  p->filename = concat ("lib", optarg, ".a");
+ #endif /* !EMX */
  	  p->local_sym_name = concat ("-l", optarg, "");
  	  p->search_dirs_flag = 1;
  	  p++;
***************
*** 1604,1610 ****
--- 1734,1744 ----
  	{
  	  register char *string
  	    = concat (search_dirs[i], "/", entry->filename);
+ #ifdef EMX /* host */
+ 	  desc = open (string, O_RDONLY|O_BINARY, 0);
+ #else /* !EMX */
  	  desc = open (string, O_RDONLY, 0);
+ #endif /* !EMX */
  	  if (desc > 0)
  	    {
  	      entry->filename = string;
***************
*** 1615,1621 ****
--- 1749,1759 ----
  	}
      }
    else
+ #ifdef EMX /* host */
+     desc = open (entry->filename, O_RDONLY|O_BINARY, 0);
+ #else /* !EMX */
      desc = open (entry->filename, O_RDONLY, 0);
+ #endif /* !EMX */
  
    if (desc > 0)
      {
***************
*** 2113,2118 ****
--- 2251,2260 ----
    for (p = entry->symbols; p < end; p++)
      {
        if (p->n_type == (N_SETV | N_EXT)) continue;
+ #ifdef EMX /* import, relocatable */
+       if (p->n_type == (N_IMP1 | N_EXT))
+         reloc_flag = 1;
+ #endif /* EMX */
        if (set_element_prefixes
  	  && set_element_prefixed_p (p->n_un.n_strx + entry->strings))
  	p->n_type += (N_SETA - N_ABS);
***************
*** 2348,2353 ****
--- 2490,2500 ----
  */
  #endif
  
+ #ifdef EMX /* import */
+         case N_IMP1:
+           reftype = "imported";
+           break;
+ #endif /* EMX */
  	default:
  	  reftype = "I don't know this type";
  	  break;
***************
*** 2820,2825 ****
--- 2967,2982 ----
  
    initialize_data_start ();
  
+ #ifdef FIXSETBUG
+   /* Make sure the set vectors are aligned properly. */
+   {
+     int new_data_size = ((data_size + sizeof(unsigned long) - 1)
+                          & ~(sizeof(unsigned long)-1));
+ 
+     set_sect_pad += new_data_size - data_size;
+     data_size = new_data_size;
+   }
+ #else /* !FIXSETBUG */
    /* Make sure bss starts out aligned as much as anyone can want.  */
    {
      int new_data_size = (data_size + sizeof(double) - 1) & ~(sizeof(double)-1);
***************
*** 2827,2832 ****
--- 2984,2990 ----
      data_pad += new_data_size - data_size;
      data_size = new_data_size;
    }
+ #endif /* !FIXSETBUG */
  
    /* Set up the set element vector */
  
***************
*** 2836,2849 ****
--- 2994,3022 ----
           for each symbol for the length word at the beginning of the
  	 vector, plus a word for each symbol for a zero at the end of
  	 the vector (for incremental linking).  */
+ #ifdef FIXSETBUG
+       set_sect_size
+ 	= (set_symbol_count + 2 * set_vector_count) * sizeof (unsigned long);
+ #else /* !FIXSETBUG */
        set_sect_size
  	= (2 * set_symbol_count + set_vector_count) * sizeof (unsigned long);
+ #endif /* !FIXSETBUG */
        set_sect_start = data_start + data_size;
        data_size += set_sect_size;
        set_vectors = (unsigned long *) xmalloc (set_sect_size);
        setv_fill_count = 0;
      }
  
+ #ifdef FIXSETBUG
+   /* Make sure bss starts out aligned as much as anyone can want.  */
+   {
+     int new_data_size = (data_size + sizeof(double) - 1) & ~(sizeof(double)-1);
+ 
+     data_pad += new_data_size - data_size;
+     data_size = new_data_size;
+   }
+ #endif /* FIXSETBUG */
+ 
    /* Compute start addresses of each file's sections and symbols.  */
  
    each_full_file (relocate_file_addresses, 0);
***************
*** 2890,2896 ****
--- 3063,3074 ----
  		    }
  		  set_vectors[setv_fill_count++] = p->n_value;
  		}
+ #ifdef EMX /* import */
+ 	      else if ((type & N_EXT) && type != (N_UNDF | N_EXT)
+                        && type != (N_IMP1 | N_EXT))
+ #else /* !EMX */
  	      else if ((type & N_EXT) && type != (N_UNDF | N_EXT))
+ #endif /* !EMX */
  		{
  		  /* non-common definition */
  		  if (defs++ && sp->value != p->n_value)
***************
*** 3877,3883 ****
--- 4055,4065 ----
  
    outheader.a_syms = nsyms * sizeof (struct nlist);
  
+ #ifdef EMX /* relocatable */
+   if (output_style == OUTPUT_RELOCATABLE || reloc_flag)
+ #else /* !EMX */
    if (output_style == OUTPUT_RELOCATABLE)
+ #endif /* !EMX */
      {
        outheader.a_trsize = text_reloc_size;
        outheader.a_drsize = data_reloc_size;
***************
*** 4501,4506 ****
--- 4683,4722 ----
    fatal ("unknown output file type (enum file_type)", (char *) 0);
  }
  
+ #ifdef EMX /* emxbind */
+ /* Parse output_filename and decide whether to create an exe file or not */
+ 
+ void check_exe (void)
+ {
+   char *ext;
+   int i;
+ 
+   if (exe_flag)
+     output_filename = concat (output_filename, ".exe", "");
+   ext = _getext (output_filename);
+   if (ext == NULL
+       || (stricmp (ext+1, "exe") != 0 && stricmp (ext+1, "dll") != 0))
+     {
+       exe_filename = NULL;
+       return;
+     }
+   if (stricmp (ext+1, "dll") == 0)
+     {
+       reloc_flag = 1; dll_flag = 1;
+     }
+   i = ext - output_filename;
+   exe_filename = output_filename;
+   output_filename = xmalloc (i + 1);
+   memcpy (output_filename, exe_filename, i);
+   output_filename[i] = 0;     /* remove .exe */
+   if (strip_symbols == STRIP_ALL)
+     {
+       strip_symbols = STRIP_DEBUGGER;
+       emxbind_strip = 1;
+     }
+ }
+ #endif /* EMX */
+ 
  /* Write the output file */
  
  void
***************
*** 4519,4525 ****
--- 4735,4747 ----
       the way Unix ld works; I'm going to consider it a feature.  */
    (void) unlink (output_filename);
    
+ #ifdef EMX /* emxbind, host */
+   if (exe_filename != NULL)
+     unlink (exe_filename);
+   outdesc = open (output_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
+ #else /* !EMX */
    outdesc = open (output_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ #endif /* !EMX */
    if (outdesc < 0) perror_name (output_filename);
  
    if (fstat (outdesc, &statbuf) < 0)
***************
*** 4527,4533 ****
--- 4749,4757 ----
  
    filemode = statbuf.st_mode;
  
+ #ifndef EMX /* host */
    chmod (output_filename, filemode & ~0111);
+ #endif /* !EMX */
  
    /* Calculate the offsets of the various pieces of the output file.  */
    compute_section_offsets ();
***************
*** 4537,4543 ****
--- 4761,4771 ----
    write_data ();
  
    /* Output the merged relocation info, if requested with `-r'.  */
+ #ifdef EMX /* relocatable */
+   if (output_style == OUTPUT_RELOCATABLE || reloc_flag)
+ #else /* !EMX */
    if (output_style == OUTPUT_RELOCATABLE)
+ #endif /* !EMX */
      write_rel ();
  
    /* Output the symbol table (both globals and locals).  */
***************
*** 4560,4565 ****
--- 4788,4867 ----
  
    if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
      perror_name (output_filename);
+ 
+ #ifdef EMX /* emxbind */
+   if (exe_filename != NULL)
+     {
+       char *nargv[11];
+       char emxl_path[512];
+       int i, saved_errno;
+ 
+       i = 0;
+       nargv[i++] = "emxbind";
+       nargv[i++] = "-bq";
+       if (emxbind_strip)
+         nargv[i++] = "-s";
+       if (def_filename != NULL)
+ 	{
+ 	  nargv[i] = alloca (strlen (def_filename) + 3);
+ 	  strcpy (nargv[i], "-d");
+ 	  strcat (nargv[i], def_filename);
+ 	  i++;
+ 	}
+       else if (dll_flag)
+ 	nargv[i++] = "-d";
+       if (stack_size != 0)
+ 	{
+ 	  nargv[i] = alloca (20);
+           sprintf (nargv[i], "-k0x%x", stack_size);
+ 	  i++;
+ 	}
+       if (map_flag)
+ 	{
+ 	  if (map_filename == NULL)
+ 	    {
+ 	      map_filename = alloca (strlen (output_filename) + 5);
+ 	      strcpy (map_filename, output_filename);
+ 	      _remext (map_filename);
+ 	      strcat (map_filename, ".map");
+ 	    }
+ 	  nargv[i] = alloca (strlen (map_filename) + 3);
+           strcpy (nargv[i], "-m");
+           strcat (nargv[i], map_filename);
+ 	  i++;
+ 	}
+       if (res_filename != NULL)
+ 	{
+ 	  nargv[i] = alloca (strlen (res_filename) + 3);
+ 	  strcpy (nargv[i], "-r");
+ 	  strcat (nargv[i], res_filename);
+ 	  i++;
+ 	}
+       if (_path (emxl_path, "emxl.exe") == 0)
+ 	nargv[i++] = emxl_path;
+       else
+ 	nargv[i++] = "/emx/bin/emxl.exe";
+       nargv[i++] = output_filename;
+       nargv[i++] = exe_filename;
+       nargv[i] = NULL;
+       i = spawnvp (P_WAIT, "emxbind", nargv);
+       saved_errno = errno; unlink (output_filename); errno = saved_errno;
+       if (i < 0)
+         perror_name ("emxbind");
+       else if (i != 0)
+         fatal ("emxbind failed\n", NULL);
+       if (chmod (exe_filename, filemode | (0111 & ~mask)) == -1)
+ 	perror_name (exe_filename);
+       if (exe_flag)
+         {
+           i = open (output_filename,
+                     O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
+           if (i < 0)
+             perror_name (output_filename);
+           close (i);
+         }
+     }
+ #endif /* EMX */
  }
  
  void modify_location (), perform_relocation (), copy_text (), copy_data ();
***************
*** 4661,4667 ****
--- 4963,4973 ----
    /* Deal with relocation information however is appropriate */
  
    if (entry->textrel)  reloc = entry->textrel;
+ #ifdef EMX /* relocatable */
+   else if (output_style == OUTPUT_RELOCATABLE || reloc_flag)
+ #else /* !EMX */
    else if (output_style == OUTPUT_RELOCATABLE)
+ #endif /* !EMX */
      {
        read_file_relocation (entry);
        reloc = entry->textrel;
***************
*** 4712,4720 ****
--- 5018,5035 ----
    /* Write out the set element vectors.  See digest symbols for
       description of length of the set vector section.  */
  
+ #ifdef FIXSETBUG
+   padfile (set_sect_pad, outdesc);
+ #endif /* FIXSETBUG */
+ 
    if (set_vector_count)
+ #ifdef FIXSETBUG
+     mywrite (set_vectors, set_symbol_count + 2 * set_vector_count,
+ 	     sizeof (unsigned long), outdesc);
+ #else /* !FIXSETBUG */
      mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
  	     sizeof (unsigned long), outdesc);
+ #endif /* !FIXSETBUG */
  
    if (trace_files)
      fprintf (stderr, "\n");
***************
*** 4743,4749 ****
--- 5058,5068 ----
    bytes = (char *) alloca (entry->data_size);
  
    if (entry->datarel) reloc = entry->datarel;
+ #ifdef EMX /* relocatable */
+   else if (output_style == OUTPUT_RELOCATABLE || reloc_flag) /* Will need this again */
+ #else /* !EMX */
    else if (output_style == OUTPUT_RELOCATABLE)	/* Will need this again */
+ #endif /* !EMX */
      {
        read_file_relocation (entry);
        reloc = entry->datarel;
***************
*** 5040,5046 ****
--- 5359,5369 ----
  	  /* If the symbol is now defined, change the external relocation
  	     to an internal one.  */
  
+ #ifdef EMX /* import */
+ 	  if (symptr->defined && symptr->defined != (N_IMP1 | N_EXT))
+ #else /* !EMX */
  	  if (symptr->defined)
+ #endif /* !EMX */
  	    {
  	      RELOC_EXTERN_P(p) = 0;
  	      RELOC_SYMBOL(p) = (symptr->defined & ~N_EXT);
***************
*** 5206,5212 ****
--- 5529,5539 ----
    lseek (outdesc, output_strs_offset + output_strs_size, 0);
  
    if (!outstream)
+ #ifdef EMX /* host */
+     outstream = fdopen (outdesc, "wb");
+ #else /* !EMX */
      outstream = fdopen (outdesc, "w");
+ #endif /* !EMX */
  
    for (i = 0; i < strtab_index; i++)
      {
***************
*** 5425,5431 ****
--- 5752,5772 ----
        struct nlist nl;
  
        nl.n_type = N_TEXT;
+ #ifdef EMX /* fix GCC/ld/GDB problem */
+       {
+         char *tmp;
+         int len;
+ 
+         tmp = entry->local_sym_name;
+         len = strlen (tmp);
+         if (strncmp (tmp, "-l", 2) != 0
+             && (len < 2 || strcmp (tmp+len-2, ".o") != 0))
+           tmp = concat (tmp, ".o", "");   /* Needed by GDB */
+         nl.n_un.n_strx = assign_string_table_index (tmp);
+       }
+ #else /* !EMX */
        nl.n_un.n_strx = assign_string_table_index (entry->local_sym_name);
+ #endif /* !EMX */
        nl.n_value = entry->text_start_address;
        nl.n_desc = 0;
  #ifdef N_SECT
***************
*** 5783,5790 ****
--- 6124,6133 ----
  perror_name (name)
       char *name;
  {
+ #ifndef EMX /* host */
    extern int errno, sys_nerr;
    extern char *sys_errlist[];
+ #endif /* !EMX */
    char *s;
  
    if (errno < sys_nerr)
***************
*** 5801,5808 ****
--- 6144,6153 ----
  perror_file (entry)
       struct file_entry *entry;
  {
+ #ifndef EMX /* host */
    extern int errno, sys_nerr;
    extern char *sys_errlist[];
+ #endif /* !EMX */
    char *s;
  
    if (errno < sys_nerr)
***************
*** 5952,5954 ****
--- 6297,6310 ----
    return 8192;
  }
  #endif
+ 
+ #ifdef EMX /* demangling */
+ 
+ char *my_cplus_demangle (const char *mangled)
+ {
+   if (*mangled == '_')
+     ++mangled;
+   return cplus_demangle (mangled, demangle_options);
+ }
+ 
+ #endif /* EMX */
diff -c ./Makefile c:\emx\gnu\binutils/makefile
*** ./Makefile	Thu Jun 21 18:05:48 1990
--- c:/emx/gnu/binutils/makefile	Tue Nov 01 15:14:20 1994
***************
*** 19,29 ****
  # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  
  
! GNUCC = gcc -O
! bindir=/usr/local/bin
  
- # for BSD systems
- CFLAGS = -g
  # Don't add robotussin; it won't compile on BSD or GNU systems.
  # objdump is not here because it (at least used to) not compile
  # on most systems (trouble with N_DATADDR).  I've fixed some of
--- 19,34 ----
  # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  
  
! GNUCC = gcc
! CC = gcc
! bindir=/emx/bin
! 
! .c.o:
! 	$(CC) $(CFLAGS) -c $*.c
! 
! # for emx (-g breaks ar!)
! CFLAGS = -O -I. -DEMX
  
  # Don't add robotussin; it won't compile on BSD or GNU systems.
  # objdump is not here because it (at least used to) not compile
  # on most systems (trouble with N_DATADDR).  I've fixed some of
***************
*** 74,89 ****
  # rounds this up to a power of two (e.g. 5M becomes 8M), and so it might 
  # fail unnecessarily.  I've also seen some unix malloc's fail, even when
  # there is enough memory.  So use the new GNU malloc.
! MALLOC = $(archpfx)gmalloc.o
  
  GNU_GETOPT = $(archpfx)getopt.o
  GNU_GETOPT_LONG = $(archpfx)getopt.o $(archpfx)getopt1.o
  
  # C++ demangler
! CPLUS_DEM = $(archpfx)cplus-dem.o
  
  LIBS=$(ALLOCALIBS) $(SIGNAME)
  
  all: $(PROGS)
  
  $(archpfx)ld: $(archpfx)ld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM)
--- 79,96 ----
  # rounds this up to a power of two (e.g. 5M becomes 8M), and so it might 
  # fail unnecessarily.  I've also seen some unix malloc's fail, even when
  # there is enough memory.  So use the new GNU malloc.
! # MALLOC = $(archpfx)gmalloc.o
  
  GNU_GETOPT = $(archpfx)getopt.o
  GNU_GETOPT_LONG = $(archpfx)getopt.o $(archpfx)getopt1.o
  
  # C++ demangler
! CPLUS_DEM = $(archpfx)cplus-de.o
  
  LIBS=$(ALLOCALIBS) $(SIGNAME)
  
+ bin4emx: ar ld size nm objdump strip
+ 
  all: $(PROGS)
  
  $(archpfx)ld: $(archpfx)ld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM)
***************
*** 115,121 ****
  $(archpfx)ranlib.o: ranlib.c
  	$(CC) -c $(CFLAGS) -DAR_PROG=\"$(bindir)/ar\" ranlib.c $(OUTPUT_OPTION)
  
! $(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
  	$(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
  		$(GNU_GETOPT_LONG) $(LIBS)
  
--- 122,128 ----
  $(archpfx)ranlib.o: ranlib.c
  	$(CC) -c $(CFLAGS) -DAR_PROG=\"$(bindir)/ar\" ranlib.c $(OUTPUT_OPTION)
  
! $(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG)
  	$(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
  		$(GNU_GETOPT_LONG) $(LIBS)
  
***************
*** 131,139 ****
  	libconvert usg-gnulib gnulib
  
  clean:
! 	-rm -f *.o core
! 	-rm -f $(archpfx)*.o
! 	-rm -f $(PROGS)
  
  dist: binutils.tar.Z
  
--- 138,150 ----
  	libconvert usg-gnulib gnulib
  
  clean:
! 	-del *.o
! 	-del ar
! 	-del ld
! 	-del nm
! 	-del objdump
! 	-del size
! 	-del strip
  
  dist: binutils.tar.Z
  
diff -c ./nm.c c:\emx\gnu\binutils/nm.c
*** ./nm.c	Tue Jun 12 03:47:34 1990
--- c:/emx/gnu/binutils/nm.c	Sat Nov 27 23:34:48 1993
***************
*** 1,3 ****
--- 1,5 ----
+ /* nm.c -- changed for emx by Eberhard Mattes -- Nov 1993 */
+ 
  /* Describe symbol table of a rel file.
     Copyright (C) 1986, 1988 Free Software Foundation, Inc.
  
***************
*** 30,36 ****
--- 32,42 ----
  #include "a.out.encap.h"
  #else
  /* On native BSD systems, use the system's own a.out.h.  */
+ #ifdef EMX
+ #include <a_out.h>
+ #else /* !EMX */
  #include <a.out.h>
+ #endif /* !EMX */
  #endif
  #endif
  
***************
*** 83,88 ****
--- 89,97 ----
  
  /* C++ demangler stuff.  */
  char *cplus_demangle ();
+ #ifdef EMX
+ extern int no_demangle;
+ #endif /* EMX */
  
  /* Print NAME on STREAM, demangling if necessary.  */
  void
***************
*** 90,96 ****
--- 99,110 ----
       FILE *stream;
       char *name;
  {
+ #ifdef EMX
+   char *demangled = (no_demangle ? NULL
+                      : cplus_demangle (*name == '_' ? name + 1 : name));
+ #else /* !EMX */
    char *demangled = cplus_demangle (name);
+ #endif /* !EMX */
    if (demangled == NULL)
      fputs (name, stream);
    else
***************
*** 210,215 ****
--- 224,232 ----
  int file_on_each_line;	/* print file name on each line.  */
  int debugger_syms;	/* print the debugger-only symbols.  */
  int print_symdefs;	/* describe the __.SYMDEF data in any archive file specified.  */
+ #ifdef EMX
+ int no_demangle;        /* do not demangle C++ names */
+ #endif /* !EMX */
  
  /* The __.SYMDEF member of an archive has the following format:
     1) A longword saying the size of the symdef data that follows
***************
*** 258,266 ****
--- 275,289 ----
        {"reverse",	0, &reverse_sort,	1},
        {"print-symdefs",	0, &print_symdefs,	1},
        {"undefined-only",0, &undefined_only,	1},
+ #ifdef EMX
+       {"no-demangle",   0, &no_demangle,	1},
+ #endif /* !EMX */
        {NULL, 0, NULL, 0}
      };
  
+ #ifdef EMX
+   _wildcard (&argc, &argv);
+ #endif /* !EMX */
    program_name = argv[0];
  
    number_of_files = 0;
***************
*** 272,279 ****
    file_on_each_line = 0;
    debugger_syms = 0;
    print_symdefs = 0;
! 
    while ((c = getopt_long (argc, argv, "agnoprsu", long_options, &ind)) != EOF)
      switch (c)
        {
        case 0:
--- 295,309 ----
    file_on_each_line = 0;
    debugger_syms = 0;
    print_symdefs = 0;
! #ifdef EMX
!   no_demangle = 0;
! #endif /* !EMX */
! 
! #ifdef EMX
!   while ((c = getopt_long (argc, argv, "agnoprsud", long_options, &ind)) != EOF)
! #else /* !EMX */
    while ((c = getopt_long (argc, argv, "agnoprsu", long_options, &ind)) != EOF)
+ #endif /* !EMX */
      switch (c)
        {
        case 0:
***************
*** 311,316 ****
--- 341,351 ----
  	undefined_only = 1;
  	break;
  
+ #ifdef EMX
+       case 'd':
+ 	no_demangle = 1;
+ 	break;
+ #endif /* !EMX */
        default:
  	fprintf (stderr, "\
  Usage: %s [-agnoprsu] [+all] [+extern-only] [+numeric-sort]\n\
***************
*** 351,358 ****
  {
    int len, desc, nchars;
    char armag[SARMAG];
! 
    desc = open (name, O_RDONLY, 0);
  
    if (desc < 0)
      {
--- 386,400 ----
  {
    int len, desc, nchars;
    char armag[SARMAG];
! #ifdef EMX
!   long hdr_pos;
! #endif /* !EMX */
! 
! #ifdef EMX
!   desc = open (name, O_RDONLY | O_BINARY, 0);
! #else /* !EMX */
    desc = open (name, O_RDONLY, 0);
+ #endif /* !EMX */
  
    if (desc < 0)
      {
***************
*** 363,373 ****
--- 405,422 ----
    input_name = name;
    input_member = 0;
  
+ #ifdef EMX
+   _seek_hdr (desc); hdr_pos = tell (desc);
+ #endif /* !EMX */
    nchars = read (desc, armag, SARMAG);
    if (nchars == SARMAG && !strncmp(armag, ARMAG, SARMAG))
      scan_library (desc);
    else
+ #ifdef EMX
+     do_one_rel_file (desc, hdr_pos);
+ #else /* !EMX */
      do_one_rel_file (desc, 0);
+ #endif /* !EMX */
  
    close (desc);
  }
diff -c ./objdump.c c:\emx\gnu\binutils/objdump.c
*** ./objdump.c	Sat Dec 30 01:16:06 1989
--- c:/emx/gnu/binutils/objdump.c	Sun May 03 11:42:22 1992
***************
*** 1,3 ****
--- 1,5 ----
+ /* objdump.c -- changed for emx by Eberhard Mattes -- Jan 1992 */
+ 
  /* objdump -- dump information about an object file.
     Copyright (C) 1988, Free Software Foundation, Inc.
  
***************
*** 22,42 ****
   * refer to the manual page dump(1) in the system 5 program's reference manual
   */
  #include <stdio.h>
  #include "getopt.h"
  
  #ifndef COFF_ENCAPSULATE
! #include <a.out.h>
! /* Tell a.out.gnu.h not to try to redefine some things.  */
! #define __STRUCT_EXEC_OVERRIDE__
! #define N_NLIST_DECLARED
! #define N_RELOCATION_INFO_DECLARED
! #define N_MAGIC(exec) ((exec).a_magic)
! #include "a.out.gnu.h"
  #else
  #include "a.out.encap.h"
  #endif
  
! char *malloc();
  char *xmalloc();
  int nsyms;
  struct nlist *symtbl;
--- 24,41 ----
   * refer to the manual page dump(1) in the system 5 program's reference manual
   */
  #include <stdio.h>
+ #include <stdlib.h>
  #include "getopt.h"
  
  #ifndef COFF_ENCAPSULATE
! #include <a_out.h>
  #else
  #include "a.out.encap.h"
  #endif
  
! #define HEADER_SEEK(f) _fseek_hdr(f)
! static long hdr_pos;
! 
  char *xmalloc();
  int nsyms;
  struct nlist *symtbl;
***************
*** 58,78 ****
  
  	symtbl = (struct nlist *)xmalloc (nsyms * sizeof (struct nlist));
  
! 	fseek (f, N_STROFF(*execp), 0);
  	if (fread ((char *)&strsize, sizeof strsize, 1, f) != 1) {
  		fprintf (stderr, "%s: can not read string table size\n",
  			 program_name);
  		exit (1);
  	}
  	strtbl = xmalloc (strsize);
! 	fseek (f, N_STROFF (*execp), 0);
  	if (fread (strtbl, 1, strsize, f) != strsize) {
  		fprintf (stderr, "%s: error reading string table\n",
  			 program_name);
  		exit (1);
  	}
  
! 	fseek (f, N_SYMOFF (*execp), 0);
  	if (fread ((char *)symtbl, sizeof (struct nlist), nsyms, f) != nsyms) {
  		fprintf (stderr, "%s: error reading symbol table\n",
  			 program_name);
--- 57,77 ----
  
  	symtbl = (struct nlist *)xmalloc (nsyms * sizeof (struct nlist));
  
!     fseek (f, N_STROFF(*execp) + hdr_pos, 0);
  	if (fread ((char *)&strsize, sizeof strsize, 1, f) != 1) {
  		fprintf (stderr, "%s: can not read string table size\n",
  			 program_name);
  		exit (1);
  	}
  	strtbl = xmalloc (strsize);
!     fseek (f, N_STROFF (*execp) + hdr_pos, 0);
  	if (fread (strtbl, 1, strsize, f) != strsize) {
  		fprintf (stderr, "%s: error reading string table\n",
  			 program_name);
  		exit (1);
  	}
  
!     fseek (f, N_SYMOFF (*execp) + hdr_pos, 0);
  	if (fread ((char *)symtbl, sizeof (struct nlist), nsyms, f) != nsyms) {
  		fprintf (stderr, "%s: error reading symbol table\n",
  			 program_name);
***************
*** 133,138 ****
--- 132,138 ----
  	    {NULL, 0, NULL, 0}
  	  };
  
+     _wildcard (&argc, &argv);
  	page_size = getpagesize ();
  
  	program_name = argv[0];
***************
*** 164,170 ****
  	FILE *f;
  	struct exec exec;
  	printf ("%s:\n", name);
! 	f = fopen (name, "r");
  	if (f == NULL) {
  		fprintf (stderr, "%s: can not open ", program_name);
  		perror (name);
--- 164,170 ----
  	FILE *f;
  	struct exec exec;
  	printf ("%s:\n", name);
!         f = fopen (name, "rb");
  	if (f == NULL) {
  		fprintf (stderr, "%s: can not open ", program_name);
  		perror (name);
***************
*** 173,178 ****
--- 173,179 ----
  #ifdef HEADER_SEEK
  	HEADER_SEEK (f);
  #endif
+ 	hdr_pos = ftell (f);
  	if (fread ((char *)&exec, sizeof exec, 1, f) != 1) {
  		fprintf (stderr, "%s: can not read header for %s\n",
  			 program_name, name);
***************
*** 207,215 ****
  	int x;
  
  #if defined (__GNU_EXEC_MACROS__) && !defined (__STRUCT_EXEC_OVERRIDE__)
! 	printf ("magic: 0x%x (%o)", N_MAGIC(*execp), N_MAGIC(*execp));
! 	printf ("machine type: %d", N_MACHTYPE(*execp));
! 	printf ("flags: 0x%x", N_FLAGS(*execp));
  #else /* non-gnu struct exec.  */
  	printf ("magic: 0x%x (%o) ", execp->a_magic, execp->a_magic);
  #endif /* non-gnu struct exec.  */
--- 208,216 ----
  	int x;
  
  #if defined (__GNU_EXEC_MACROS__) && !defined (__STRUCT_EXEC_OVERRIDE__)
! 	printf ("magic: 0x%x (%o) ", N_MAGIC(*execp), N_MAGIC(*execp));
! 	printf ("machine type: %d ", N_MACHTYPE(*execp));
! 	printf ("flags: 0x%x ", N_FLAGS(*execp));
  #else /* non-gnu struct exec.  */
  	printf ("magic: 0x%x (%o) ", execp->a_magic, execp->a_magic);
  #endif /* non-gnu struct exec.  */
***************
*** 269,279 ****
  	read_symbols (execp, f);
  	if (execp->a_trsize) {
  		printf ("text reloc\n");
! 		dump_reloc1 (execp, f, N_TRELOFF (*execp), execp->a_trsize);
  	}
  	if (execp->a_drsize) {
  		printf ("data reloc\n");
! 		dump_reloc1 (execp, f, N_DRELOFF (*execp), execp->a_drsize);
  	}
  }
  
--- 270,280 ----
  	read_symbols (execp, f);
  	if (execp->a_trsize) {
  		printf ("text reloc\n");
!         dump_reloc1 (execp, f, N_TRELOFF (*execp) + hdr_pos, execp->a_trsize);
  	}
  	if (execp->a_drsize) {
  		printf ("data reloc\n");
!         dump_reloc1 (execp, f, N_DRELOFF (*execp) + hdr_pos, execp->a_drsize);
  	}
  }
  
diff -c ./size.c c:\emx\gnu\binutils/size.c
*** ./size.c	Tue Jun 12 03:56:50 1990
--- c:/emx/gnu/binutils/size.c	Sun May 03 11:42:22 1992
***************
*** 1,3 ****
--- 1,5 ----
+ /* size.c -- changed for emx by Eberhard Mattes -- Jan 1992 */
+ 
  /* Size of rel file utility (`size') for GNU.
     Copyright (C) 1986 Free Software Foundation, Inc.
  
***************
*** 16,21 ****
--- 18,24 ----
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  
  #include <stdio.h>
+ #include <stdlib.h>
  #include <ar.h>
  #include <sys/types.h>
  #include <sys/file.h>
***************
*** 29,35 ****
  #include "a.out.encap.h"
  #else
  /* On native BSD systems, use the system's own a.out.h.  */
! #include <a.out.h>
  #endif
  #endif
  
--- 32,38 ----
  #include "a.out.encap.h"
  #else
  /* On native BSD systems, use the system's own a.out.h.  */
! #include <a_out.h>
  #endif
  #endif
  
***************
*** 61,67 ****
  
  int member_offset;
  
- char *malloc ();
  
  void do_one_file (), do_one_rel_file ();
  char *xmalloc ();
--- 64,69 ----
***************
*** 73,78 ****
--- 75,81 ----
  {
    int i;
  
+   _wildcard (&argc, &argv);
    number_of_files = argc - 1;
  
    printf ("text\tdata\tbss\tdec\thex\n");
***************
*** 106,113 ****
  {
    int len, desc;
    char armag[SARMAG];
  
!   desc = open (name, O_RDONLY, 0);
  
    if (desc < 0)
      {
--- 109,117 ----
  {
    int len, desc;
    char armag[SARMAG];
+   long hdr_pos;      /* emx */
  
!   desc = open (name, O_RDONLY | O_BINARY, 0);
  
    if (desc < 0)
      {
***************
*** 118,125 ****
    input_name = name;
    input_member = 0;
  
    if (SARMAG != read (desc, armag, SARMAG) || strncmp (armag, ARMAG, SARMAG))
!     do_one_rel_file (desc, 0L);
    else
      scan_library (desc);
  
--- 122,131 ----
    input_name = name;
    input_member = 0;
  
+   _seek_hdr (desc); hdr_pos = tell (desc);
+ 
    if (SARMAG != read (desc, armag, SARMAG) || strncmp (armag, ARMAG, SARMAG))
!     do_one_rel_file (desc, hdr_pos);
    else
      scan_library (desc);
  
***************
*** 345,352 ****
  perror_name (name)
       char *name;
  {
-   extern int errno, sys_nerr;
-   extern char *sys_errlist[];
    char *s;
  
    if (errno < sys_nerr)
--- 351,356 ----
diff -c ./strip.c c:\emx\gnu\binutils/strip.c
*** ./strip.c	Mon Jun 11 22:40:00 1990
--- c:/emx/gnu/binutils/strip.c	Mon Oct 03 23:32:10 1994
***************
*** 1,3 ****
--- 1,5 ----
+ /* strip.c -- changed for emx by Eberhard Mattes -- Oct 1994 */
+ 
  /* strip certain symbols from a rel file.
     Copyright (C) 1986 Free Software Foundation, Inc.
  
***************
*** 16,21 ****
--- 18,24 ----
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  
  #include <stdio.h>
+ #include <stdlib.h>
  #include <sys/types.h>
  #include <sys/file.h>
  #include <sys/stat.h>
***************
*** 38,44 ****
  #include "a.out.encap.h"
  #else
  /* On native BSD systems, use the system's own a.out.h.  */
! #include <a.out.h>
  #endif
  #endif
  
--- 41,47 ----
  #include "a.out.encap.h"
  #else
  /* On native BSD systems, use the system's own a.out.h.  */
! #include <a_out.h>
  #endif
  #endif
  
***************
*** 138,145 ****
  /* 1 => discard locals starting with L; 2 => discard all locals */
  int discard_locals;
  
- char *malloc ();
- 
  void strip_file ();
  int file_open ();
  void rewrite_file_symbols(), file_close();
--- 141,146 ----
***************
*** 169,174 ****
--- 170,176 ----
    struct file_entry *p;
    int i;
  
+   _wildcard (&argc, &argv);
    strip_symbols = 0;   /* default is to strip everything.  */
    discard_locals = 0;
  
***************
*** 224,239 ****
    exit (0);
  }
  
- int delayed_signal;
- 
- void
- delay_signal (signo)
-      int signo;
- {
-   delayed_signal = signo;
-   signal (signo, delay_signal);
- }
- 
  /* process one input file */
  
  void
--- 226,231 ----
***************
*** 262,275 ****
      }
  
    /* Effectively defer handling of asynchronous kill signals.  */
!   delayed_signal = 0;
!   if (signal (SIGINT, SIG_IGN) != SIG_IGN)
!     sigint_handled = 1, signal (SIGINT, delay_signal);
!   if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
!     sighup_handled = 1, signal (SIGHUP, delay_signal);
!   if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
!     sigterm_handled = 1, signal (SIGTERM, delay_signal);
! 
    /* Change the file.  */
  
    rewrite_file_symbols (entry);
--- 254,260 ----
      }
  
    /* Effectively defer handling of asynchronous kill signals.  */
!   /* -- deleted for emx */
    /* Change the file.  */
  
    rewrite_file_symbols (entry);
***************
*** 279,294 ****
    file_close ();
  
    /* Effectively undefer handling.  */
!   if (sigint_handled)
!     signal (SIGINT, SIG_DFL);
!   if (sighup_handled)
!     signal (SIGHUP, SIG_DFL);
!   if (sigterm_handled)
!     signal (SIGTERM, SIG_DFL);
! 
!   /* Handle any signal that came in while they were deferred.  */
!   if (delayed_signal)
!     kill (getpid (), delayed_signal);
  }
  
  /** Convenient functions for operating on one or all files being processed.  */
--- 264,270 ----
    file_close ();
  
    /* Effectively undefer handling.  */
!   /* -- deleted for emx */
  }
  
  /** Convenient functions for operating on one or all files being processed.  */
***************
*** 314,320 ****
    int desc;
    int len, magicnum;
  
!   desc = open (entry->filename, O_RDWR, 0);
  
    if (desc > 0)
      {
--- 290,296 ----
    int desc;
    int len, magicnum;
  
!   desc = open (entry->filename, O_RDWR | O_BINARY, 0);
  
    if (desc > 0)
      {
***************
*** 405,416 ****
  	entry->syms_offset = N_SYMOFF(hdr);
  	entry->syms_size = hdr.a_syms;
  	entry->strs_offset = N_STROFF(hdr);
! 	lseek(desc, entry->strs_offset, 0);
! 	if (read (desc, (char *) &entry->strs_size, sizeof entry->strs_size)
! 	    != sizeof entry->strs_size)
  	  {
! 	    error_with_file ("cannot read string table size", entry);
! 	    return -1;
  	  }
  	return 0;
        }
--- 381,397 ----
  	entry->syms_offset = N_SYMOFF(hdr);
  	entry->syms_size = hdr.a_syms;
  	entry->strs_offset = N_STROFF(hdr);
! 	if (hdr.a_syms == 0)
! 	  entry->strs_size = 0;
! 	else
  	  {
! 	    lseek(desc, entry->strs_offset, 0);
! 	    if (read (desc, (char *) &entry->strs_size, sizeof entry->strs_size)
! 		!= sizeof entry->strs_size)
! 	      {
! 		error_with_file ("cannot read string table size", entry);
! 		return -1;
! 	      }
  	  }
  	return 0;
        }
***************
*** 845,852 ****
  perror_name (name)
       char *name;
  {
-   extern int errno, sys_nerr;
-   extern char *sys_errlist[];
    char *s;
  
    if (errno < sys_nerr)
--- 826,831 ----
***************
*** 862,870 ****
  perror_file (entry)
       struct file_entry *entry;
  {
!   extern int errno, sys_nerr;
!   extern char *sys_errlist[];
!   char *s;
  
    if (errno < sys_nerr)
      s = sys_errlist[errno];
--- 841,847 ----
  perror_file (entry)
       struct file_entry *entry;
  {
!   const char *s;
  
    if (errno < sys_nerr)
      s = sys_errlist[errno];
***************
*** 876,882 ****
  /* Report an error.   STRING is printed, and the filename of ENTRY.  */
  
  error_with_file (string, entry, arg1, arg2)
!      char *string;
       struct file_entry *entry;
       int arg1, arg2;
  {
--- 853,859 ----
  /* Report an error.   STRING is printed, and the filename of ENTRY.  */
  
  error_with_file (string, entry, arg1, arg2)
!      const char *string;
       struct file_entry *entry;
       int arg1, arg2;
  {
