Skip to content

Commit 73fd9d3

Browse files
itfteresajohnson
authored andcommitted
[lld] Support separate native object file path in --thinlto-prefix-replace
Currently, the --thinlto-prefix-replace="oldpath;newpath" option is used during distributed ThinLTO thin links to specify the mapping of the input bitcode object files' directory tree (oldpath) to the directory tree (newpath) used for both: 1) the output files of the thin link itself (the .thinlto.bc index files and the optional .imports files) 2) the specified object file paths written to the response file given in the --thinlto-index-only=${response} option, which is used by the final native link and must match the paths of the native object files that will be produced by ThinLTO backend compiles. This patch expands the --thinlto-prefix-replace option to allow a separate directory tree mapping to be specified for the object file paths written to the response file (number 2 above). This is important to support builds and build systems where the same output directory may not be written by multiple build actions (e.g. the thin link and the ThinLTO backend compiles). The new format is: --thinlto-prefix-replace="origpath;outpath[;objpath]" This replaces the origpath directory tree of the thin link input files with outpath when writing the thin link index and imports outputs (number 1 above). If objpath is specified it replaces origpath of the input files with objpath when writing the response file (number 2 above), otherwise it falls back to the old behavior of using outpath for this as well. Reviewed By: tejohnson, MaskRay Differential Revision: https://reviews.llvm.org/D144596
1 parent a401e10 commit 73fd9d3

File tree

16 files changed

+272
-39
lines changed

16 files changed

+272
-39
lines changed

lld/COFF/Config.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,16 @@ struct Configuration {
218218
// Used for /thinlto-index-only:
219219
llvm::StringRef thinLTOIndexOnlyArg;
220220

221-
// Used for /thinlto-object-prefix-replace:
222-
std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
221+
// Used for /thinlto-prefix-replace:
222+
// Replace the prefix in paths generated for ThinLTO, replacing
223+
// thinLTOPrefixReplaceOld with thinLTOPrefixReplaceNew. If
224+
// thinLTOPrefixReplaceNativeObject is defined, replace the prefix of object
225+
// file paths written to the response file given in the
226+
// --thinlto-index-only=${response} option with
227+
// thinLTOPrefixReplaceNativeObject, instead of thinLTOPrefixReplaceNew.
228+
llvm::StringRef thinLTOPrefixReplaceOld;
229+
llvm::StringRef thinLTOPrefixReplaceNew;
230+
llvm::StringRef thinLTOPrefixReplaceNativeObject;
223231

224232
// Used for /thinlto-object-suffix-replace:
225233
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;

lld/COFF/Driver.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <future>
5454
#include <memory>
5555
#include <optional>
56+
#include <tuple>
5657

5758
using namespace llvm;
5859
using namespace llvm::object;
@@ -90,6 +91,14 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
9091
return ret;
9192
}
9293

94+
// Parse options of the form "old;new[;extra]".
95+
static std::tuple<StringRef, StringRef, StringRef>
96+
getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
97+
auto [oldDir, second] = getOldNewOptions(args, id);
98+
auto [newDir, extraDir] = second.split(';');
99+
return {oldDir, newDir, extraDir};
100+
}
101+
93102
// Drop directory components and replace extension with
94103
// ".exe", ".dll" or ".sys".
95104
static std::string getOutputPath(StringRef path, bool isDll, bool isDriver) {
@@ -1884,8 +1893,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18841893
args.hasArg(OPT_thinlto_index_only_arg);
18851894
config->thinLTOIndexOnlyArg =
18861895
args.getLastArgValue(OPT_thinlto_index_only_arg);
1887-
config->thinLTOPrefixReplace =
1888-
getOldNewOptions(args, OPT_thinlto_prefix_replace);
1896+
std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
1897+
config->thinLTOPrefixReplaceNativeObject) =
1898+
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace);
18891899
config->thinLTOObjectSuffixReplace =
18901900
getOldNewOptions(args, OPT_thinlto_object_suffix_replace);
18911901
config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);

