8000 [clang][MinGW] Always link ntdll.dll by trcrsired · Pull Request #162997 · llvm/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

Conversation

trcrsired
Copy link
Contributor

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

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
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Oct 11, 2025
@llvmbot
Copy link
Member
llvmbot commented Oct 11, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: cqwrteur (trcrsired)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/162997.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+4-1)
  • (modified) clang/test/Driver/mingw-windowsapp.c (+1-1)
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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0