Index: branches/libc-0.6/src/emx/src/emxomf/emxomfld.c
===================================================================
--- branches/libc-0.6/src/emx/src/emxomf/emxomfld.c	(revision 2993)
+++ branches/libc-0.6/src/emx/src/emxomf/emxomfld.c	(revision 2995)
@@ -64,4 +64,7 @@
 static const char *map_fname = NULL;
 static int map_flag = FALSE;
+
+/* The sym file output flag, set by the -Zsym option. */
+static int sym_flag = FALSE;
 
 /* The module definition file name (input), set if a file matching
@@ -1395,5 +1398,5 @@
 
   if (opt_t)
-      show_spawn(pszwhat);
+    show_spawn(pszwhat);
 
   /* construct spawnvp() argument array */
@@ -1487,5 +1490,5 @@
          "\n", stderr);
   fputs ("Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n"
-         "                [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n"
+         "                [-Zexe] [-Zdll] [-Zsym] [-Zstack <size>] [-Zmap[=<map_file>]]\n"
          "                [-Z[no-]autoconv] [-Zdll-search] [-O <option>] [-static]\n"
          "                [-non_shared] [-Bstatic] [-dn] [call_shared] [-Bshared]\n"
@@ -1505,5 +1508,8 @@
          "    lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n"
          " -Zdll-search:\n"
-         "    Enables dlls as valid libraries from shared linking. (default disabled)\n"
+         "    Enables dlls as valid libraries from shared linking. (default disabled)\n", 
+         stderr);
+  fputs (" -Zsym:"
+         "    Invoke mapsym.cmd on the mapfile to produce a .sym file. Requires -Zmap.\n" 
          "\n", stderr);
   fputs ("Environment variables:\n"
@@ -1549,4 +1555,6 @@
 #define OPT_ZDLL_SEARCH     0x1008
   {"Zdll-search",0, 0, OPT_ZDLL_SEARCH},
+#define OPT_ZSYM            0x1009
+  {"Zsym",0, 0, OPT_ZSYM},
 /*  {"e", 1, 0, 'e'}, entry point */
   {"i", 0, 0, 'i'},
@@ -1743,4 +1751,8 @@
           break;
 
+        case OPT_ZSYM:
+          sym_flag = TRUE;
+          break;
+
         case OPT_LIBS_STATIC:
           opt_libs_static = 1;
@@ -1773,4 +1785,12 @@
     {
       fprintf (stderr, "emxomfld: no input files\n");
+      return 1;
+    }
+
+  /* Check that -Zmap was specified with -Zsym. */
+
+  if (sym_flag && !map_flag)
+    {
+      fprintf (stderr, "emxomfld: -Zsym without -Zmap.\n");
       return 1;
     }
@@ -2196,14 +2216,14 @@
       t = xstrdup (output_fname);
       _remext (t);
-      _execname(&execname[0], sizeof(execname));
-      strcpy(_getname(&execname[0]), "ldstub.bin");
+      _execname (&execname[0], sizeof(execname));
+      strcpy (_getname(&execname[0]), "ldstub.bin");
 
       /* Copy stub into file */
       if (opt_t)
-          fprintf(stderr, "*** copy %s to %s (-Zexe)", execname, t);
-      DosCopy(&execname[0], t, 4);
+        fprintf (stderr, "*** copy %s to %s (-Zexe)", execname, t);
+      DosCopy (&execname[0], t, 4);
 
       /* Now touch it */
-      if (utime(t, NULL))
+      if (utime (t, NULL))
         {
           perror ("emxomfld");
@@ -2213,6 +2233,56 @@
     }
 
+  /* Run mapsym if requested and linking succeeded. */
+  if (rc == 0 && sym_flag)
+    {
+      char* cwd = getcwd (NULL, 0);
+      char  map_fname_fullpath[_MAX_PATH];
+      char  drive[_MAX_PATH];
+      char  dir[_MAX_DIR];
+
+      /* get absolute path of map file and change CWD to map file directory. */
+      _fullpath (map_fname_fullpath, map_fname, sizeof (map_fname_fullpath));
+      _splitpath (map_fname_fullpath, drive, dir, NULL, NULL);
+      strcat (drive, dir);
+      if (chdir (drive))
+        {
+          perror ("chdir failed");
+          exit (2);
+        }
+
+      /* Invoke mapsym.cmd writing the .sym file to current directory. */
+      arg_init (TRUE);
+      if (getenv ("COMSPEC"))
+        put_arg (getenv ("COMSPEC"), TRUE, FALSE);
+      else
+        put_arg ("cmd.exe", TRUE, FALSE);
+      put_arg ("/c", FALSE, FALSE);
+      put_arg ("mapsym.cmd", TRUE, FALSE);
+      if (!stricmp (linker_type, "WLINK"))
+         put_arg ("watcom", TRUE, FALSE);
+      else if (!stricmp (linker_type, "LINK386"))
+         put_arg ("link386", TRUE, FALSE);
+      else
+         put_arg ("vac3xx", TRUE, FALSE);
+      put_arg (map_fname_fullpath, TRUE, FALSE);
+      arg_end ();
+      rc = emxomfld_spawn (command_line, "Mapsym");
+      if (rc < 0)
+        {
+          perror ("emxomfld: mapsym");
+          exit (2);
+        }
+
+      /* Restore the working directory */
+      if (chdir (cwd))
+        {
+          perror ("chdir failed");
+          exit (2);
+        }
+    }
+
   /* Return the return code of Linker or RC. */
 
   return rc;
 }
+
