Index: /trunk/src/emx/src/emxomf/emxomf.c
===================================================================
--- /trunk/src/emx/src/emxomf/emxomf.c	(revision 474)
+++ /trunk/src/emx/src/emxomf/emxomf.c	(revision 475)
@@ -290,5 +290,6 @@
 static int weak_list_altered;
 
-/* The file name of the weak symbol list file */
+/* The file name of the weak symbol list file.
+   If NULL the new method is used, if not NULL the old method is used. */
 static char *weak_list_filename;
 
@@ -621,8 +622,9 @@
     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");
   if (!weak_list_filename)
-    weak_list_filename = "weaksyms.omf";
+      return ;
   wf = fopen (weak_list_filename, "r");
   if (!wf)
@@ -751,4 +753,6 @@
 {
   struct lname *p;
+
+/** @todo: change this to use a stringpool for speed reasons! */
 
   /* Walk through the list of known OMF-style names.  If there is a
@@ -1185,4 +1189,57 @@
 
 
+/**
+ * Generates new names for weak symbols.
+ *
+ * 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.
+ *
+ * @returns Pointer to pszOrgName or pszName.
+ * @param   pSym        Pointer to the symbol in question.
+ * @param   pszOrgName  Pointer to the symbols actual name.
+ * @param   pachName    Pointer to a character buffer of size cchName where the
+ *                      new name will be written.
+ * @param   cchName     Size of the buffer pointed to by pachName.
+ * @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)
+        {
+            /*
+             * 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. */
+            {
+                int cch = strlen(pszOrgName);
+                memcpy(pachName, pszOrgName, cch);
+
+                break;
+            }
+        }
+    }
+}
+
+
+
 /* Write ALIAS records into the output file for all indirect
    references. */
@@ -1239,4 +1296,5 @@
   const char *name, *pub_name;
   dword address;
+  char  szName[260];
 
   started = FALSE;
@@ -1248,6 +1306,8 @@
           {
             name = str_ptr + sym_ptr[i].n_un.n_strx;
-            if ((sym_ptr[i].n_type & N_EXT)
-                || (type == N_TEXT && strncmp (name, "___POST$", 8) == 0))
+            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)
+                   )
               {
                 if ((sym_ptr[i].n_type & N_EXT) && out_lib != NULL)
@@ -1260,4 +1320,12 @@
                       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));
+
                 if (started && !fits (strlen (name) + 6))
                   {
@@ -1333,10 +1401,25 @@
   write_pubdef1 (N_TEXT, text_index, FALSE, 0);
   write_pubdef1 (N_TEXT, text_index, TRUE, 0);
+  if (!write_pubdef_main)
+  {
+      write_pubdef1 (N_WEAKT, text_index, FALSE, 0);
+      write_pubdef1 (N_WEAKT, text_index, TRUE, 0);
+  }
   /* kso #456 2003-06-10: The debugger looks for 'main' not '_main'. */
   write_pubdef_main ();
   write_pubdef1 (N_DATA, udat_index, FALSE, text_size);
   write_pubdef1 (N_DATA, udat_index, TRUE, text_size);
+  if (!write_pubdef_main)
+  {
+      write_pubdef1 (N_WEAKD, text_index, FALSE, 0);
+      write_pubdef1 (N_WEAKD, text_index, TRUE, 0);
+  }
   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)
+  {
+      write_pubdef1 (N_WEAKB, bss_index, FALSE, text_size + data_size);
+      write_pubdef1 (N_WEAKB, bss_index, TRUE, text_size + data_size);
+  }
 }
 
@@ -3218,4 +3301,8 @@
   write_libs ();
   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
