[lld] 2a631a8 - [lld/COFF] Add /dwodir to enable DWARF fission with LTO

Haohai Wen via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 30 17:59:26 PDT 2023


Author: Haohai Wen
Date: 2023-07-01T08:59:12+08:00
New Revision: 2a631a8fedc21eae9568feb69d405800fa9648e5

URL: https://github.com/llvm/llvm-project/commit/2a631a8fedc21eae9568feb69d405800fa9648e5
DIFF: https://github.com/llvm/llvm-project/commit/2a631a8fedc21eae9568feb69d405800fa9648e5.diff

LOG: [lld/COFF] Add /dwodir to enable DWARF fission with LTO

This patch added /dwodir to lld/COFF which is equivalent to lld/ELF
option -plugin-opt=dwo_dir=. This option tells LTO backend to create
dwo directory and files and all dwo files will be in it. Otherwise all
dwarf sections will be embeded into image even if -gsplit-dwarf is
specified when using LTO.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D154070

Added: 
    lld/test/COFF/lto-debug-fission.ll

Modified: 
    lld/COFF/Config.h
    lld/COFF/Driver.cpp
    lld/COFF/LTO.cpp
    lld/COFF/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 3925238d269339..7d5b664599b549 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -203,6 +203,9 @@ struct Configuration {
   StringRef manifestUIAccess = "'false'";
   StringRef manifestFile;
 
+  // used for /dwodir
+  StringRef dwoDir;
+
   // Used for /aligncomm.
   std::map<std::string, int> alignComm;
 

diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index f8e2c17099c0c8..15a14981a36a28 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1910,6 +1910,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
     fatal("/manifestinput: requires /manifest:embed");
   }
 
+  // Handle /dwodir
+  config->dwoDir = args.getLastArgValue(OPT_dwodir);
+
   config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
   config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
                              args.hasArg(OPT_thinlto_index_only_arg);

diff  --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index cca14be0fc2b4b..67f5a62920e98e 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -84,6 +84,7 @@ lto::Config BitcodeCompiler::createConfig() {
   c.DisableVerify = true;
 #endif
   c.DiagHandler = diagnosticHandler;
+  c.DwoDir = ctx.config.dwoDir.str();
   c.OptLevel = ctx.config.ltoo;
   c.CPU = getCPUStr();
   c.MAttrs = getMAttrs();

diff  --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index 2a89509be5fe02..f7d9eeb7e7250e 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -42,6 +42,8 @@ def color_diagnostics_eq: Joined<["--"], "color-diagnostics=">,
 def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
 def delayload : P<"delayload", "Delay loaded DLL name">;
 def diasdkdir : P<"diasdkdir", "Set the location of the DIA SDK">;
+def dwodir : P<"dwodir",
+    "Directory to store .dwo files when LTO and debug fission are used">;
 def entry   : P<"entry", "Name of entry point symbol">;
 def errorlimit : P<"errorlimit",
     "Maximum number of errors to emit before stopping (0 = no limit)">;

diff  --git a/lld/test/COFF/lto-debug-fission.ll b/lld/test/COFF/lto-debug-fission.ll
new file mode 100644
index 00000000000000..1389624b58678e
--- /dev/null
+++ b/lld/test/COFF/lto-debug-fission.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; RUN: opt %s -o %t1.o
+; RUN: rm -rf %t.dir
+
+; Test to ensure that -dwodir:$DIR creates .dwo files under $DIR
+; RUN: lld-link -dwodir:%t.dir -noentry -dll %t1.o -out:%t.dll
+; RUN: llvm-readobj -h %t.dir/0.dwo | FileCheck %s
+
+; CHECK: Format: COFF-x86-64
+
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+define void @f() {
+entry:
+  ret void
+}


        


More information about the llvm-commits mailing list