[lld] [LLD][COFF] Update nodefaultlibs after updating search paths (PR #128813)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 20:17:41 PST 2025


https://github.com/A2uria created https://github.com/llvm/llvm-project/pull/128813

Fix #107346

>From b5973588b79aedeaf2f19dcb8eb3fbba9e1da457 Mon Sep 17 00:00:00 2001
From: A2uria <a2uria at qq.com>
Date: Wed, 26 Feb 2025 12:13:00 +0800
Subject: [PATCH] [LLD][COFF] Update nodefaultlibs after updating search paths

---
 lld/COFF/Driver.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 1589323073c09..086ec83cc5206 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -786,6 +786,13 @@ void LinkerDriver::addWinSysRootLibSearchPaths() {
                                       path))
       searchPaths.push_back(saver().save(path));
   }
+
+  // Libraries specified by `/nodefaultlib:` may not be found in incomplete
+  // search paths before lld infers a machine type from input files.
+  std::set<std::string> noDefaultLibs;
+  for (const std::string &path : ctx.config.noDefaultLibs)
+    noDefaultLibs.insert(findLib(path).lower());
+  ctx.config.noDefaultLibs = noDefaultLibs;
 }
 
 // Parses LIB environment which contains a list of search paths.



More information about the llvm-commits mailing list