[lld] 33f9342 - [lld][COFF] Add -print-search-paths for debugging.

Tobias Hieta via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 13 01:53:21 PDT 2023


Author: Tobias Hieta
Date: 2023-07-13T10:52:57+02:00
New Revision: 33f93425dd1b8028bf2db43fb23abd0244cd7467

URL: https://github.com/llvm/llvm-project/commit/33f93425dd1b8028bf2db43fb23abd0244cd7467
DIFF: https://github.com/llvm/llvm-project/commit/33f93425dd1b8028bf2db43fb23abd0244cd7467.diff

LOG: [lld][COFF] Add -print-search-paths for debugging.

While working on adding more implicit search paths to the
lld COFF driver, it was helpful to have a way to print all
the search paths, both for debugging and for testing without
having to create very complicated test cases.

This is a simple arg that just prints the search paths and exits.

Related to the efforts in #63827

Differential Revision: https://reviews.llvm.org/D155047

Added: 
    lld/test/COFF/print-search-paths.s

Modified: 
    lld/COFF/Config.h
    lld/COFF/Driver.cpp
    lld/COFF/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 7d5b664599b549..96b49ed3850d49 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -132,6 +132,7 @@ struct Configuration {
   bool driverWdm = false;
   bool showTiming = false;
   bool showSummary = false;
+  bool printSearchPaths = false;
   unsigned debugTypes = static_cast<unsigned>(DebugType::None);
   llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
   std::vector<std::string> natvisFiles;

diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 15a14981a36a28..5cefdac3395ebf 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1500,6 +1500,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
     config->showTiming = true;
 
   config->showSummary = args.hasArg(OPT_summary);
+  config->printSearchPaths = args.hasArg(OPT_print_search_paths);
 
   // Handle --version, which is an lld extension. This option is a bit odd
   // because it doesn't start with "/", but we deliberately chose "--" to
@@ -2052,6 +2053,17 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   }
   config->wordsize = config->is64() ? 8 : 4;
 
+  if (config->printSearchPaths) {
+    SmallString<256> buffer;
+    raw_svector_ostream stream(buffer);
+    stream << "Library search paths:\n";
+
+    for (StringRef path : searchPaths)
+      stream << "  " << path << "\n";
+
+    message(buffer);
+  }
+
   // Process files specified as /defaultlib. These must be processed after
   // addWinSysRootLibSearchPaths(), which is why they are in a separate loop.
   for (auto *arg : args.filtered(OPT_defaultlib))

diff  --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index f7d9eeb7e7250e..ea4ddb2d849534 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -295,6 +295,7 @@ def lldmap_file : P_priv<"lldmap">;
 def map : F<"map">;
 def map_file : P_priv<"map">;
 def map_info : P<"mapinfo", "Include the specified information in a map file">;
+def print_search_paths : F<"print-search-paths">;
 def show_timing : F<"time">;
 def summary : F<"summary">;
 

diff  --git a/lld/test/COFF/print-search-paths.s b/lld/test/COFF/print-search-paths.s
new file mode 100644
index 00000000000000..a484ac5b0fb164
--- /dev/null
+++ b/lld/test/COFF/print-search-paths.s
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+# RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
+# RUN: lld-link -safeseh:no /dll /noentry /winsysroot:%t.dir/sysroot /vctoolsversion:1.1.1.1 /winsdkversion:10.0.1 %t.obj -print-search-paths | FileCheck -DSYSROOT=%t.dir %s
+# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t_32.obj
+# RUN: lld-link -safeseh:no /dll /noentry /winsysroot:%t.dir/sysroot /vctoolsversion:1.1.1.1 /winsdkversion:10.0.1 %t_32.obj -print-search-paths | FileCheck -DSYSROOT=%t.dir -check-prefix=X86 %s
+# CHECK: Library search paths:
+# CHECK:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}VC{{[/\\]}}Tools{{[/\\]}}MSVC{{[/\\]}}1.1.1.1{{[/\\]}}lib{{[/\\]}}x64
+# CHECK:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}VC{{[/\\]}}Tools{{[/\\]}}MSVC{{[/\\]}}1.1.1.1{{[/\\]}}atlmfc{{[/\\]}}lib{{[/\\]}}x64
+# CHECK:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}Windows Kits{{[/\\]}}10{{[/\\]}}Lib{{[/\\]}}10.0.1{{[/\\]}}ucrt{{[/\\]}}x64
+# CHECK:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}Windows Kits{{[/\\]}}10{{[/\\]}}Lib{{[/\\]}}10.0.1{{[/\\]}}um{{[/\\]}}x64
+# X86: Library search paths:
+# X86:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}VC{{[/\\]}}Tools{{[/\\]}}MSVC{{[/\\]}}1.1.1.1{{[/\\]}}lib{{[/\\]}}x86
+# X86:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}VC{{[/\\]}}Tools{{[/\\]}}MSVC{{[/\\]}}1.1.1.1{{[/\\]}}atlmfc{{[/\\]}}lib{{[/\\]}}x86
+# X86:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}Windows Kits{{[/\\]}}10{{[/\\]}}Lib{{[/\\]}}10.0.1{{[/\\]}}ucrt{{[/\\]}}x86
+# X86:   [[SYSROOT]]{{[/\\]}}sysroot{{[/\\]}}Windows Kits{{[/\\]}}10{{[/\\]}}Lib{{[/\\]}}10.0.1{{[/\\]}}um{{[/\\]}}x86
+
+
+        .text
+        .globl  _main
+_main:
+        ret


        


More information about the llvm-commits mailing list