gendef: Disable reserved symbol names by default Mark few reserved symbols as PRIVATE which tells dlltool to not include them into generated import library. Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-tools/gendef/src/gendef.c b/mingw-w64-tools/gendef/src/gendef.c index b56777d..8786954 100644 --- a/mingw-w64-tools/gendef/src/gendef.c +++ b/mingw-w64-tools/gendef/src/gendef.c
@@ -345,6 +345,42 @@ } 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) { PIMAGE_SECTION_HEADER sec; @@ -785,6 +821,10 @@ 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, '.') ? "\"" : "";