[PATCH] D23280: COFF: handle /debugtype option

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 14:00:26 PDT 2016


compnerd created this revision.
compnerd added a reviewer: ruiu.
compnerd added a subscriber: llvm-commits.
compnerd set the repository for this revision to rL LLVM.

Add the support infrastructure for the `/debugtype` option which takes a comma delimited list of debug info to generate.  The defaults are based on other options potentially (`/driver` or `/profile`).  This sets up the infrastructure to allow us to emit RSDS records to get "build id" equivalents on COFF (similar to binutils).

Repository:
  rL LLVM

https://reviews.llvm.org/D23280

Files:
  COFF/Config.h
  COFF/Driver.cpp
  COFF/Options.td

Index: COFF/Options.td
===================================================================
--- COFF/Options.td
+++ COFF/Options.td
@@ -62,7 +62,9 @@
     HelpText<"Use module-definition file">;
 
 def debug : F<"debug">, HelpText<"Embed a symbol table in the image">;
+def debugtype : P<"debugtype", "Debug Info Options">;
 def dll : F<"dll">, HelpText<"Create a DLL">;
+def driver : P<"driver", "Generate a Windows NT Kernel Mode Driver">;
 def nodefaultlib_all : F<"nodefaultlib">;
 def noentry : F<"noentry">;
 def profile : F<"profile">;
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -16,6 +16,7 @@
 #include "Writer.h"
 #include "lld/Driver/Driver.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/LibDriver/LibDriver.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -282,6 +283,31 @@
   return Data.str();
 }
 
+static unsigned getDefaultDebugType(const llvm::opt::InputArgList &Args) {
+  unsigned DebugTypes = static_cast<unsigned>(Configuration::DebugType::CV);
+  if (Args.hasArg(OPT_driver))
+    DebugTypes |= static_cast<unsigned>(Configuration::DebugType::PData);
+  if (Args.hasArg(OPT_profile))
+    DebugTypes |= static_cast<unsigned>(Configuration::DebugType::Fixup);
+  return DebugTypes;
+}
+
+static unsigned parseDebugType(StringRef Arg) {
+  llvm::SmallVector<StringRef, 3> Types;
+  Arg.split(Types, ',', /*KeepEmpty=*/false);
+
+  unsigned DebugTypes = static_cast<unsigned>(Configuration::DebugType::None);
+  for (auto Type : Types)
+    DebugTypes |=
+        llvm::StringSwitch<unsigned>(Type.lower())
+            .Case("cv", static_cast<unsigned>(Configuration::DebugType::CV))
+            .Case("pdata",
+                  static_cast<unsigned>(Configuration::DebugType::PData))
+            .Case("fixup",
+                  static_cast<unsigned>(Configuration::DebugType::Fixup));
+  return DebugTypes;
+}
+
 void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
   // If the first command line argument is "/lib", link.exe acts like lib.exe.
   // We call our own implementation of lib.exe that understands bitcode files.
@@ -341,8 +367,13 @@
     Config->Force = true;
 
   // Handle /debug
-  if (Args.hasArg(OPT_debug))
+  if (Args.hasArg(OPT_debug)) {
     Config->Debug = true;
+    Config->DebugTypes =
+        Args.hasArg(OPT_debugtype)
+            ? parseDebugType(Args.getLastArg(OPT_debugtype)->getValue())
+            : getDefaultDebugType(Args);
+  }
 
   // Handle /noentry
   if (Args.hasArg(OPT_noentry)) {
Index: COFF/Config.h
===================================================================
--- COFF/Config.h
+++ COFF/Config.h
@@ -63,6 +63,12 @@
 
 // Global configuration.
 struct Configuration {
+  enum class DebugType {
+    None  = 0x0,
+    CV    = 0x1,  /// CodeView
+    PData = 0x2,  /// Procedure Data
+    Fixup = 0x4,  /// Relocation Table
+  };
   enum ManifestKind { SideBySide, Embed, No };
   bool is64() { return Machine == AMD64; }
 
@@ -78,6 +84,7 @@
   bool Force = false;
   bool Debug = false;
   bool WriteSymtab = true;
+  unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
 
   // Symbols in this set are considered as live by the garbage collector.
   std::set<Undefined *> GCRoot;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23280.67222.patch
Type: text/x-patch
Size: 3334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160808/62fc4ab1/attachment.bin>


More information about the llvm-commits mailing list