[clang] [clang][MinGW] Always link ntdll.dll (PR #162997)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 11 05:28:43 PDT 2025
https://github.com/trcrsired created https://github.com/llvm/llvm-project/pull/162997
GCC with MCF threads has already linked ntdll.dll for serveral years. First, all supported windows versions are NT-based and even on 9x OSes such as Windows 95, ntdll.dll still exists. Plus the linker won't link to ntdll.dll if user does not use any ntdll functions.
There is no reason not to link ntdll.dll when kernel32.dll is always linked
https://github.com/gcc-mirror/gcc/blob/master/gcc/config/mingw/mingw32.h#L199
>From cd2727ca58b01f70ee638f8136d7ba202683708f Mon Sep 17 00:00:00 2001
From: trcrsired <uwgghhbcad at gmail.com>
Date: Sat, 11 Oct 2025 20:22:22 +0800
Subject: [PATCH] [clang][MinGW] Always link ntdll.dll
GCC with MCF threads has already linked ntdll.dll for serveral years.
First, all supported windows versions are NT-based and even on 9x OSes
such as Windows 95, ntdll.dll still exists. Plus the linker won't link
to ntdll.dll if user does not use any ntdll functions.
There is no reason not to link ntdll.dll when kernel32.dll is always
linked
---
clang/lib/Driver/ToolChains/MinGW.cpp | 5 ++++-
clang/test/Driver/mingw-windowsapp.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 1bb9bcfe6aab2..336e236cfdd58 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -359,14 +359,17 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lshell32");
CmdArgs.push_back("-luser32");
CmdArgs.push_back("-lkernel32");
+ CmdArgs.push_back("-lntdll");
}
if (Args.hasArg(options::OPT_static)) {
CmdArgs.push_back("--end-group");
} else {
AddLibGCC(Args, CmdArgs);
- if (!HasWindowsApp)
+ if (!HasWindowsApp) {
CmdArgs.push_back("-lkernel32");
+ CmdArgs.push_back("-lntdll");
+ }
}
}
diff --git a/clang/test/Driver/mingw-windowsapp.c b/clang/test/Driver/mingw-windowsapp.c
index d0a44952b30a3..50950c0195995 100644
--- a/clang/test/Driver/mingw-windowsapp.c
+++ b/clang/test/Driver/mingw-windowsapp.c
@@ -1,6 +1,6 @@
// RUN: %clang -v --target=i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DEFAULT %s
// RUN: %clang -v --target=i686-pc-windows-gnu -### %s -lwindowsapp 2>&1 | FileCheck -check-prefix=CHECK_WINDOWSAPP %s
-// CHECK_DEFAULT: "-lmsvcrt" "-ladvapi32" "-lshell32" "-luser32" "-lkernel32" "-lmingw32"
+// CHECK_DEFAULT: "-lmsvcrt" "-ladvapi32" "-lshell32" "-luser32" "-lkernel32" "-lntdll" "-lmingw32"
// CHECK_WINDOWSAPP: "-lwindowsapp" "-lmingw32"
// CHECK_WINDOWSAPP-SAME: "-lmsvcrt" "-lmingw32"
More information about the cfe-commits
mailing list