COFF: Add /nosymtab command line option.

This is an LLD extension to MSVC link.exe command line. MSVC linker
does not write symbol tables for executables. We do unless no /debug
option is given.

There's a situation that we want to enable debug info but don't want
to emit the symbol table. One example is when we are comparing output
file size. With this patch, you can tell the linker to not create
a symbol table by just specifying /nosymtab.

llvm-svn: 248225
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 4558d57..409ede6 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -70,6 +70,7 @@
   bool Relocatable = true;
   bool Force = false;
   bool Debug = false;
+  bool WriteSymtab = true;
 
   // Symbols in this set are considered as live by the garbage collector.
   std::set<Undefined *> GCRoot;
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 9eade90..4d375c3 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -427,6 +427,8 @@
     Config->NxCompat = false;
   if (Args.hasArg(OPT_tsaware_no))
     Config->TerminalServerAware = false;
+  if (Args.hasArg(OPT_nosymtab))
+    Config->WriteSymtab = false;
 
   // Create a list of input files. Files can be given as arguments
   // for /defaultlib option.
diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index 2402b80..a21b8de 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -86,6 +86,9 @@
 def help : F<"help">;
 def help_q : Flag<["/?", "-?"], "">, Alias<help>;
 
+// LLD extensions
+def nosymtab : F<"nosymtab">;
+
 // Flags for debugging
 def lldmap : Joined<["/", "-"], "lldmap:">;
 
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 8e1a652..a74b316 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -422,8 +422,9 @@
 }
 
 void Writer::createSymbolAndStringTable() {
-  if (!Config->Debug)
+  if (!Config->Debug || !Config->WriteSymtab)
     return;
+
   // Name field in the section table is 8 byte long. Longer names need
   // to be written to the string table. First, construct string table.
   for (OutputSection *Sec : OutputSections) {