[lld] [LLD] [COFF] Parse all /debug: options, like /opt: (PR #75178)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 10:08:44 PST 2023


https://github.com/mstorsjo updated https://github.com/llvm/llvm-project/pull/75178

>From deb4ffdb7925003cbb91d0624834bba2a8ded428 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Mon, 6 Nov 2023 17:48:29 +0200
Subject: [PATCH] [LLD] [COFF] Parse all /debug: options, like /opt:

Most option handling is like it was before; the last /debug: option
takes effect.

However, the options /debug:dwarf or /debug:symtab don't reset
all flags into the specific behaviour they chose before - e.g. if
an earlier option enables writing a PDB, a later /debug:dwarf or
/debug:symtab doesn't disable that. This allows combining these
options with options for controlling PDB writing, for finetuning
what is done.
---
 lld/COFF/Driver.cpp            | 69 ++++++++++++++++++++--------------
 lld/test/COFF/debug-dwarf.test |  8 ++++
 lld/test/COFF/symtab.test      |  2 +
 3 files changed, 50 insertions(+), 29 deletions(-)

diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 54121cec178d87..f9abc8cda1b8d2 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1616,37 +1616,48 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
 
   // Handle /debug
   bool shouldCreatePDB = false;
-  if (auto *arg = args.getLastArg(OPT_debug, OPT_debug_opt)) {
-    std::string s;
+  for (auto *arg : args.filtered(OPT_debug, OPT_debug_opt)) {
+    std::string str;
     if (arg->getOption().getID() == OPT_debug)
-      s = "full";
+      str = "full";
     else
-      s = StringRef(arg->getValue()).lower();
-    if (s == "fastlink") {
-      warn("/debug:fastlink unsupported; using /debug:full");
-      s = "full";
-    }
-    if (s == "none") {
-    } else if (s == "full" || s == "ghash" || s == "noghash") {
-      config->debug = true;
-      config->incremental = true;
-      config->includeDwarfChunks = true;
-      if (s == "full" || s == "ghash")
-        config->debugGHashes = true;
-      shouldCreatePDB = true;
-      doGC = false;
-    } else if (s == "dwarf") {
-      config->debug = true;
-      config->incremental = true;
-      config->includeDwarfChunks = true;
-      config->writeSymtab = true;
-      config->warnLongSectionNames = false;
-      doGC = false;
-    } else if (s == "symtab") {
-      config->writeSymtab = true;
-      doGC = false;
-    } else {
-      error("/debug: unknown option: " + s);
+      str = StringRef(arg->getValue()).lower();
+    SmallVector<StringRef, 1> vec;
+    StringRef(str).split(vec, ',');
+    for (StringRef s : vec) {
+      if (s == "fastlink") {
+        warn("/debug:fastlink unsupported; using /debug:full");
+        s = "full";
+      }
+      if (s == "none") {
+        config->debug = false;
+        config->incremental = false;
+        config->includeDwarfChunks = false;
+        config->debugGHashes = false;
+        config->writeSymtab = false;
+        shouldCreatePDB = false;
+        doGC = true;
+      } else if (s == "full" || s == "ghash" || s == "noghash") {
+        config->debug = true;
+        config->incremental = true;
+        config->includeDwarfChunks = true;
+        if (s == "full" || s == "ghash")
+          config->debugGHashes = true;
+        shouldCreatePDB = true;
+        doGC = false;
+      } else if (s == "dwarf") {
+        config->debug = true;
+        config->incremental = true;
+        config->includeDwarfChunks = true;
+        config->writeSymtab = true;
+        config->warnLongSectionNames = false;
+        doGC = false;
+      } else if (s == "symtab") {
+        config->writeSymtab = true;
+        doGC = false;
+      } else {
+        error("/debug: unknown option: " + s);
+      }
     }
   }
 
diff --git a/lld/test/COFF/debug-dwarf.test b/lld/test/COFF/debug-dwarf.test
index 156b2f58f64e31..eacf363b41af4a 100644
--- a/lld/test/COFF/debug-dwarf.test
+++ b/lld/test/COFF/debug-dwarf.test
@@ -17,3 +17,11 @@
 # RUN: rm -f %t.pdb
 # RUN: lld-link /debug:dwarf /pdb:%t.pdb /entry:main /out:%t.exe %p/Inputs/ret42.obj
 # RUN: not ls %t.pdb
+
+# Check that /debug /debug:dwarf or /debug:full,dwarf creates %t.pdb.
+# RUN: rm -f %t.pdb
+# RUN: lld-link /debug /debug:dwarf /entry:main /out:%t.exe %p/Inputs/ret42.obj
+# RUN: ls %t.pdb
+# RUN: rm -f %t.pdb
+# RUN: lld-link /debug:full,dwarf /entry:main /out:%t.exe %p/Inputs/ret42.obj
+# RUN: ls %t.pdb
diff --git a/lld/test/COFF/symtab.test b/lld/test/COFF/symtab.test
index 48c749957a422a..f65754335a97ef 100644
--- a/lld/test/COFF/symtab.test
+++ b/lld/test/COFF/symtab.test
@@ -5,6 +5,8 @@
 # RUN: llvm-readobj --symbols %t.exe | FileCheck %s
 # RUN: lld-link /debug:symtab /opt:noref /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
 # RUN: llvm-readobj --symbols %t.exe | FileCheck %s
+# RUN: lld-link /debug:full,symtab /opt:noref /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj --symbols %t.exe | FileCheck %s
 
 # RUN: lld-link /debug /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
 # RUN: llvm-readobj --symbols %t.exe | FileCheck -check-prefix=NO %s



More information about the llvm-commits mailing list