Skip to content

Commit 6c39ee7

Browse files
authored
[Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile option (#127442)
In SPGO lto mode, linker needs -lto-sample-profile option to set sample profile file. Linux adds this option by transferring fprofile-sample-use to -plugin-opt=sample-profile=, which is alias of lto-sample-profile. (in clang\lib\Driver\ToolChains\CommonArgs.cpp: tools::addLTOOptions()). But clang on Windows misses the transferring. So add it now.
1 parent 8187caf commit 6c39ee7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/Driver/ToolChains/MSVC.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
232232
}
233233
}
234234

235+
if (C.getDriver().isUsingLTO()) {
236+
if (Arg *A = tools::getLastProfileSampleUseArg(Args))
237+
CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") +
238+
A->getValue()));
239+
}
235240
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
236241

237242
// Control Flow Guard checks

clang/test/Driver/cl-link.c

+3
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@
7171
// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
7272
// INFER-LLD: lld-link
7373
// INFER-LLD-NOT: INFERASANLIBS
74+
75+
// RUN: %clang_cl --target=x86_64-unknown-windows-msvc /Tc%s -flto -fuse-ld=lld -### -fprofile-sample-use=%S/Inputs/file.prof 2>&1 | FileCheck -check-prefix=CHECK-SAMPLE-PROFILE %s
76+
// CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"

0 commit comments

Comments
 (0)