Author: tianleliu Date: 2025-02-19T12:45:45+08:00 New Revision: 6c39ee717f03a0fe28f563d525fa5aff09804ba8
URL: https://github.com/llvm/llvm-project/commit/6c39ee717f03a0fe28f563d525fa5aff09804ba8 DIFF: https://github.com/llvm/llvm-project/commit/6c39ee717f03a0fe28f563d525fa5aff09804ba8.diff LOG: [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. Added: Modified: clang/lib/Driver/ToolChains/MSVC.cpp clang/test/Driver/cl-link.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index bae41fc06c036..d5a7fc7e85230 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -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 diff --git a/clang/test/Driver/cl-link.c b/clang/test/Driver/cl-link.c index 9bf8a8137926d..726bc26a64edd 100644 --- a/clang/test/Driver/cl-link.c +++ b/clang/test/Driver/cl-link.c @@ -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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits