Index: trunk/src/emx/src/emxomf/weakld.c
===================================================================
--- trunk/src/emx/src/emxomf/weakld.c	(revision 2234)
+++ trunk/src/emx/src/emxomf/weakld.c	(revision 2235)
@@ -269,4 +269,10 @@
         WLDSF_EXPORT    = 0x1000,
 
+        /** Internal flags which indicates that the symbol was exported in
+         * the definition file. This to select symbols which only appears in
+         * __declspec(dllexport) and put them into the definition file for
+         * proper weak handling. */
+        WLDSF_EXPORT_DEF = 0x2000,
+
         /** Internal flag to say that we've already aliased this weak
          * in the definition file.
@@ -277,5 +283,4 @@
          * truncated by emxomf. */
         WLDSF_TRUNCATED = 0x10000,
-
     }                   fFlags;
 
@@ -3544,4 +3549,6 @@
     /** Our current linenumber index. */
     unsigned    iLine;
+    /** Set if we have processed any weak __declspec(dllexport) symbols. */
+    unsigned    fWeakDllExport;
 } WLDGDCPARAM, *PWLDGDCPARAM;
 
@@ -3594,4 +3601,7 @@
 
             WLDDBG2(("wldGenerateDefCallback: '%s', '%s'", pSymExp->pszName, pSymInt ? pSymInt->pszName : "<the-same-name>"));
+
+            /* mark the exported symbol exported. */
+            pSymExp->fFlags |= WLDSF_EXPORT_DEF;
 
             /* Skip it all if neither of the symbols are weak. */
@@ -3661,4 +3671,59 @@
 
 /**
+ * Checks the __declspec(dllexport) symbols for weak symbols.
+ * When a weak export is found, it will be added to the .def file.
+ *
+ * @returns 0 on success
+ * @returns !0 on failure after writing sufficient error message.
+ * @param   pWld    Linker instance.
+ * @param   pSym    Symbol.
+ * @param   pvUser  Pointer to a WLDGDCPARAM struct.
+ */
+static int      wldGenerateDefExportEnum(PWLD pWld, PWLDSYM pSym, void *pvUser)
+{
+    PWLDGDCPARAM     pParam = (PWLDGDCPARAM)pvUser;
+
+    if (!pParam->fWeakDllExport)
+    {
+        /* copy the rest of the file if any changes was made. */
+        char szTmp[512];
+        while (!feof(pParam->phOrgFile) && fgets(szTmp, sizeof(szTmp), pParam->phOrgFile))
+            if (fputs(szTmp, pParam->phNewFile) < 0)
+                return wldErr(pWld, "Write error.");
+
+        if (fputs("\n"
+                  "; weakld added weak __declspec(dllexport) exports\n"
+                  "EXPORTS\n",
+                  pParam->phNewFile) < 0)
+            return wldErr(pWld, "Write error.");
+        pParam->fWeakDllExport = 1;
+    }
+
+    /*
+     * Now generate the export entry.
+     */
+    if (!pSym->pAliasFor)
+    {
+        WLDINFO(pWld, ("Adding __declspec(dllexport) weak symbol '%s' to the definition aliasing '%s'",
+                       pSym->pszName, pSym->pszWeakName));
+        fprintf(pParam->phNewFile, "    \"%s\" = \"%s\"\n",
+                pSym->pszName, pSym->pszWeakName);
+    }
+    else
+    {
+        WLDINFO(pWld, ("Adding __declspec(dllexport) weak symbol '%s' to the definition aliasing '%s' (alias)",
+                       pSym->pszName,
+                       pSym->pAliasFor->pszWeakName ? pSym->pAliasFor->pszWeakName : pSym->pAliasFor->pszName));
+        fprintf(pParam->phNewFile, "    \"%s\" = \"%s\"\n",
+                pSym->pszName,
+                pSym->pAliasFor->pszWeakName ? pSym->pAliasFor->pszWeakName : pSym->pAliasFor->pszName);
+    }
+    if (ferror(pParam->phNewFile))
+        return wldErr(pWld, "Write error.");
+    return 0;
+}
+
+
+/**
  * Generates an unique temporary file.
  *
@@ -3745,4 +3810,5 @@
                         param.phNewFile = phFile;
                         param.iLine = 0;
+                        param.fWeakDllExport = 0;
 
                         /* parse it */
@@ -3750,4 +3816,10 @@
                         rc = _md_parse(pMD, wldGenerateDefCallback, &param);
                         _md_close(pMD);
+
+                        /* now see if there are any aliases in __declspec(dllexport) statements. */
+                        if (!rc)
+                            rc = symEnum(pWld, &pWld->Global,
+                                         WLDSF_EXPORT | WLDSF_WEAK, WLDSF_EXPORT | WLDSF_WEAK | WLDSF_EXPORT_DEF | WLDSF_WEAKALIASDONE,
+                                         wldGenerateDefExportEnum, &param);
 
                         /* copy the rest of the file if any changes was made. */
@@ -3759,7 +3831,7 @@
                                     rc = wldErr(pWld, "Write error.");
                         }
-                        else if (!rc)
+                        else if (!rc && !param.fWeakDllExport)
                         {
-                            /* no changes was made. */
+                            /* no changes were made. */
                             WLDINFO(pWld, ("No weak exports, removing file."));
                             fclose(phFile);
