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
This commit is contained in:
Rui Ueyama 2015-09-21 23:43:31 +00:00
parent fc580a60e2
commit 9640173e16
5 changed files with 13 additions and 1 deletions

View File

@ -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;

View File

@ -427,6 +427,8 @@ void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
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.

View File

@ -86,6 +86,9 @@ defm tsaware : B<"tsaware", "Create non-Terminal Server aware executable">;
def help : F<"help">;
def help_q : Flag<["/?", "-?"], "">, Alias<help>;
// LLD extensions
def nosymtab : F<"nosymtab">;
// Flags for debugging
def lldmap : Joined<["/", "-"], "lldmap:">;

View File

@ -422,8 +422,9 @@ Optional<coff_symbol16> Writer::createSymbol(Defined *Def) {
}
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) {

View File

@ -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