lld/COFF/LTO.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {
5656

5757
std::string BitcodeCompiler::getThinLTOOutputFile(StringRef path) {
5858
return lto::getThinLTOOutputFile(
59-
std::string(path), std::string(ctx.config.thinLTOPrefixReplace.first),
60-
std::string(ctx.config.thinLTOPrefixReplace.second));
59+
std::string(path), std::string(ctx.config.thinLTOPrefixReplaceOld),
60+
std::string(ctx.config.thinLTOPrefixReplaceNew));
6161
}
6262

6363
lto::Config BitcodeCompiler::createConfig() {
@@ -114,8 +114,9 @@ BitcodeCompiler::BitcodeCompiler(COFFLinkerContext &c) : ctx(c) {
114114
if (ctx.config.thinLTOIndexOnly) {
115115
auto OnIndexWrite = [&](StringRef S) { thinIndices.erase(S); };
116116
backend = lto::createWriteIndexesThinBackend(
117-
std::string(ctx.config.thinLTOPrefixReplace.first),
118-
std::string(ctx.config.thinLTOPrefixReplace.second),
117+
std::string(ctx.config.thinLTOPrefixReplaceOld),
118+
std::string(ctx.config.thinLTOPrefixReplaceNew),
119+
std::string(ctx.config.thinLTOPrefixReplaceNativeObject),
119120
ctx.config.thinLTOEmitImportsFiles, indexFile.get(), OnIndexWrite);
120121
} else {
121122
backend = lto::createInProcessThinBackend(

lld/ELF/Config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ struct Config {
177177
StringRef zCetReport = "none";
178178
llvm::StringRef ltoBasicBlockSections;
179179
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
180-
std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
180+
llvm::StringRef thinLTOPrefixReplaceOld;
181+
llvm::StringRef thinLTOPrefixReplaceNew;
182+
llvm::StringRef thinLTOPrefixReplaceNativeObject;
181183
std::string rpath;
182184
llvm::SmallVector<VersionDefinition, 0> versionDefinitions;
183185
llvm::SmallVector<llvm::StringRef, 0> auxiliaryList;

lld/ELF/Driver.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "llvm/Support/TimeProfiler.h"
6666
#include "llvm/Support/raw_ostream.h"
6767
#include <cstdlib>
68+
#include <tuple>
6869
#include <utility>
6970

7071
using namespace llvm;
@@ -1023,6 +1024,14 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
10231024
return ret;
10241025
}
10251026

1027+
// Parse options of the form "old;new[;extra]".
1028+
static std::tuple<StringRef, StringRef, StringRef>
1029+
getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
1030+
auto [oldDir, second] = getOldNewOptions(args, id);
1031+
auto [newDir, extraDir] = second.split(';');
1032+
return {oldDir, newDir, extraDir};
1033+
}
1034+
10261035
// Parse the symbol ordering file and warn for any duplicate entries.
10271036
static SmallVector<StringRef, 0> getSymbolOrderingFile(MemoryBufferRef mb) {
10281037
SetVector<StringRef, SmallVector<StringRef, 0>> names;
@@ -1249,8 +1258,9 @@ static void readConfigs(opt::InputArgList &args) {
12491258
config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
12501259
config->thinLTOObjectSuffixReplace =
12511260
getOldNewOptions(args, OPT_thinlto_object_suffix_replace_eq);
1252-
config->thinLTOPrefixReplace =
1253-
getOldNewOptions(args, OPT_thinlto_prefix_replace_eq);
1261+
std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
1262+
config->thinLTOPrefixReplaceNativeObject) =
1263+
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace_eq);
12541264
if (config->thinLTOEmitIndexFiles && !config->thinLTOIndexOnly) {
12551265
if (args.hasArg(OPT_thinlto_object_suffix_replace_eq))
12561266
error("--thinlto-object-suffix-replace is not supported with "
@@ -1259,6 +1269,11 @@ static void readConfigs(opt::InputArgList &args) {
12591269
error("--thinlto-prefix-replace is not supported with "
12601270
"--thinlto-emit-index-files");
12611271
}
1272+
if (!config->thinLTOPrefixReplaceNativeObject.empty() &&
1273+
config->thinLTOIndexOnlyArg.empty()) {
1274+
error("--thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with "
1275+
"--thinlto-index-only=");
1276+
}
12621277
config->thinLTOModulesToCompile =
12631278
args::getStrings(args, OPT_thinlto_single_module_eq);
12641279
config->timeTraceEnabled = args.hasArg(OPT_time_trace_eq);

lld/ELF/LTO.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static std::unique_ptr<raw_fd_ostream> openLTOOutputFile(StringRef file) {
6868

6969
static std::string getThinLTOOutputFile(StringRef modulePath) {
7070
return lto::getThinLTOOutputFile(
71-
std::string(modulePath), std::string(config->thinLTOPrefixReplace.first),
72-
std::string(config->thinLTOPrefixReplace.second));
71+
std::string(modulePath), std::string(config->thinLTOPrefixReplaceOld),
72+
std::string(config->thinLTOPrefixReplaceNew));
7373
}
7474

7575
static lto::Config createConfig() {
@@ -196,8 +196,9 @@ BitcodeCompiler::BitcodeCompiler() {
196196
auto onIndexWrite = [&](StringRef s) { thinIndices.erase(s); };
197197
if (config->thinLTOIndexOnly) {
198198
backend = lto::createWriteIndexesThinBackend(
199-
std::string(config->thinLTOPrefixReplace.first),
200-
std::string(config->thinLTOPrefixReplace.second),
199+
std::string(config->thinLTOPrefixReplaceOld),
200+
std::string(config->thinLTOPrefixReplaceNew),
201+
std::string(config->thinLTOPrefixReplaceNativeObject),
201202
config->thinLTOEmitImportsFiles, indexFile.get(), onIndexWrite);
202203
} else {
203204
backend = lto::createInProcessThinBackend(

lld/MachO/Config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ struct Configuration {
173173
llvm::StringRef thinLTOCacheDir;
174174
llvm::StringRef thinLTOIndexOnlyArg;
175175
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
176-
std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
176+
llvm::StringRef thinLTOPrefixReplaceOld;
177+
llvm::StringRef thinLTOPrefixReplaceNew;
178+
llvm::StringRef thinLTOPrefixReplaceNativeObject;
177179
bool deadStripDylibs = false;
178180
bool demangle = false;
179181
bool deadStrip = false;

lld/MachO/Driver.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,14 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
868868
return ret;
869869
}
870870

871+
// Parse options of the form "old;new[;extra]".
872+
static std::tuple<StringRef, StringRef, StringRef>
873+
getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
874+
auto [oldDir, second] = getOldNewOptions(args, id);
875+
auto [newDir, extraDir] = second.split(';');
876+
return {oldDir, newDir, extraDir};
877+
}
878+
871879
static void parseClangOption(StringRef opt, const Twine &msg) {
872880
std::string err;
873881
raw_string_ostream os(err);
@@ -1578,8 +1586,9 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
15781586
config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
15791587
config->thinLTOObjectSuffixReplace =
15801588
getOldNewOptions(args, OPT_thinlto_object_suffix_replace_eq);
1581-
config->thinLTOPrefixReplace =
1582-
getOldNewOptions(args, OPT_thinlto_prefix_replace_eq);
1589+
std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
1590+
config->thinLTOPrefixReplaceNativeObject) =
1591+
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace_eq);
15831592
if (config->thinLTOEmitIndexFiles && !config->thinLTOIndexOnly) {
15841593
if (args.hasArg(OPT_thinlto_object_suffix_replace_eq))
15851594
error("--thinlto-object-suffix-replace is not supported with "
@@ -1588,6 +1597,11 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
15881597
error("--thinlto-prefix-replace is not supported with "
15891598
"--thinlto-emit-index-files");
15901599
}
1600+
if (!config->thinLTOPrefixReplaceNativeObject.empty() &&
1601+
config->thinLTOIndexOnlyArg.empty()) {
1602+
error("--thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with "
1603+
"--thinlto-index-only=");
1604+
}
15911605
config->runtimePaths = args::getStrings(args, OPT_rpath);
15921606
config->allLoad = args.hasFlag(OPT_all_load, OPT_noall_load, false);
15931607
config->archMultiple = args.hasArg(OPT_arch_multiple);

lld/MachO/LTO.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {
4747

4848
static std::string getThinLTOOutputFile(StringRef modulePath) {
4949
return lto::getThinLTOOutputFile(
50-
std::string(modulePath), std::string(config->thinLTOPrefixReplace.first),
51-
std::string(config->thinLTOPrefixReplace.second));
50+
std::string(modulePath), std::string(config->thinLTOPrefixReplaceOld),
51+
std::string(config->thinLTOPrefixReplaceNew));
5252
}
5353

5454
static lto::Config createConfig() {
@@ -99,8 +99,9 @@ BitcodeCompiler::BitcodeCompiler() {
9999
auto onIndexWrite = [&](StringRef S) { thinIndices.erase(S); };
100100
if (config->thinLTOIndexOnly) {
101101
backend = lto::createWriteIndexesThinBackend(
102-
std::string(config->thinLTOPrefixReplace.first),
103-
std::string(config->thinLTOPrefixReplace.second),
102+
std::string(config->thinLTOPrefixReplaceOld),
103+
std::string(config->thinLTOPrefixReplaceNew),
104+
std::string(config->thinLTOPrefixReplaceNativeObject),
104105
config->thinLTOEmitImportsFiles, indexFile.get(), onIndexWrite);
105106
} else {
106107
backend = lto::createInProcessThinBackend(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; REQUIRES: x86
2+
; RUN: rm -rf %t && mkdir %t
3+
; RUN: mkdir -p %t/old/subdir
4+
; RUN: opt -module-summary %s -o %t/old/subdir/1.obj
5+
; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t/old/subdir/2.obj
6+
; RUN: opt -module-summary %p/Inputs/thinlto-empty.ll -o %t/old/3.obj
7+
8+
;; Ensure lld writes linked files to linked objects file.
9+
; RUN: lld-link -entry:main -thinlto-index-only:%t/1.txt %t/old/subdir/1.obj %t/old/subdir/2.obj %t/old/3.obj -out:%t/t.exe
10+
; RUN: ls %t/old/subdir/1.obj.thinlto.bc
11+
; RUN: ls %t/old/subdir/2.obj.thinlto.bc
12+
; RUN: ls %t/old/3.obj.thinlto.bc
13+
; RUN: FileCheck --check-prefix=CHECK-NO-REPLACE %s < %t/1.txt
14+
; CHECK-NO-REPLACE: old/subdir/1.obj
15+
; CHECK-NO-REPLACE-NEXT: old/subdir/2.obj
16+
; CHECK-NO-REPLACE-NEXT: old/3.obj
17+
18+
;; Check that this also works with thinlto-prefix-replace.
19+
; RUN: lld-link -entry:main -thinlto-index-only:%t/2.txt -thinlto-prefix-replace:"%t/old/;%t/new/" %t/old/subdir/1.obj %t/old/subdir/2.obj %t/old/3.obj -out:%t/t.exe
20+
; RUN: ls %t/new/subdir/1.obj.thinlto.bc
21+
; RUN: ls %t/new/subdir/2.obj.thinlto.bc
22+
; RUN: ls %t/new/3.obj.thinlto.bc
23+
; RUN: FileCheck --check-prefix=CHECK-REPLACE-PREFIX %s < %t/2.txt
24+
; CHECK-REPLACE-PREFIX: new/subdir/1.obj
25+
; CHECK-REPLACE-PREFIX-NEXT: new/subdir/2.obj
26+
; CHECK-REPLACE-PREFIX-NEXT: new/3.obj
27+
28+
;; Check that this also works with replacing the prefix of linked objects.
29+
; RUN: lld-link -entry:main -thinlto-index-only:%t/3.txt -thinlto-prefix-replace:"%t/old/;%t/new/;%t/obj/" %t/old/subdir/1.obj %t/old/subdir/2.obj %t/old/3.obj -out:%t/t.exe
30+
; RUN: ls %t/new/subdir/1.obj.thinlto.bc
31+
; RUN: ls %t/new/subdir/2.obj.thinlto.bc
32+
; RUN: ls %t/new/3.obj.thinlto.bc
33+
; RUN: FileCheck --check-prefix=CHECK-REPLACE-OBJECT-PREFIX %s < %t/3.txt
34+
; CHECK-REPLACE-OBJECT-PREFIX: obj/subdir/1.obj
35+
; CHECK-REPLACE-OBJECT-PREFIX-NEXT: obj/subdir/2.obj
36+
; CHECK-REPLACE-OBJECT-PREFIX-NEXT: obj/3.obj
37+
38+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
39+
target triple = "x86_64-pc-windows-msvc19.0.24215"
40+
41+
declare void @g(...)
42+
43+
define void @main() {
44+
call void (...) @g()
45+
ret void
46+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; REQUIRES: x86
2+
; RUN: rm -rf %t && mkdir %t && cd %t
3+
; RUN: mkdir -p old/subdir
4+
; RUN: opt -module-summary %s -o old/subdir/1.o
5+
; RUN: opt -module-summary %p/Inputs/thinlto.ll -o old/subdir/2.o
6+
; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o old/3.o
7+
8+
;; Ensure lld writes linked files to linked objects file.
9+
; RUN: ld.lld --thinlto-index-only=1.txt -shared old/subdir/1.o old/subdir/2.o old/3.o -o /dev/null
10+
; RUN: ls old/subdir/1.o.thinlto.bc
11+
; RUN: ls old/subdir/2.o.thinlto.bc
12+
; RUN: ls old/3.o.thinlto.bc
13+
; RUN: FileCheck --match-full-lines --check-prefix=CHECK-NO-REPLACE %s < 1.txt
14+
; CHECK-NO-REPLACE: old/subdir/1.o
15+
; CHECK-NO-REPLACE-NEXT: old/subdir/2.o
16+
; CHECK-NO-REPLACE-NEXT: old/3.o
17+
18+
;; Check that this also works with thinlto-prefix-replace.
19+
; RUN: ld.lld --thinlto-index-only=2.txt --thinlto-prefix-replace="old/;new/" -shared old/subdir/1.o old/subdir/2.o old/3.o -o /dev/null
20+
; RUN: ls new/subdir/1.o.thinlto.bc
21+
; RUN: ls new/subdir/2.o.thinlto.bc
22+
; RUN: ls new/3.o.thinlto.bc
23+
; RUN: FileCheck --match-full-lines --check-prefix=CHECK-REPLACE-PREFIX %s < 2.txt
24+
; CHECK-REPLACE-PREFIX: new/subdir/1.o
25+
; CHECK-REPLACE-PREFIX-NEXT: new/subdir/2.o
26+
; CHECK-REPLACE-PREFIX-NEXT: new/3.o
27+
28+
;; Check that this also works with replacing the prefix of linked objects.
29+
; RUN: ld.lld --thinlto-index-only=3.txt --thinlto-prefix-replace="old/;new/;obj/" -shared old/subdir/1.o old/subdir/2.o old/3.o -o /dev/null
30+
; RUN: ls new/subdir/1.o.thinlto.bc
31+
; RUN: ls new/subdir/2.o.thinlto.bc
32+
; RUN: ls new/3.o.thinlto.bc
33+
; RUN: FileCheck --match-full-lines --check-prefix=CHECK-REPLACE-OBJECT-PREFIX %s < 3.txt
34+
; CHECK-REPLACE-OBJECT-PREFIX: obj/subdir/1.o
35+
; CHECK-REPLACE-OBJECT-PREFIX-NEXT: obj/subdir/2.o
36+
; CHECK-REPLACE-OBJECT-PREFIX-NEXT: obj/3.o
37+
38+
; Create an error if prefix replace option have 'old;new;obj' format but index file is not set. Ensure that the error is about thinlto-prefix-replace.
39+
; RUN: not ld.lld --thinlto-prefix-replace="old/;new/;obj/" -shared old/subdir/1.o old/subdir/2.o old/3.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERROR
40+
; ERROR: error: --thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with --thinlto-index-only=
41+
42+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
43+
target triple = "x86_64-unknown-linux-gnu"
44+
45+
declare void @g(...)
46+
47+
define void @f() {
48+
entry:
49+
call void (...) @g()
50+
ret void
51+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; REQUIRES: x86
2+
; RUN: rm -rf %t && split-file %s %t
3+
; RUN: mkdir -p %t/old/subdir
4+
5+
; RUN: opt -module-summary %t/f.ll -o %t/old/subdir/1.o
6+
; RUN: opt -module-summary %t/g.ll -o %t/old/subdir/2.o
7+
; RUN: opt -module-summary %t/empty.ll -o %t/old/3.o
8+
9+
;; Ensure lld writes linked files to linked objects file.
10+
; RUN: %lld --thinlto-index-only=%t/1.txt -dylib %t/old/subdir/1.o %t/old/subdir/2.o %t/old/3.o -o /dev/null
11+
; RUN: ls %t/old/subdir/1.o.thinlto.bc
12+
; RUN: ls %t/old/subdir/2.o.thinlto.bc
13+
; RUN: ls %t/old/3.o.thinlto.bc
14+
; RUN: FileCheck --check-prefix=CHECK-NO-REPLACE %s < %t/1.txt
15+
; CHECK-NO-REPLACE: old/subdir/1.o
16+
; CHECK-NO-REPLACE-NEXT: old/subdir/2.o
17+
; CHECK-NO-REPLACE-NEXT: old/3.o
18+
19+
;; Check that this also works with thinlto-prefix-replace.
20+
; RUN: %lld --thinlto-index-only=%t/2.txt --thinlto-prefix-replace="%t/old/;%t/new/" -dylib %t/old/subdir/1.o %t/old/subdir/2.o %t/old/3.o -o /dev/null
21+
; RUN: ls %t/new/subdir/1.o.thinlto.bc
22+
; RUN: ls %t/new/subdir/2.o.thinlto.bc
23+
; RUN: ls %t/new/3.o.thinlto.bc
24+
; RUN: FileCheck --check-prefix=CHECK-REPLACE-PREFIX %s < %t/2.txt
25+
; CHECK-REPLACE-PREFIX: new/subdir/1.o
26+
; CHECK-REPLACE-PREFIX-NEXT: new/subdir/2.o
27+
; CHECK-REPLACE-PREFIX-NEXT: new/3.o
28+
29+
30+
;; Check that this also works with replacing the prefix of linked objects.
31+
; RUN: %lld --thinlto-index-only=%t/3.txt --thinlto-prefix-replace="%t/old/;%t/new/;%t/obj/" -dylib %t/old/subdir/1.o %t/old/subdir/2.o %t/old/3.o -o /dev/null
32+
; RUN: ls %t/new/subdir/1.o.thinlto.bc
33+
; RUN: ls %t/new/subdir/2.o.thinlto.bc
34+
; RUN: ls %t/new/3.o.thinlto.bc
35+
; RUN: FileCheck --check-prefix=CHECK-REPLACE-OBJECT-PREFIX %s < %t/3.txt
36+
; CHECK-REPLACE-OBJECT-PREFIX: obj/subdir/1.o
37+
; CHECK-REPLACE-OBJECT-PREFIX-NEXT: obj/subdir/2.o
38+
; CHECK-REPLACE-OBJECT-PREFIX-NEXT: obj/3.o
39+
40+
; Create an error if prefix replace option have 'old;new;obj' format but index file is not set. Ensure that the error is about thinlto-prefix-replace.
41+
; RUN: not %lld --thinlto-prefix-replace="%t/old/;%t/new/;%t/obj/" -dylib %t/old/subdir/1.o %t/old/subdir/2.o %t/old/3.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERROR
42+
; ERROR: error: --thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with --thinlto-index-only=
43+
44+
;--- f.ll
45+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
46+
target triple = "x86_64-apple-darwin"
47+
48+
declare void @g(...)
49+
50+
define void @f() {
51+
entry:
52+
call void (...) @g()
53+
ret void
54+
}
55+
56+
;--- g.ll
57+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
58+
target triple = "x86_64-apple-darwin"
59+
60+
define void @g() {
61+
entry:
62+
ret void
63+
}
64+
65+
;--- empty.ll
66+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
67+
target triple = "x86_64-apple-darwin"

0 commit comments

Comments
 (0)