Index: trunk/src/emx/src/emxomf/emxomf.c
===================================================================
--- trunk/src/emx/src/emxomf/emxomf.c	(revision 478)
+++ trunk/src/emx/src/emxomf/emxomf.c	(revision 479)
@@ -33,4 +33,5 @@
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <ar.h>
 
@@ -260,4 +261,7 @@
 /* Remove underscores from all symbol names */
 static int opt_rmunder = FALSE;
+
+/* Add timestamp to symbol to make it more unique. */
+static int opt_weakts = FALSE;
 
 /* This is the page size for OMF libraries.  It is set by the -p
@@ -343,4 +347,7 @@
 static char mod_name[256];
 
+/* This variable holds a normalized module name used with weak syms.  See get_mod_name(). */
+static char weak_mod_name[256];
+
 /* This growing array holds the file name table for generating line
    number information.  */
@@ -573,6 +580,5 @@
 		if (t == N_TEXT || t == N_DATA || t == N_BSS
                     /* kso #465 2003-06-04: Find weak symbols too. */
-                    || t == N_WEAKT || t == N_WEAKD || t == N_WEAKB
-                    || t == N_WEAKA /* hmm.. */
+                    || (t >= N_WEAKA && t <= N_WEAKB)
                     || (t == 0 && sym_ptr[j].n_value != 0))
 		  return sym_ptr+j;
@@ -622,5 +628,5 @@
     return;
 
-  /* Find and open the weak symbol list file 
+  /* Find and open the weak symbol list file
      #483: If not present we'll use the new method. */
   weak_list_filename = getenv ("GCC_WEAKSYMS");
@@ -1147,4 +1153,7 @@
   int i;
 
+  if (!weak_list_filename)
+      return;
+
 #define SETTYPE(t) ((struct nlist *)sym_ptr)[i].n_type = t
 
@@ -1192,5 +1201,5 @@
  * Generates new names for weak symbols.
  *
- * These names will be catch bye emxomfld and an alias from the generated to 
+ * These names will be catch bye emxomfld and an alias from the generated to
  * the real name will be generated and put in a library before linking.
  *
@@ -1203,39 +1212,40 @@
  * @remark I'm sorry this function is written in my coding style - not!
  */
-static char *weak_process_name(struct nlist *pSym, char *pszOrgName, char *pachName, int cchName));
-{
-    for (i = 0; i < sym_count; ++i)
-    {
-
-        switch (sym_ptr->n_type)
+static const char *weak_process_name(const struct nlist *pSym, const char *pszOrgName, char *pachName, int cchName)
+{
+    switch (sym_ptr->n_type)
+    {
+        /*
+         * Hmmm... Check that we handle this correctly else where
+         */
+        case N_WEAKU:               /* 0x0d  Weak undefined symbol. */
+        default:
+            break;
+
+        /*
+         * These symbols are defined in this module, so we need to
+         * make a unique and recognizable name for them.
+         */
+        case N_WEAKA:               /* 0x0e  Weak absolute symbol. */
+        case N_WEAKT:               /* 0x0f  Weak text symbol. */
+        case N_WEAKD:               /* 0x10  Weak data symbol. */
+        case N_WEAKB:               /* 0x11  Weak bss symbol. */
         {
-            /*
-             * Hmmm... Check that we handle this correctly else where
-             */
-            case N_WEAKU:               /* 0x0d  Weak undefined symbol. */
-                break;
-
-            /* 
-             * I'm uncertain what this means, needs to google  
-             * for and explanation of how this is used. 
-             */    
-            case N_WEAKA:               /* 0x0e  Weak absolute symbol. */
-                break; 
-                       
-            /*
-             * These symbols are defined in this module, so we need to 
-             * make a unique and recognizable name for them.
-             */
-            case N_WEAKT:               /* 0x0f  Weak text symbol. */
-            case N_WEAKD:               /* 0x10  Weak data symbol. */
-            case N_WEAKB:               /* 0x11  Weak bss symbol. */
+            if (!opt_weakts)
+                snprintf(pachName, cchName, "%s$w$%s",
+                         pszOrgName, weak_mod_name);
+            else
             {
-                int cch = strlen(pszOrgName);
-                memcpy(pachName, pszOrgName, cch);
-
-                break;
+                struct timeval tv = {0, 0};
+                gettimeofday(&tv, NULL);
+                snprintf(pachName, cchName, "%s$w$%s%lx%lx",
+                         pszOrgName, weak_mod_name, tv.tv_sec, tv.tv_usec);
             }
+            return pachName;
         }
-    }
+
+    }
+    /* default is to keep the original name */
+    return pszOrgName;
 }
 
@@ -1296,9 +1306,11 @@
   const char *name, *pub_name;
   dword address;
-  char  szName[260];
+  char  szName[256];
 
   started = FALSE;
   for (i = 0; i < sym_count; ++i)
-    if ((sym_ptr[i].n_type & ~N_EXT) == type)
+    if (   (sym_ptr[i].n_type & ~N_EXT) == type
+        || (type >= N_WEAKU && type <= N_WEAKB && sym_ptr[i].n_type == type)
+        )
       {
         address = sym_ptr[i].n_value - start;
@@ -1308,6 +1320,5 @@
             if (   (sym_ptr[i].n_type & N_EXT)
                 || (type == N_TEXT && strncmp (name, "___POST$", 8) == 0)
-                || (sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB)
-                   )
+                || (sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB) )
               {
                 if ((sym_ptr[i].n_type & N_EXT) && out_lib != NULL)
@@ -1320,11 +1331,9 @@
                       error (lib_errmsg);
                   }
-            
+
                 /* for weaksymbols we may have to decorate the name */
                 if (   !weak_list_filename
-                    && sym_ptr[i].n_type >= N_WEAKU 
-                    && sym_ptr[i].n_type <= N_WEAKB
-                       )
-                    name = weak_process_name(sym_ptr[i], name, szName, sizeof(szName));
+                    && sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB )
+                    name = weak_process_name(&sym_ptr[i], name, szName, sizeof(szName));
 
                 if (started && !fits (strlen (name) + 6))
