[lld] [LLD][COFF] Fix importing DllMain from import libraries (PR #146610)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 14:02:10 PDT 2025


================
@@ -176,8 +205,17 @@ void ArchiveFile::parse() {
   }
 
   // Read the symbol table to construct Lazy objects.
-  for (const Archive::Symbol &sym : file->symbols())
+  bool skipDllMain = false;
+  for (const Archive::Symbol &sym : file->symbols()) {
+    // If the DllMain symbol was exported by mistake, skip importing it
+    // otherwise we might end up with a import thunk in the final binary which
+    // is wrong.
----------------
mstorsjo wrote:

I find this comment a bit hand-wavy. Obviously, calling another DLL's `DllMain` rathern than our own is not going to be doing the right thing - it's not so much about an import thunk or so, right? So I'd rather just say this: 

```
// If an import library provides the DllMain symbol, skip importing it, as we should be using our own DllMain, not another DLL's DllMain.
```

https://github.com/llvm/llvm-project/pull/146610


More information about the llvm-commits mailing list