Skip to content

Commit 05288f5

Browse files
committed
Merging r360674:
------------------------------------------------------------------------ r360674 | russell_gallop | 2019-05-14 07:01:40 -0700 (Tue, 14 May 2019) | 7 lines [Driver][Windows] Add dependent lib argument for profile instr generate This is needed so lld-link can find clang_rt.profile when self hosting on Windows with PGO. Using clang-cl as a linker knows to add the library but self hosting, using -DCMAKE_LINKER=<...>/lld-link.exe doesn't. Differential Revision: https://reviews.llvm.org/D61742 ------------------------------------------------------------------------ llvm-svn: 360828
1 parent bc6695c commit 05288f5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,9 @@ static void appendUserToPath(SmallVectorImpl<char> &Result) {
718718
Result.append(UID.begin(), UID.end());
719719
}
720720

721-
static void addPGOAndCoverageFlags(Compilation &C, const Driver &D,
722-
const InputInfo &Output, const ArgList &Args,
721+
static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
722+
const Driver &D, const InputInfo &Output,
723+
const ArgList &Args,
723724
ArgStringList &CmdArgs) {
724725

725726
auto *PGOGenerateArg = Args.getLastArg(options::OPT_fprofile_generate,
@@ -759,6 +760,11 @@ static void addPGOAndCoverageFlags(Compilation &C, const Driver &D,
759760
ProfileGenerateArg->getValue()));
760761
// The default is to use Clang Instrumentation.
761762
CmdArgs.push_back("-fprofile-instrument=clang");
763+
if (TC.getTriple().isWindowsMSVCEnvironment()) {
764+
// Add dependent lib for clang_rt.profile
765+
CmdArgs.push_back(Args.MakeArgString("--dependent-lib=" +
766+
TC.getCompilerRT(Args, "profile")));
767+
}
762768
}
763769

764770
if (PGOGenerateArg) {
@@ -4118,7 +4124,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41184124
// sampling, overhead of call arc collection is way too high and there's no
41194125
// way to collect the output.
41204126
if (!Triple.isNVPTX())
4121-
addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs);
4127+
addPGOAndCoverageFlags(TC, C, D, Output, Args, CmdArgs);
41224128

41234129
if (auto *ABICompatArg = Args.getLastArg(options::OPT_fclang_abi_compat_EQ))
41244130
ABICompatArg->render(Args, CmdArgs);

clang/test/Driver/cl-options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// RUN: %clang_cl -### /FA -fprofile-instr-generate=/tmp/somefile.profraw -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-FILE %s
6767
// RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s
6868
// RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use=file -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s
69-
// CHECK-PROFILE-GENERATE: "-fprofile-instrument=clang"
69+
// CHECK-PROFILE-GENERATE: "-fprofile-instrument=clang" "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
7070
// CHECK-PROFILE-GENERATE-FILE: "-fprofile-instrument-path=/tmp/somefile.profraw"
7171
// CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
7272

clang/test/Driver/instrprof-ld.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,17 @@
121121
//
122122
// CHECK-WINDOWS-X86-64: "{{.*}}link{{(.exe)?}}"
123123
// CHECK-WINDOWS-X86-64: "{{.*}}clang_rt.profile-x86_64.lib"
124+
125+
// Test instrumented profiling dependent-lib flags
126+
//
127+
// RUN: %clang %s -### -o %t.o -target x86_64-pc-win32 \
128+
// RUN: -fprofile-instr-generate 2>&1 \
129+
// RUN: | FileCheck --check-prefix=CHECK-WINDOWS-X86-64-DEPENDENT-LIB %s
130+
//
131+
// CHECK-WINDOWS-X86-64-DEPENDENT-LIB: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib"
132+
//
133+
// RUN: %clang %s -### -o %t.o -target x86_64-mingw32 \
134+
// RUN: -fprofile-instr-generate 2>&1 \
135+
// RUN: | FileCheck --check-prefix=CHECK-MINGW-X86-64-DEPENDENT-LIB %s
136+
//
137+
// CHECK-MINGW-X86-64-DEPENDENT-LIB-NOT: "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.a"

0 commit comments

Comments
 (0)