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

Tobias Hieta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 00:25:52 PDT 2023


thieta created this revision.
Herald added a project: All.
thieta requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155047

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/Options.td
  lld/test/COFF/print-search-paths.s


Index: lld/test/COFF/print-search-paths.s
===================================================================
--- /dev/null
+++ lld/test/COFF/print-search-paths.s
@@ -0,0 +1,29 @@
+# REQUIRES: x86
+# RUN: mkdir -p %t.dir/sysroot/VC/Tools/MSVC/1.1.1.1/lib/x86
+# RUN: mkdir -p %t.dir/sysroot/VC/Tools/MSVC/1.1.1.1/lib/x64
+# RUN: mkdir -p %t.dir/sysroot/VC/Tools/MSVC/1.1.1.1/ATLMFC/lib/x86
+# RUN: mkdir -p %t.dir/sysroot/VC/Tools/MSVC/1.1.1.1/ATLMFC/lib/x64
+# RUN: mkdir -p %t.dir/sysroot/Windows Kits/10/Lib/10.0.1/ucrt/x86
+# RUN: mkdir -p %t.dir/sysroot/Windows Kits/10/Lib/10.0.1/ucrt/x64
+# RUN: mkdir -p %t.dir/sysroot/Windows Kits/10/Lib/10.0.1/um/x86
+# RUN: mkdir -p %t.dir/sysroot/Windows Kits/10/Lib/10.0.1/um/x64
+# RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
+# RUN: lld-link /winsysroot:%t.dir/sysroot /winsdkversion:10.0.1 %t.obj -print-search-paths | FileCheck %s
+# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t_32.obj
+# RUN: lld-link /winsysroot:%t.dir/sysroot /winsdkversion:10.0.1 %t_32.obj -print-search-paths | FileCheck %s -check-prefix X86
+# CHECK: Library search paths:
+# CHECK:   sysroot\VC\Tools\MSVC\1.1.1.1\lib\x64
+# CHECK:   sysroot\VC\Tools\MSVC\1.1.1.1\atlmfc\lib\x64
+# CHECK:   sysroot\Windows Kits\10\Lib\10.0.1\ucrt\x64
+# CHECK:   sysroot\Windows Kits\10\Lib\10.0.1\um\x64
+# X86: Library search paths:
+# X86:   sysroot\VC\Tools\MSVC\1.1.1.1\lib\x86
+# X86:   sysroot\VC\Tools\MSVC\1.1.1.1\atlmfc\lib\x86
+# X86:   sysroot\Windows Kits\10\Lib\10.0.1\ucrt\x86
+# X86:   sysroot\Windows Kits\10\Lib\10.0.1\um\x86
+
+
+        .text
+        .globl  _main
+_main:
+        ret
Index: lld/COFF/Options.td
===================================================================
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -297,6 +297,7 @@
 def map_info : P<"mapinfo", "Include the specified information in a map file">;
 def show_timing : F<"time">;
 def summary : F<"summary">;
+def print_search_paths : F<"print-search-paths">;
 
 //==============================================================================
 // The flags below do nothing. They are defined only for link.exe compatibility.
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1500,6 +1500,7 @@
     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,18 @@
   }
   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);
+    return;
+  }
+
   // 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))
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -132,6 +132,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155047.539414.patch
Type: text/x-patch
Size: 3636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230712/436a8278/attachment.bin>


More information about the llvm-commits mailing list