[lld] r248225 - COFF: Add /nosymtab command line option.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 16:43:31 PDT 2015


Author: ruiu
Date: Mon Sep 21 18:43:31 2015
New Revision: 248225

URL: http://llvm.org/viewvc/llvm-project?rev=248225&view=rev
Log:
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.

Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Options.td
    lld/trunk/COFF/Writer.cpp
    lld/trunk/test/COFF/symtab.test

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=248225&r1=248224&r2=248225&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Mon Sep 21 18:43:31 2015
@@ -70,6 +70,7 @@ struct Configuration {
   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;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=248225&r1=248224&r2=248225&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Mon Sep 21 18:43:31 2015
@@ -427,6 +427,8 @@ void LinkerDriver::link(llvm::ArrayRef<c
     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.

Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=248225&r1=248224&r2=248225&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Mon Sep 21 18:43:31 2015
@@ -86,6 +86,9 @@ defm tsaware  : B<"tsaware", "Create non
 def help : F<"help">;
 def help_q : Flag<["/?", "-?"], "">, Alias<help>;
 
+// LLD extensions
+def nosymtab : F<"nosymtab">;
+
 // Flags for debugging
 def lldmap : Joined<["/", "-"], "lldmap:">;
 

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=248225&r1=248224&r2=248225&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Sep 21 18:43:31 2015
@@ -422,8 +422,9 @@ Optional<coff_symbol16> Writer::createSy
 }
 
 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) {

Modified: lld/trunk/test/COFF/symtab.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/symtab.test?rev=248225&r1=248224&r2=248225&view=diff
==============================================================================
--- lld/trunk/test/COFF/symtab.test (original)
+++ lld/trunk/test/COFF/symtab.test Mon Sep 21 18:43:31 2015
@@ -4,6 +4,9 @@
 # RUN: lld-link /debug /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 /nosymtab /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib
+# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=NO %s
+
 # CHECK:      Symbols [
 # CHECK-NEXT:   Symbol {
 # CHECK-NEXT:     Name: .text
@@ -106,6 +109,8 @@
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 
+# NO: Symbols [
+
 ---
 header:
   Machine:         IMAGE_FILE_MACHINE_AMD64




More information about the llvm-commits mailing list