Skip to content

Commit 5375b94

Browse files
committed
[lld-link] implement -lto-obj-path
Summary: This adds the -lto-obj-path option to 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. Reviewers: ruiu, tejohnson, pcc, rnk Reviewed By: ruiu, rnk Subscribers: mehdi_amini, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65964 llvm-svn: 369559
1 parent 969b3e6 commit 5375b94

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

lld/COFF/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ struct Configuration {
190190
// Used for /thinlto-object-suffix-replace:
191191
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
192192

193+
// Used for /lto-obj-path:
194+
llvm::StringRef ltoObjPath;
195+
193196
uint64_t align = 4096;
194197
uint64_t imageBase = -1;
195198
uint64_t fileAlign = 512;

lld/COFF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
14751475
getOldNewOptions(args, OPT_thinlto_prefix_replace);
14761476
config->thinLTOObjectSuffixReplace =
14771477
getOldNewOptions(args, OPT_thinlto_object_suffix_replace);
1478+
config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);
14781479
// Handle miscellaneous boolean flags.
14791480
config->allowBind = args.hasFlag(OPT_allowbind, OPT_allowbind_no, true);
14801481
config->allowIsolation =

lld/COFF/LTO.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ std::vector<StringRef> BitcodeCompiler::compile() {
177177
// files. After that, we exit from linker and ThinLTO backend runs in a
178178
// distributed environment.
179179
if (config->thinLTOIndexOnly) {
180+
if (!config->ltoObjPath.empty())
181+
saveBuffer(buf[0], config->ltoObjPath);
180182
if (indexFile)
181183
indexFile->close();
182184
return {};

lld/COFF/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def thinlto_object_suffix_replace : P<
191191
def thinlto_prefix_replace: P<
192192
"thinlto-prefix-replace",
193193
"'old;new' replace old prefix with new prefix in ThinLTO outputs">;
194+
def lto_obj_path : P<
195+
"lto-obj-path",
196+
"output native object for merged LTO unit to this path">;
194197
def dash_dash_version : Flag<["--"], "version">,
195198
HelpText<"Print version information">;
196199
defm threads: B<"threads",

lld/test/COFF/lto-obj-path.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; REQUIRES: x86
2+
3+
; Test to ensure that thinlto-index-only with lto-obj-path creates
4+
; the native object file.
5+
; RUN: opt -module-summary %s -o %t1.obj
6+
; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.obj
7+
; RUN: rm -f %t4.obj
8+
; RUN: lld-link -thinlto-index-only -lto-obj-path:%t4.obj -out:t3.exe \
9+
; RUN: -entry:main %t1.obj %t2.obj
10+
; RUN: llvm-readobj -h %t4.obj | FileCheck %s
11+
; RUN: llvm-nm %t4.obj 2>&1 | FileCheck %s -check-prefix=SYMBOLS
12+
; RUN: llvm-nm %t4.obj 2>&1 | count 1
13+
14+
; CHECK: Format: COFF-x86-64
15+
; SYMBOLS: @feat.00
16+
17+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
18+
target triple = "x86_64-pc-windows-msvc19.0.24215"
19+
20+
declare void @g(...)
21+
22+
define void @main() {
23+
call void (...) @g()
24+
ret void
25+
}

0 commit comments

Comments
 (0)