Skip to content

Commit 9f4157a

Browse files
committed
Fixup .def(.in) files to export functions replaced by the MinGW runtime
1 parent f86b63d commit 9f4157a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

windows/mingw/buildsdk.d

+20-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ string patchLines(string inFile, string outFile, LineTransformer lineTransformer
6868
// Preprocesses a 'foo.def.in' file to 'foo.def'.
6969
void generateDef(string inFile, string outFile)
7070
{
71-
const includeDir = buildPath(dirName(dirName(inFile)), "def-include");
71+
const patchedInFile = outFile ~ ".in";
72+
const realInFile = patchLines(inFile, patchedInFile, (line)
73+
{
74+
// The MinGW-w64 .def.in files use 'F_X86_ANY(DATA)' to hide functions
75+
// overridden by the MinGW runtime, primarily math functions.
76+
return line.replace(" F_X86_ANY(DATA)", "");
77+
});
78+
79+
const includeDir = buildPath(inFile.dirName.dirName, "def-include");
7280
const archDefine = x64 ? "DEF_X64" : "DEF_I386";
73-
runShell(`cl /EP /D` ~ archDefine ~ `=1 "/I` ~ includeDir ~ `" "` ~ inFile ~ `" > "` ~ outFile ~ `"`);
81+
runShell(`cl /EP /D` ~ archDefine ~ `=1 "/I` ~ includeDir ~ `" "` ~ realInFile ~ `" > "` ~ outFile ~ `"`);
7482
}
7583

7684
void sanitizeDef(string defFile)
@@ -97,6 +105,15 @@ void sanitizeDef(string defFile)
97105
}
98106
}
99107

108+
// The MinGW runtime apparently replaces ceil(f)/floor(f) and hides the original functions via DATA.
109+
if (line == "ceil DATA" || line == "ceilf DATA" ||
110+
line == "floor DATA" || line == "floorf DATA")
111+
return line[0 .. $-5];
112+
113+
// MinGW apparently also replaces ucrtbase.dll's '_tzset'.
114+
if (line == "_tzset DATA")
115+
return "_tzset";
116+
100117
// Don't export function 'atexit'; we have our own in msvc_atexit.c.
101118
if (line == "atexit")
102119
return "";
@@ -259,6 +276,6 @@ void main(string[] args)
259276
buildUuid(outDir);
260277

261278
//version (verbose) {} else
262-
foreach (f; std.file.dirEntries(outDir, "*.def", SpanMode.shallow))
279+
foreach (f; std.file.dirEntries(outDir, "*.def*", SpanMode.shallow))
263280
std.file.remove(f.name);
264281
}

0 commit comments

Comments
 (0)