Index: trunk/src/emx/src/emxomf/weakld.c
===================================================================
--- trunk/src/emx/src/emxomf/weakld.c	(revision 1097)
+++ trunk/src/emx/src/emxomf/weakld.c	(revision 1098)
@@ -246,4 +246,10 @@
     PWLDMOD             pMod;
 
+    /** Array of modules refering this symbol. */
+    PWLDMOD *           paReferers;
+
+    /** Number of modules in the array. */
+    unsigned            cReferers;
+
     /** Per type data union */
     union type_data
@@ -436,7 +442,6 @@
 static int          symSearchLibEnum(PWLD pWld, PWLDSYM pSym, void *pvUser);
 static inline unsigned symHash(const char* pszSym, unsigned cch);
-#ifdef WLD_ENABLED_DBG
+static const char * symGetDescr(PWLDSYM pSym);
 static void         symDbg(PWLDSYM pSym, const char *pszMsg);
-#endif
 static PWLDSYM      symAdd(PWLD pWld, PWLDMOD pMod, unsigned fFlags, const char *pachName, int cchName, PWLDSYMACTION peAction);
 static PWLDSYM      symAddImport(PWLD pWld, PWLDMOD pMod, int fLibSearch,
@@ -1348,7 +1353,20 @@
 
     if (pMod)
-        modErr(pMod, "Unresolved symbol '%s'.", pSym->pszName);
+        modErr(pMod, "Unresolved symbol (%s) '%s'.", symGetDescr(pSym), pSym->pszName);
     else
-        wldErr(pWld, "Unresolved symbol '%s'.", pSym->pszName);
+        wldErr(pWld, "Unresolved symbol (%s) '%s'.", symGetDescr(pSym), pSym->pszName);
+    if (pSym->cReferers)
+    {
+        int     i;
+        wldInfo("The symbol is referenced by:\n");
+        for (i = 0; i < pSym->cReferers; i++)
+        {
+            pMod = pSym->paReferers[i];
+            if (pMod->pLib)
+                fprintf(stderr, "    %s(%s)\n", pMod->pLib->pszLibName, pMod->pszModName);
+            else
+                fprintf(stderr, "    %s\n", pMod->pszModName);
+        }
+    }
     return 0;
 }
