diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h --- a/lld/COFF/Config.h +++ b/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 thinLTOPrefixReplace; diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/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 = diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp --- a/lld/COFF/LTO.cpp +++ b/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 {}; diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td --- a/lld/COFF/Options.td +++ b/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">; diff --git a/lld/test/COFF/thinlto-obj-path.ll b/lld/test/COFF/thinlto-obj-path.ll new file mode 100644 --- /dev/null +++ b/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 +}