[clang] f97b61e - [Driver][MSVC] Support DWARF fission when using LTO on Windows
Haohai Wen via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 6 07:19:25 PDT 2023
Author: Haohai Wen
Date: 2023-07-06T22:18:58+08:00
New Revision: f97b61ed27aa6b0cef21e86e71d683feab32ce34
URL: https://github.com/llvm/llvm-project/commit/f97b61ed27aa6b0cef21e86e71d683feab32ce34
DIFF: https://github.com/llvm/llvm-project/commit/f97b61ed27aa6b0cef21e86e71d683feab32ce34.diff
LOG: [Driver][MSVC] Support DWARF fission when using LTO on Windows
D154070 has added /dwodir to lld/COFF to tells LTO backend to create dwo
directory and files. This patch makes clang to emit /dwodir to lld when
user specify -gsplit-dwarf with LTO. This behavior is simiar to DWARF
fission with LTO for ELF.
A simple use case:
$clang-cl -c -flto -gdwarf main.c -o main.o
$clang-cl -c -flto -gdwarf a.c -o a.o
$clang-cl -flto -fuse-ld=lld -gdwarf -gsplit-dwarf main.o a.o
This'll generate a dwo file: main.exe_dwo/0.dwo
Reviewed By: mstorsjo, MaskRay, hans
Differential Revision: https://reviews.llvm.org/D154295
Added:
Modified:
clang/lib/Driver/ToolChains/MSVC.cpp
clang/test/Driver/lto-dwo.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index 6b2eaef1f2e7d1..4a6989d113f82b 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -277,11 +277,18 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
else if (Linker.equals_insensitive("lld"))
Linker = "lld-link";
- if (Linker == "lld-link")
+ if (Linker == "lld-link") {
for (Arg *A : Args.filtered(options::OPT_vfsoverlay))
CmdArgs.push_back(
Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue()));
+ if (C.getDriver().isUsingLTO() &&
+ Args.hasFlag(options::OPT_gsplit_dwarf, options::OPT_gno_split_dwarf,
+ false))
+ CmdArgs.push_back(Args.MakeArgString(Twine("/dwodir:") +
+ Output.getFilename() + "_dwo"));
+ }
+
// Add filenames, libraries, and other linker inputs.
for (const auto &Input : Inputs) {
if (Input.isFilename()) {
diff --git a/clang/test/Driver/lto-dwo.c b/clang/test/Driver/lto-dwo.c
index 0bac5f25d4daac..206d4cba7f2a92 100644
--- a/clang/test/Driver/lto-dwo.c
+++ b/clang/test/Driver/lto-dwo.c
@@ -1,6 +1,9 @@
// Confirm that -gsplit-dwarf=DIR is passed to linker
// RUN: %clang --target=x86_64-unknown-linux -### %s -flto=thin -gsplit-dwarf -o a.out 2> %t
-// RUN: FileCheck -check-prefix=CHECK-LINK-DWO-DIR-DEFAULT < %t %s
+// RUN: FileCheck -check-prefix=CHECK-LINK-ELF-DWO-DIR-DEFAULT < %t %s
+// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -### -fuse-ld=lld -flto -gsplit-dwarf -o a.out -- %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-COFF-DWO-DIR-DEFAULT < %t %s
//
-// CHECK-LINK-DWO-DIR-DEFAULT: "-plugin-opt=dwo_dir=a.out_dwo"
+// CHECK-LINK-ELF-DWO-DIR-DEFAULT: "-plugin-opt=dwo_dir=a.out_dwo"
+// CHECK-LINK-COFF-DWO-DIR-DEFAULT: "/dwodir:a.out_dwo"
More information about the cfe-commits
mailing list