Skip to content

Commit 6d60e48

Browse files
committed
Forward Clang -mllvm options to remote compiler invocations
1 parent 7525a13 commit 6d60e48

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
549549
for (auto A : Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
550550
CmdArgs.push_back(
551551
Args.MakeArgString("-mllvm=-thinlto-distributor-arg=" + A));
552+
553+
for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
554+
CmdArgs.push_back(Args.MakeArgString(
555+
Twine("-mllvm=-thinlto-remote-compiler-arg=-mllvm=") +
556+
A->getValue(0)));
557+
}
552558
}
553559

554560
if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))

clang/test/Driver/DTLTO/dtlto.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: echo "--target=x86_64-linux-gnu \
66
// RUN: -Xthinlto-distributor=distarg1 \
77
// RUN: -Xthinlto-distributor=distarg2,distarg3 \
8+
// RUN: -mllvm llvm1 \
9+
// RUN: -mllvm=llvm2 \
810
// RUN: -fuse-ld=lld" > %t.rsp
911

1012

@@ -18,6 +20,8 @@
1820
// CHECK-SAME: "-mllvm=-thinlto-distributor-arg=distarg1"
1921
// CHECK-SAME: "-mllvm=-thinlto-distributor-arg=distarg2"
2022
// CHECK-SAME: "-mllvm=-thinlto-distributor-arg=distarg3"
23+
// CHECK-SAME: "-mllvm=-thinlto-remote-compiler-arg=-mllvm=llvm1"
24+
// CHECK-SAME: "-mllvm=-thinlto-remote-compiler-arg=-mllvm=llvm2"
2125

2226

2327
/// Check that options are not added without --thinlto-distributor= and

cross-project-tests/dtlto/mllvm.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// Test that -mllvm options are forwarded to the remote compiler for DTLTO.
2+
3+
// RUN: rm -rf %t && mkdir %t && cd %t
4+
5+
// RUN: %clang --target=x86_64-linux-gnu %s -shared -flto=thin \
6+
// RUN: -fthinlto-distributor=%python \
7+
// RUN: -Xthinlto-distributor=%llvm_src_root/utils/dtlto/local.py \
8+
// RUN: -fuse-ld=lld \
9+
// RUN: -nostdlib \
10+
// RUN: -Werror \
11+
/// Specify -v for both the inital and remote clang invocations.
12+
// RUN: -v \
13+
// RUN: -Wl,-mllvm=-thinlto-remote-compiler-arg=-v \
14+
/// -thinlto-remote-compiler-arg is a safe -mllvm option to use for this test as
15+
/// it is part of the DTLTO implemenation.
16+
// RUN: -mllvm -thinlto-remote-compiler-arg=llvm1 \
17+
// RUN: -mllvm=-thinlto-remote-compiler-arg=llvm2 \
18+
// RUN: 2>&1 | FileCheck %s
19+
20+
// -mllvm arguments are forwarded to `clang -cc1`.
21+
// CHECK: -mllvm -thinlto-remote-compiler-arg=llvm1
22+
// CHECK-SAME: -mllvm -thinlto-remote-compiler-arg=llvm2
23+
24+
// -mllvm arguments are forwarded to the remote compiler via lld.
25+
// CHECK: -mllvm=-thinlto-remote-compiler-arg=-mllvm=-thinlto-remote-compiler-arg=llvm1
26+
// CHECK-SAME: -mllvm=-thinlto-remote-compiler-arg=-mllvm=-thinlto-remote-compiler-arg=llvm2
27+
28+
// -mllvm arguments are forwarded to `clang -cc1` in the remote execution.
29+
// CHECK: -mllvm -thinlto-remote-compiler-arg=llvm1
30+
// CHECK-SAME: -mllvm -thinlto-remote-compiler-arg=llvm2
31+
32+
33+
int _start() { return 0; }

0 commit comments

Comments
 (0)