If there is a def file "lib1.def" with line "func1" and gendef was called
on lib2.dll which contains func2 symbol defined as PE forward to lib1.func1
then gendef produces "lib2.def" file with line "func2@0 = lib1.func1" even
when gendef was not called with -a option.

This behavior is wrong because func1 in lib1.def is not defined as stdcall
therefore gendef should not add stdcall decoration for func2.

This change fixes this issue, changes the way how gendef reads and parse
input def files.
---
 mingw-w64-tools/gendef/src/gendef.c     |  5 ++++-
 mingw-w64-tools/gendef/src/gendef_def.c | 22 ++++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/mingw-w64-tools/gendef/src/gendef.c 
b/mingw-w64-tools/gendef/src/gendef.c
index c25734c4c4e5..e0d8fee6ef3f 100644
--- a/mingw-w64-tools/gendef/src/gendef.c
+++ b/mingw-w64-tools/gendef/src/gendef.c
@@ -737,6 +737,7 @@ dump_def (void)
   while ((exp = gExp) != NULL)
     {
       sImportname *pimpname;
+      int has_info = 0;
       int seen_ret;
       seen_ret = 1;
       gExp = exp->next;
@@ -759,6 +760,7 @@ dump_def (void)
          uint32_t at = 0;
          if (gendef_getsymbol_info (pimpname->dll, pimpname->name, &isD, &at))
            {
+             has_info = 1;
              exp->beData = isD;
              if (!isD)
                exp->retpop = at;
@@ -770,6 +772,7 @@ dump_def (void)
          uint32_t at = 0;
          if (gendef_getsymbol_info (exp->forward, NULL, &isD, &at))
            {
+             has_info = 1;
              exp->beData = isD;
              if (!isD)
                exp->retpop = at;
@@ -842,7 +845,7 @@ dump_def (void)
       if (exp->retpop != (uint32_t) -1 && !exp->be64 && has_atdecoration() && 
exp->name[0] == '?')
         fprintf(fp," ; has WINAPI (@%u)", (unsigned int) exp->retpop);
 
-      if (exp->name[0] != 0 && (exp->retpop != (uint32_t) -1 || (exp->retpop 
== 0 && exp->be64) || !has_atdecoration ()))
+      if (exp->name[0] != 0 && (has_info || exp->retpop != (uint32_t) -1 || 
(exp->retpop == 0 && exp->be64) || !has_atdecoration ()))
        {
        }
       else if (pimpname)
diff --git a/mingw-w64-tools/gendef/src/gendef_def.c 
b/mingw-w64-tools/gendef/src/gendef_def.c
index 3dc33b805ee4..fdecf3b3582d 100644
--- a/mingw-w64-tools/gendef/src/gendef_def.c
+++ b/mingw-w64-tools/gendef/src/gendef_def.c
@@ -49,7 +49,7 @@ static int add_path_def (const char *path);
 static sImpDef *is_def_loaded (const char *);
 static sImpDef *gendef_loaddef (const char *);
 static FILE *fopen_def (const char *name);
-static uint32_t get_uint32_by_str (const char *txt);
+static uint32_t get_uint32_by_str (const char **txt_ptr);
 
 int
 gendef_getsymbol_info (const char *dllname, const char *symbolname, int 
*isData, uint32_t *at)
@@ -91,7 +91,7 @@ gendef_getsymbol_info (const char *dllname, const char 
*symbolname, int *isData,
   id = gendef_loaddef (def);
   if (id)
     {
-      char *t = id->data;
+      const char *t = id->data;
       while (t != NULL && *t != 0)
        {
          t = strchr (t, '\n');
@@ -99,10 +99,18 @@ gendef_getsymbol_info (const char *dllname, const char 
*symbolname, int *isData,
            t++;
          if (t && strncmp (t, symbolname, symlen) == 0)
            {
-             if ((t[symlen] > 0 && t[symlen] <= 0x20) || t[symlen] == '@')
+             if ((t[symlen] >= 0 && t[symlen] <= 0x20) || t[symlen] == '@')
                {
-                 t += symlen + 1;
-                 *at = get_uint32_by_str (t);
+                 *at = -1;
+                 t += symlen;
+                 if (t[symlen] == '@')
+                   {
+                     t++;
+                     const char *old_t = t;
+                     int num = get_uint32_by_str (&t);
+                     if (old_t != t)
+                       *at = num;
+                   }
                  while (*t != 0 && *t != '\n')
                    {
                      if (!strncmp (t, "DATA", 4))
@@ -228,8 +236,9 @@ is_def_loaded (const char *dname)
 }
 
 static uint32_t
-get_uint32_by_str (const char *txt)
+get_uint32_by_str (const char **txt_ptr)
 {
+  const char *txt = *txt_ptr;
   uint32_t ret = 0;
   while (*txt != 0 && *txt >= '0' && *txt <= '9')
     {
@@ -237,6 +246,7 @@ get_uint32_by_str (const char *txt)
       ret += (uint32_t) (txt[0] - '0');
       ++txt;
     }
+  *txt_ptr = txt;
   return ret;
 }
 
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to