[LLD] [MinGW] Implement the -lto-sample-profile option (#85841)

This has been a supported option for ELF and is added to the COFF Linker
in #85701

GitOrigin-RevId: 276283d8641f13b6ecde736ab1a8720f742d9d02
diff --git a/MinGW/Driver.cpp b/MinGW/Driver.cpp
index efd643f..bb08c77 100644
--- a/MinGW/Driver.cpp
+++ b/MinGW/Driver.cpp
@@ -455,6 +455,8 @@
     add("-lldemit:llvm");
   if (args.hasArg(OPT_lto_emit_asm))
     add("-lldemit:asm");
+  if (auto *arg = args.getLastArg(OPT_lto_sample_profile))
+    add("-lto-sample-profile:" + StringRef(arg->getValue()));
 
   if (auto *a = args.getLastArg(OPT_thinlto_cache_dir))
     add("-lldltocache:" + StringRef(a->getValue()));
diff --git a/MinGW/Options.td b/MinGW/Options.td
index 9a0a96a..56f67e3 100644
--- a/MinGW/Options.td
+++ b/MinGW/Options.td
@@ -160,6 +160,8 @@
   HelpText<"Context sensitive profile file path">;
 def lto_emit_asm: FF<"lto-emit-asm">,
   HelpText<"Emit assembly code">;
+def lto_sample_profile: JJ<"lto-sample-profile=">,
+  HelpText<"Sample profile file path">;
 
 def thinlto_cache_dir: JJ<"thinlto-cache-dir=">,
   HelpText<"Path to ThinLTO cached object file directory">;
diff --git a/test/MinGW/driver.test b/test/MinGW/driver.test
index a4e9e5e..619fee8 100644
--- a/test/MinGW/driver.test
+++ b/test/MinGW/driver.test
@@ -422,6 +422,9 @@
 RUN: ld.lld -### foo.o -m i386pe -plugin-opt=emit-llvm 2>&1 | FileCheck -check-prefix=LTO_EMIT_LLVM %s
 LTO_EMIT_LLVM: -lldemit:llvm
 
+RUN: ld.lld -### foo.o -m i386pep --lto-sample-profile=foo 2>&1 | FileCheck -check-prefix=LTO_SAMPLE_PROFILE %s
+LTO_SAMPLE_PROFILE: -lto-sample-profile:foo
+
 Test GCC specific LTO options that GCC passes unconditionally, that we ignore.
 
 RUN: ld.lld -### foo.o -m i386pep -plugin /usr/lib/gcc/x86_64-w64-mingw32/10-posix/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-w64-mingw32/10-posix/lto-wrapper -plugin-opt=-fresolution=/tmp/ccM9d4fP.res -plugin-opt=-pass-through=-lmingw32 2> /dev/null