@@ -27,7 +27,6 @@ import std.string;
27
27
version = verbose;
28
28
29
29
bool x64;
30
- string [string ] weakSymbols; // weak name => real name
31
30
32
31
33
32
void runShell (string cmd)
@@ -132,17 +131,15 @@ void sanitizeDef(string defFile)
132
131
return ` LIBRARY "vcruntime140.dll"` ;
133
132
134
133
// The MinGW-w64 .def files specify weak external symbols as 'alias == realName'.
134
+ // Just ignore them; they are incomplete and sometimes wrong.
135
135
const i = line.indexOf(" ==" );
136
136
if (i > 0 )
137
137
{
138
138
const weakName = strip(line[0 .. i]);
139
139
const realName = strip(line[i+ 2 .. $]);
140
140
141
141
if (weakName.indexOf(' ' ) < 0 && realName.indexOf(' ' ) < 0 )
142
- {
143
- weakSymbols[weakName] = realName;
144
142
return " ;" ~ line;
145
- }
146
143
}
147
144
148
145
// Un-hide functions overridden by the MinGW runtime.
@@ -393,47 +390,34 @@ void buildMsvcrt(string outDir)
393
390
394
391
void buildOldnames (string outDir)
395
392
{
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;
402
395
403
- const lines = std.file.readText (" oldnames.list" ).splitLines;
404
- foreach (line; lines)
396
+ void processAliasesFile (string path)
405
397
{
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 ;
408
402
409
- string weakName;
410
- string realName;
403
+ const equalsIndex = line.indexOf(' =' );
404
+ const weakName = line[0 .. equalsIndex];
405
+ const realName = line[equalsIndex+ 1 .. $];
411
406
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);
422
408
}
423
-
424
- weakSymbols[weakName] = realName;
425
409
}
426
410
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);
431
415
432
416
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
434
418
" 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 ~ ` "));`
437
421
).join(" \n " );
438
422
439
423
version (verbose)
0 commit comments