[lld] [LLD][COFF] Don't dllimport from static libraries (PR #134443)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 4 13:44:07 PDT 2025


================
@@ -231,6 +231,17 @@ void SymbolTable::reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
   }
   if (numDisplayedRefs < numRefs)
     diag << "\n>>> referenced " << numRefs - numDisplayedRefs << " more times";
+
+  // Hints
+  StringRef name = undefDiag.sym->getName();
+  if (name.starts_with("__imp_")) {
+    Symbol *imp = find(name.substr(strlen("__imp_")));
+    if (imp && imp->isLazy()) {
+      diag << "\nNOTE: a relevant symbol '" << imp->getName()
+           << "' is available in " << toString(imp->getFile())
+           << " but cannot be used because it is not a import library.";
----------------
mstorsjo wrote:

Nit: **an** import library

Initially I felt confused by this message, but I think it may be the best way to phrase it. The other angle at this is, that if this wasn't a static library but object files, or members in a static library that we've already pulled in, then we'd actually link it successfully. But it's hard to suggest that in the diagnostic, and we probably don't want to push users that way anyway. So I guess this wording is fine.

I don't see this diagnostic tested though - I think it would be good to check that we do hit it.


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


More information about the llvm-commits mailing list