@@ -1401,5 +1410,5 @@
   write_pubdef1 (N_TEXT, text_index, FALSE, 0);
   write_pubdef1 (N_TEXT, text_index, TRUE, 0);
-  if (!write_pubdef_main)
+  if (!weak_list_filename)
   {
       write_pubdef1 (N_WEAKT, text_index, FALSE, 0);
@@ -1410,5 +1419,5 @@
   write_pubdef1 (N_DATA, udat_index, FALSE, text_size);
   write_pubdef1 (N_DATA, udat_index, TRUE, text_size);
-  if (!write_pubdef_main)
+  if (!weak_list_filename)
   {
       write_pubdef1 (N_WEAKD, text_index, FALSE, 0);
@@ -1417,5 +1426,5 @@
   write_pubdef1 (N_BSS, bss_index, FALSE, text_size + data_size);
   write_pubdef1 (N_BSS, bss_index, TRUE, text_size + data_size);
-  if (!write_pubdef_main)
+  if (!weak_list_filename)
   {
       write_pubdef1 (N_WEAKB, bss_index, FALSE, text_size + data_size);
@@ -2711,4 +2720,5 @@
   int i, len, ok;
   const char *p1, *p2;
+  char *p3;
 
   ok = FALSE;
@@ -2734,4 +2744,14 @@
       _strncpy (mod_name, p1, sizeof (mod_name));
     }
+
+  /* Find the base name and lenght (excluding extension)
+     This is used for weak symbol handling. */
+  for (p1 = "\\/:", p2 = mod_name; *p1; p1++)
+    if ((p3 = strrchr(p2, *p1)) != NULL)
+      p2 = p3 + 1;
+  for (p3 = weak_mod_name; *p2; p2++)
+    if (isalnum(*p2) || *p2 == '$' || *p2 == '_' || *p2 == '@')
+        *p3++ = *p2;
+  *p3 = '\0';
 }
 
@@ -2919,6 +2939,6 @@
 
 
-  /* 
-   * If no lines or no files, we don't want to issue any LINNUM records. 
+  /*
+   * If no lines or no files, we don't want to issue any LINNUM records.
    */
   if (valid_lines <= 0 || file_grow.count <= 0)
@@ -3302,8 +3322,4 @@
   write_debug_style ();
 
-  /* Method 2 Weak symbol processing (generate names). */
-
-  weak_process_names();
-
   /* Define all the OMF names (LNAMES record).  Of course, we must not
      define new OMF names after this point. */
@@ -3461,4 +3477,5 @@
   puts ("  -I <idmdll>        Name the identifier manipulation DLL");
   puts ("  -O <directory>     Extract files to <directory>");
+  puts ("  -t                 Add timestamping to the weak symbol mangling");
   puts ("  -w                 Suppress reading/writing of the weaksyms.omf file");
   puts ("  -z                 Remove underscores from all symbol names");
@@ -3958,4 +3975,7 @@
         opt_rmunder = TRUE;
         break;
+      case 't':
+        opt_weakts = TRUE;
+        break;
       default:
         usage ();
