[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.
This commit is contained in:
tianleliu
2025-02-18 20:45:45 -08:00
committed by GitHub
parent 8187caf8e3
commit 6c39ee717f
2 changed files with 8 additions and 0 deletions

View File

@@ -232,6 +232,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
if (C.getDriver().isUsingLTO()) {
if (Arg *A = tools::getLastProfileSampleUseArg(Args))
CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") +
A->getValue()));
}
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
// Control Flow Guard checks

View File

@@ -71,3 +71,6 @@
// 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
// INFER-LLD: lld-link
// INFER-LLD-NOT: INFERASANLIBS
// 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
// CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"