dlltool: Use the dll name as unique object file prefix instead of getpid()

Message ID 20220104202153.1007004-1-martin@martin.st
State New
Headers show
Series
  • dlltool: Use the dll name as unique object file prefix instead of getpid()
Related show

Commit Message

Martin Storsjö Jan. 4, 2022, 8:21 p.m.
This makes the output deterministic without requiring the caller to
pass --temp-prefix.

This also avoids potential prefix clashes, if building multiple import
libraries that later are merged into one single import library (which
is done for a number of umbrella libraries in mingw-w64-crt).

Signed-off-by: Martin Storsjö <martin@martin.st>

---
 binutils/dlltool.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

-- 
2.25.1

Comments

H.J. Lu via Binutils Jan. 11, 2022, 3:46 p.m. | #1
Hi Martin,

> This makes the output deterministic without requiring the caller to

> pass --temp-prefix.

> 

> This also avoids potential prefix clashes, if building multiple import

> libraries that later are merged into one single import library (which

> is done for a number of umbrella libraries in mingw-w64-crt).


Patch approved and applied.

Cheers
   Nick

Patch

diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 8c1ddd61f63..83f30676f77 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -3930,9 +3930,6 @@  main (int ac, char **av)
 	}
     }
 
-  if (!tmp_prefix)
-    tmp_prefix = prefix_encode ("d", getpid ());
-
   for (i = 0; mtable[i].type; i++)
     if (strcmp (mtable[i].type, mname) == 0)
       break;
@@ -3992,6 +3989,22 @@  main (int ac, char **av)
       optind++;
     }
 
+  if (!tmp_prefix)
+    {
+      if (dll_name)
+        {
+          tmp_prefix = xmalloc (strlen (dll_name) + 2);
+          sprintf (tmp_prefix, "%s_", dll_name);
+          for (i = 0; tmp_prefix[i]; i++)
+            if (!ISALNUM (tmp_prefix[i]))
+              tmp_prefix[i] = '_';
+        }
+      else
+        {
+          tmp_prefix = prefix_encode ("d", getpid ());
+        }
+    }
+
   mangle_defs ();
 
   if (exp_name)