[PATCH] D92617: [DWARF] Allow toolchain to adjust specified DWARF version.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 16:46:54 PST 2020


tra updated this revision to Diff 309404.
tra edited the summary of this revision.
tra added a comment.

Updated according to Devid's feedback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92617/new/

https://reviews.llvm.org/D92617

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-unsupported-debug-options.cu


Index: clang/test/Driver/cuda-unsupported-debug-options.cu
===================================================================
--- clang/test/Driver/cuda-unsupported-debug-options.cu
+++ clang/test/Driver/cuda-unsupported-debug-options.cu
@@ -18,5 +18,7 @@
 // CHECK-NOT: debug information option '{{.*}}' is not supported for target 'x86
 // CHECK: "-triple" "nvptx64-nvidia-cuda"
 // CHECK-NOT: {{-compress-debug|-fdebug-info-for-profiling|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
+// Make sure we do not see any dwarf version other than 2, regardless of what's used on the host side.
+// CHECK-NOT: {{-dwarf-version=[^2]}}
 // CHECK: "-triple" "x86_64
 // CHECK-SAME: {{-compress-debug|-fdebug-info-for-profiling|split-dwarf|lldb|codeview|module-format|embed-source|debug-info-macro|gnu-pubnames|generate-arange-section|generate-type-units}}
Index: clang/lib/Driver/ToolChains/Cuda.h
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -185,6 +185,8 @@
                      const llvm::opt::ArgList &Args) const override;
 
   unsigned GetDefaultDwarfVersion() const override { return 2; }
+  // NVPTX supports only DWARF2.
+  unsigned getMaxDwarfVersion() const override { return 2; }
 
   const ToolChain &HostTC;
   CudaInstallationDetector CudaInstallation;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3918,8 +3918,15 @@
     if (DWARFVersion < 5)
       D.Diag(diag::err_drv_argument_only_allowed_with)
           << A->getAsString(Args) << "-gdwarf-5";
-    else if (checkDebugInfoOption(A, Args, D, TC))
-      CmdArgs.push_back("-gembed-source");
+    else {
+      if (TC.getMaxDwarfVersion() < 5)
+        // The toolchain has reduced allowed dwarf version, so we can't enable
+        // -gembed-source.
+        D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
+            << A->getAsString(Args) << TC.getTripleString();
+      else if (checkDebugInfoOption(A, Args, D, TC))
+        CmdArgs.push_back("-gembed-source");
+    }
   }
 
   if (EmitCodeView) {
@@ -3946,7 +3953,8 @@
       DebugInfoKind <= codegenoptions::DebugDirectivesOnly)
     DebugInfoKind = codegenoptions::DebugLineTablesOnly;
 
-  RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DWARFVersion,
+  RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind,
+                          std::min(DWARFVersion, TC.getMaxDwarfVersion()),
                           DebuggerTuning);
 
   // -fdebug-macro turns on macro debug info generation.
Index: clang/include/clang/Driver/ToolChain.h
===================================================================
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -27,6 +27,7 @@
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Target/TargetOptions.h"
 #include <cassert>
+#include <climits>
 #include <memory>
 #include <string>
 #include <utility>
@@ -489,6 +490,11 @@
   // to the contrary.
   virtual unsigned GetDefaultDwarfVersion() const { return 4; }
 
+  // Some toolchains may have different restrictions on the DWARF version and
+  // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when host
+  // compilation uses DWARF5.
+  virtual unsigned getMaxDwarfVersion() const { return UINT_MAX; }
+
   // True if the driver should assume "-fstandalone-debug"
   // in the absence of an option specifying otherwise,
   // provided that debugging was requested in the first place.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92617.309404.patch
Type: text/x-patch
Size: 3718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201204/2641f006/attachment.bin>


More information about the cfe-commits mailing list