Skip to content

Commit 8d3df83

Browse files
committed
Patch .def files - don't export default atexit, export __chkstk
1 parent c9f60f5 commit 8d3df83

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

windows/mingw/buildsdk.d

+28-6
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,36 @@ void generateDef(bool x64, string inFile, string outFile)
4545
runShell(`cl /EP /D` ~ archDefine ~ `=1 "/I` ~ includeDir ~ `" "` ~ inFile ~ `" > "` ~ outFile ~ `"`);
4646
}
4747

48-
// The MinGW-w64 .def files specify renamings as 'exportedName == realName'.
49-
// The MS format is 'exportedName=realName'.
5048
void sanitizeDef(string defFile)
5149
{
52-
const data = std.file.readText(defFile);
53-
const newData = data.replace(" == ", "=");
54-
if (newData !is data)
55-
std.file.write(defFile, newData);
50+
const lines = std.file.readText(defFile).splitLines;
51+
52+
bool touched = false;
53+
const newLines = lines.map!((const string line)
54+
{
55+
string l = line;
56+
57+
// The MinGW-w64 .def files specify renamings as 'exportedName == realName'.
58+
// The MS format is 'exportedName=realName'.
59+
l = l.replace(" == ", "=");
60+
61+
// Don't export function 'atexit'; we have our own in msvc_atexit.c.
62+
if (l == "atexit" /* 120 */ || l == "atexit DATA" /* < 120 */)
63+
l = "";
64+
65+
// Do export function '__chkstk' (ntdll.dll).
66+
// LLVM emits calls to it to detect stack overflows with '_alloca'.
67+
if (l == ";__chkstk")
68+
l = "__chkstk";
69+
70+
if (l !is line)
71+
touched = true;
72+
73+
return l;
74+
}).array;
75+
76+
if (touched)
77+
std.file.write(defFile, newLines.join("\n"));
5678
}
5779

5880
void copyDefs(bool x64, string inDir, string outDir)

0 commit comments

Comments
 (0)