@@ -27,7 +27,6 @@ import std.string;
2727version = verbose;
2828
2929bool x64;
30- string [string ] weakSymbols; // weak name => real name
3130
3231
3332void runShell (string cmd)
@@ -132,17 +131,15 @@ void sanitizeDef(string defFile)
132131 return ` LIBRARY "vcruntime140.dll"` ;
133132
134133 // The MinGW-w64 .def files specify weak external symbols as 'alias == realName'.
134+ // Just ignore them; they are incomplete and sometimes wrong.
135135 const i = line.indexOf(" ==" );
136136 if (i > 0 )
137137 {
138138 const weakName = strip(line[0 .. i]);
139139 const realName = strip(line[i+ 2 .. $]);
140140
141141 if (weakName.indexOf(' ' ) < 0 && realName.indexOf(' ' ) < 0 )
142- {
143- weakSymbols[weakName] = realName;
144142 return " ;" ~ line;
145- }
146143 }
147144
148145 // Un-hide functions overridden by the MinGW runtime.
@@ -393,47 +390,34 @@ void buildMsvcrt(string outDir)
393390
394391void buildOldnames (string outDir)
395392{
396- static string prependUnderscore (string symbolName)
397- {
398- return symbolName.startsWith(" __imp_" )
399- ? symbolName[0 .. 6 ] ~ " _" ~ symbolName[6 .. $] // __imp_name => __imp__name
400- : " _" ~ symbolName; // name => _name
401- }
393+ static struct WeakSymbol { string name; string targetName; }
394+ WeakSymbol[] weakSymbols;
402395
403- const lines = std.file.readText (" oldnames.list" ).splitLines;
404- foreach (line; lines)
396+ void processAliasesFile (string path)
405397 {
406- if (line.length == 0 )
407- continue ;
398+ foreach (line; std.file.readText (path).splitLines)
399+ {
400+ if (line.length == 0 || line[0 ] == ' ;' )
401+ continue ;
408402
409- string weakName;
410- string realName;
403+ const equalsIndex = line.indexOf(' =' );
404+ const weakName = line[0 .. equalsIndex];
405+ const realName = line[equalsIndex+ 1 .. $];
411406
412- const equalsIndex = line.indexOf(' =' );
413- if (equalsIndex > 0 )
414- {
415- weakName = line[0 .. equalsIndex];
416- realName = line[equalsIndex+ 1 .. $];
417- }
418- else // most real names just feature an additional leading underscore
419- {
420- weakName = line;
421- realName = prependUnderscore(weakName);
407+ weakSymbols ~= WeakSymbol(weakName, realName);
422408 }
423-
424- weakSymbols[weakName] = realName;
425409 }
426410
427- static string getMangledName ( string symbolName)
428- {
429- return x64 ? symbolName : prependUnderscore(symbolName);
430- }
411+ const suffix = x64 ? " 64 " : " 32 " ;
412+ processAliasesFile( " oldnames.aliases " ~ suffix);
413+ // include the weak symbols from msvcrt.lib too
414+ processAliasesFile( " msvcrt140.aliases " ~ suffix);
431415
432416 const oldnames_c =
433- // access this __ref_oldnames symbol to drag in the generated linker directives (msvcrt_stub.c)
417+ // access this __ref_oldnames symbol (in msvcrt_stub.c) to drag in the generated linker directives
434418 " int __ref_oldnames;\n " ~
435- weakSymbols.byKeyValue . map! (pair =>
436- ` __pragma(comment(linker, "/alternatename:` ~ getMangledName(pair.key) ~ ` =` ~ getMangledName(pair.value) ~ ` "));`
419+ weakSymbols.map! (sym =>
420+ ` __pragma(comment(linker, "/alternatename:` ~ sym.name ~ ` =` ~ sym.targetName ~ ` "));`
437421 ).join(" \n " );
438422
439423 version (verbose)
0 commit comments