[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 13:59:12 PDT 2025
================
@@ -114,6 +114,35 @@ static coff_symbol_generic *cloneSymbol(COFFSymbolRef sym) {
}
}
+// Skip importing DllMain thunks from import libraries.
+static bool fixupDllMain(COFFLinkerContext &ctx, llvm::object::Archive *file,
+ const Archive::Symbol &sym, bool &skipDllMain) {
+ if (skipDllMain)
+ return true;
+ const Archive::Child &c =
+ CHECK(sym.getMember(), file->getFileName() +
+ ": could not get the member for symbol " +
+ toCOFFString(ctx, sym));
+ MemoryBufferRef mb =
+ CHECK(c.getMemoryBufferRef(),
+ file->getFileName() +
+ ": could not get the buffer for a child buffer of the archive");
+ if (identify_magic(mb.getBuffer()) == file_magic::coff_import_library) {
+ if (ctx.config.warnExportedDllMain) {
+ // We won't place DllMain symbols in the symbol table if they are
+ // coming from a import library. This message can be ignored with the flag
+ // '/ignore:exporteddllmain'
+ Warn(ctx)
+ << file->getFileName()
+ << ": skipping exported DllMain symbol [exporteddllmain]\nNOTE: this "
----------------
mstorsjo wrote:
Sorry I'm a little late to the party here, but I think the option naming (and likewise the internal variables, but they're less effort to change later) feels a bit backwards here.
>From the point of view of this link, there's an **imported** `DllMain` that we're ignoring. (This import lib entry probably exists because some DLL erroneously does export it, yes, but from the point of view of this linking, the issue is about an imported `DllMain`, not an issue about ourselves exporting `DllMain`.)
https://github.com/llvm/llvm-project/pull/146610
More information about the llvm-commits
mailing list