[PATCH] D65964: [lld-link] implement -thinlto-obj-path

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 11:33:06 PDT 2019


inglorion created this revision.
inglorion added reviewers: ruiu, tejohnson, pcc, rnk.
Herald added subscribers: dexonsmith, steven_wu, mehdi_amini.
Herald added a project: LLVM.

This implements the -thinlto-obj-path option in lld-link. This can be
used to specify a path at which to write a native object file for
the full LTO part when using LTO unit splitting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65964

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/LTO.cpp
  lld/COFF/Options.td
  lld/test/COFF/thinlto-obj-path.ll


Index: lld/test/COFF/thinlto-obj-path.ll
===================================================================
--- /dev/null
+++ lld/test/COFF/thinlto-obj-path.ll
@@ -0,0 +1,25 @@
+; REQUIRES: x86
+
+; Test to ensure that thinlto-index-only with thinlto-obj-path creates
+; the native object file.
+; RUN: opt -module-summary %s -o %t1.obj
+; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.obj
+; RUN: rm -f %t4.obj
+; RUN: lld-link -thinlto-index-only -thinlto-obj-path:%t4.obj -out:t3.exe \
+; RUN:     -entry:main %t1.obj %t2.obj
+; RUN: llvm-readobj -h %t4.obj | FileCheck %s
+; RUN: llvm-nm %t4.obj 2>&1 | FileCheck %s -check-prefix=SYMBOLS
+; RUN: llvm-nm %t4.obj 2>&1 | count 1
+
+; CHECK: Format: COFF-x86-64
+; SYMBOLS: @feat.00
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.0.24215"
+
+declare void @g(...)
+
+define void @main() {
+  call void (...) @g()
+  ret void
+}
Index: lld/COFF/Options.td
===================================================================
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -185,6 +185,9 @@
 def thinlto_index_only_arg : P<
     "thinlto-index-only",
     "-thinlto-index-only and also write native module names to file">;
+def thinlto_obj_path : P<
+    "thinlto-obj-path",
+    "output native object for split LTO unit to this path">;
 def thinlto_object_suffix_replace : P<
     "thinlto-object-suffix-replace",
     "'old;new' replace old suffix with new suffix in ThinLTO index">;
Index: lld/COFF/LTO.cpp
===================================================================
--- lld/COFF/LTO.cpp
+++ lld/COFF/LTO.cpp
@@ -177,6 +177,8 @@
   // files. After that, we exit from linker and ThinLTO backend runs in a
   // distributed environment.
   if (config->thinLTOIndexOnly) {
+    if (!config->thinLTOObjPath.empty())
+      saveBuffer(buf[0], config->thinLTOObjPath);
     if (indexFile)
       indexFile->close();
     return {};
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1471,6 +1471,7 @@
                              args.hasArg(OPT_thinlto_index_only_arg);
   config->thinLTOIndexOnlyArg =
       args.getLastArgValue(OPT_thinlto_index_only_arg);
+  config->thinLTOObjPath = args.getLastArgValue(OPT_thinlto_obj_path);
   config->thinLTOPrefixReplace =
       getOldNewOptions(args, OPT_thinlto_prefix_replace);
   config->thinLTOObjectSuffixReplace =
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -183,6 +183,9 @@
   // Used for /thinlto-index-only:
   llvm::StringRef thinLTOIndexOnlyArg;
 
+  // Used for /thinlto-obj-path:
+  llvm::StringRef thinLTOObjPath;
+
   // Used for /thinlto-object-prefix-replace:
   std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65964.214199.patch
Type: text/x-patch
Size: 2909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190808/70c6da8a/attachment.bin>


More information about the llvm-commits mailing list