@@ -1411,10 +1429,39 @@
 
 
-
-
-
-
-
-#ifdef WLD_ENABLED_DBG
+/**
+ * Makes a description of the symbol.
+ *
+ * @returns Pointer to static string buffer.
+ * @param   pSym    Symbol to describe.
+ */
+static const char *symGetDescr(PWLDSYM pSym)
+{
+    static char szDesc[256];
+    char *psz = &szDesc[0];
+
+    switch (pSym->fFlags & WLDSF_TYPEMASK)
+    {
+        case WLDSF_PUBLIC:  psz += sprintf(psz, "PUBLIC"); break;
+        case WLDSF_COMM:    psz += sprintf(psz, "COMM"); break;
+        case WLDSF_IMPORT:  psz += sprintf(psz, "IMPORT"); break;
+        case WLDSF_UNDEF:   psz += sprintf(psz, "UNDEF"); break;
+        case WLDSF_WKEXT:   psz += sprintf(psz, "WKEXT"); break;
+        default:            psz += sprintf(psz, "!!!internal error!!! "); asm("int $3"); break;
+    }
+    if (pSym->fFlags & WLDSF_WEAK)
+        psz += sprintf(psz, " WEAK");
+    if (pSym->fFlags & WLDSF_ALIAS)
+        psz += sprintf(psz, " ALIAS");
+    if (pSym->fFlags & WLDSF_EXPORT)
+        psz += sprintf(psz, " EXPORT");
+    if (pSym->fFlags & WLDSF_UNCERTAIN)
+        psz += sprintf(psz, " UNCERTAIN");
+
+    return &szDesc[0];
+}
+
+
+
+
 /**
  * Symbol debug output.
@@ -1429,30 +1476,9 @@
         fprintf(stderr, "weakld: dbg:");
     if (pSym)
-    {
-        fprintf(stderr, " '%s'", pSym->pszName);
-        switch (pSym->fFlags & WLDSF_TYPEMASK)
-        {
-            case WLDSF_PUBLIC:  fprintf(stderr, " PUBLIC"); break;
-            case WLDSF_COMM:    fprintf(stderr, " COMM"); break;
-            case WLDSF_IMPORT:  fprintf(stderr, " IMPORT"); break;
-            case WLDSF_UNDEF:   fprintf(stderr, " UNDEF"); break;
-            case WLDSF_WKEXT:   fprintf(stderr, " WKEXT"); break;
-            default:            fprintf(stderr, " !!!internal error!!!"); asm("int $3"); break;
-        }
-        if (pSym->fFlags & WLDSF_WEAK)
-            fprintf(stderr, " WEAK");
-        if (pSym->fFlags & WLDSF_ALIAS)
-            fprintf(stderr, " ALIAS");
-        if (pSym->fFlags & WLDSF_EXPORT)
-            fprintf(stderr, " ALIAS");
-        if (pSym->fFlags & WLDSF_UNCERTAIN)
-            fprintf(stderr, " UNCERTAIN");
-    }
+        fprintf(stderr, " '%s' %s", pSym->pszName, symGetDescr(pSym));
     else
         fprintf(stderr, " <Symbol is NULL>");
     fprintf(stderr, "\n");
 }
-#endif
-
 
 /**
@@ -1553,6 +1579,4 @@
         pSym->fFlags = fFlags;
         pSym->pszName = pszName;
-        if (SYM_IS_DEFINED(pSym->fFlags))
-            pSym->pMod = pMod;
         if (cchNameWeak)
         {
@@ -1688,4 +1712,26 @@
             wldInfo("fFlags new 0x%04x  fFlags old 0x%04x.", fFlags, pSym->fFlags);
             pSym = NULL;
+        }
+
+        /*
+         * Maintain the module pointer and referers.
+         */
+        if (pSym)
+        {
+            if (SYM_IS_DEFINED(pSym->fFlags))
+                pSym->pMod = pMod;
+            else
+            {
+                int i;
+                for (i = 0; i < pSym->cReferers; i++)
+                    if (pSym->paReferers[i] == pMod)
+                        break;
+                if (i >= pSym->cReferers)
+                {
+                    if (!(pSym->cReferers % 64))
+                        pSym->paReferers = xrealloc(pSym->paReferers, sizeof(pSym->paReferers[0]) * (pSym->cReferers + 64));
+                    pSym->paReferers[pSym->cReferers++] = pMod;
+                }
+            }
         }
     }
@@ -1861,4 +1907,6 @@
         PWLDSYM     pSymAlias;
 
+        pSym->fFlags |= WLDSF_EXPORT;
+
         /*
          * Add internal name.
@@ -1875,5 +1923,5 @@
         else
         {
-            if (pSym->pAliasFor != pSymAlias)
+            if (pSym != pSymAlias)
             {
                 pSym->fFlags |= WLDSF_ALIAS;
@@ -1982,4 +2030,6 @@
             {
                 modErr(pMod, "Aliased symbol apparently existed already (upgraded - internal error?).");
+                symDbg(pSym, "Processing");
+                symDbg(pSym->pAliasFor, "Alias");
                 pSym = NULL;
             }
@@ -2500,4 +2550,5 @@
     PWLDMOD     pObj;
     PWLDLIB     pLib;
+    unsigned    uHash;
 
     if (!pWld)
@@ -2529,4 +2580,18 @@
         pLib = pLib->pNext;
         free(pv);
+    }
+
+    /* free symbols */
+    for (uHash = 0; uHash < sizeof(pWld->Global.ap) / sizeof(pWld->Global.ap[0]); uHash++)
+    {
+        PWLDSYM     pSym = pWld->Global.ap[uHash];
+        while (pSym)
+        {
+            PWLDSYM pNext = pSym->pHashNext;
+            if (pSym->paReferers)
+                free(pSym->paReferers);
+            free(pSym);
+            pSym = pNext;
+        }
     }
 
@@ -3307,4 +3372,6 @@
                 return 0;               /* .ignore it. good idea? */
             }
+
+            WLDDBG2(("wldGenerateDefCallback: '%s', '%s'", pSymExp->pszName, pSymInt ? pSymInt->pszName : "<the-same-name>"));
 
             /* Skip it all if neither of the symbols are weak. */
