Mark few reserved symbols as PRIVATE which tells dlltool to not include
them into generated import library.
---
 mingw-w64-tools/gendef/src/gendef.c | 40 +++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/mingw-w64-tools/gendef/src/gendef.c 
b/mingw-w64-tools/gendef/src/gendef.c
index b56777db4cd5..8786954b0d9c 100644
--- a/mingw-w64-tools/gendef/src/gendef.c
+++ b/mingw-w64-tools/gendef/src/gendef.c
@@ -344,6 +344,42 @@ load_pep (void)
   return 1;
 }
 
+static int
+is_reserved_name (const char *name)
+{
+  static const char * const reserved_names[] = {
+    /* PRIVATE symbols triggering LNK4104 error:
+     * 
https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4104
+     */
+    "DllCanUnloadNow",
+    "DllGetClassObject",
+    "DllGetClassFactoryFromClassString",
+    "DllGetDocumentation",
+    "DllInitialize",
+    "DllInstall",
+    "DllRegisterServer",
+    "DllRegisterServerEx",
+    "DllRegisterServerExW",
+    "DllUnload",
+    "DllUnregisterServer",
+    "RasCustomDeleteEntryNotify",
+    "RasCustomDial",
+    "RasCustomDialDlg",
+    "RasCustomEntryDlg",
+
+    /* Symbols commonly used as entry points */
+    "DllEntryPoint",
+    "DllMain",
+  };
+  size_t i;
+
+  for (i = 0; i < sizeof(reserved_names)/sizeof(*reserved_names); i++)
+    if (strcmp(name, reserved_names[i]) == 0)
+      return 1;
+
+  return 0;
+}
+
 static int
 is_data (uint32_t va)
 {
@@ -785,6 +821,10 @@ dump_def (void)
         fprintf(fp," @%u NONAME", (unsigned int) exp->ord);
       if (exp->beData)
         fprintf(fp," DATA");
+
+      if (is_reserved_name(exp->name))
+        fprintf(fp, " PRIVATE");
+
       if (name_has_at_suffix || name_has_fastcall)
         {
           const char *quote = strchr (exp->name, '.') ? "\"" : "";
-- 
2.20.1



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

Reply via email to