Index: COFF/Config.h =================================================================== --- COFF/Config.h +++ COFF/Config.h @@ -99,6 +99,7 @@ bool Debug = false; bool DebugDwarf = false; bool DebugGHashes = false; + bool DebugSymtab = false; bool ShowTiming = false; unsigned DebugTypes = static_cast(DebugType::None); std::vector NatvisFiles; Index: COFF/Driver.cpp =================================================================== --- COFF/Driver.cpp +++ COFF/Driver.cpp @@ -1222,6 +1222,7 @@ !Config->DLL && Args.hasFlag(OPT_tsaware, OPT_tsaware_no, true); Config->DebugDwarf = Args.hasArg(OPT_debug_dwarf); Config->DebugGHashes = Args.hasArg(OPT_debug_ghash); + Config->DebugSymtab = Args.hasArg(OPT_debug_symtab); Config->MapFile = getMapFile(Args); Index: COFF/Options.td =================================================================== --- COFF/Options.td +++ COFF/Options.td @@ -139,6 +139,7 @@ // LLD extensions def debug_ghash : F<"debug:ghash">; def debug_dwarf : F<"debug:dwarf">; +def debug_symtab : F<"debug:symtab">; def export_all_symbols : F<"export-all-symbols">; def kill_at : F<"kill-at">; def lldmingw : F<"lldmingw">; Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -665,7 +665,7 @@ Sec->setStringTableOff(addEntryToStringTable(Sec->Name)); } - if (Config->DebugDwarf) { + if (Config->DebugDwarf || Config->DebugSymtab) { for (ObjFile *File : ObjFile::Instances) { for (Symbol *B : File->getSymbols()) { auto *D = dyn_cast_or_null(B); Index: MinGW/Driver.cpp =================================================================== --- MinGW/Driver.cpp +++ MinGW/Driver.cpp @@ -149,6 +149,8 @@ if (auto *A = Args.getLastArg(OPT_pdb)) { Add("-debug"); Add("-pdb:" + StringRef(A->getValue())); + } else if (Args.hasArg(OPT_strip_debug)) { + Add("-debug:symtab"); } else if (!Args.hasArg(OPT_strip_all)) { Add("-debug:dwarf"); } Index: MinGW/Options.td =================================================================== --- MinGW/Options.td +++ MinGW/Options.td @@ -35,6 +35,8 @@ def stack: S<"stack">; def strip_all: F<"strip-all">, HelpText<"Omit all symbol information from the output binary">; +def strip_debug: F<"strip-debug">, + HelpText<"Omit all debug information, but keep symbol information">; def whole_archive: F<"whole-archive">, HelpText<"Include all object files for following archives">; def verbose: F<"verbose">, HelpText<"Verbose mode">; @@ -72,3 +74,4 @@ // Alias def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias; def alias_strip_s: Flag<["-"], "s">, Alias; +def alias_strip_S: Flag<["-"], "S">, Alias; Index: test/COFF/sort-debug.test =================================================================== --- test/COFF/sort-debug.test +++ test/COFF/sort-debug.test @@ -1,6 +1,12 @@ # RUN: yaml2obj < %s > %t.obj # RUN: lld-link /debug /out:%t.exe /entry:main %t.obj # RUN: llvm-readobj -sections %t.exe | FileCheck %s +# RUN: lld-link /debug:dwarf /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck %s +# RUN: lld-link /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck -check-prefix=NODEBUG %s +# RUN: lld-link /debug:symtab /out:%t.exe /entry:main %t.obj +# RUN: llvm-readobj -sections %t.exe | FileCheck -check-prefix=NODEBUG %s # CHECK: Name: .text # CHECK: Name: .debug_abbrev @@ -10,6 +16,13 @@ # CHECK: Name: .debug_pubtypes # CHECK: Name: .reloc +# NODEBUG: Name: .text +# NODEBUG-NOT: Name: .debug_abbrev +# NODEBUG-NOT: Name: .debug_info +# NODEBUG-NOT: Name: .debug_line +# NODEBUG-NOT: Name: .debug_pubnames +# NODEBUG-NOT: Name: .debug_pubtypes +# NODEBUG: Name: .reloc --- !COFF header: Index: test/COFF/symtab.test =================================================================== --- test/COFF/symtab.test +++ test/COFF/symtab.test @@ -3,6 +3,8 @@ # RUN: llvm-readobj -symbols %t.exe | FileCheck %s # RUN: lld-link /debug:dwarf /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:symtab /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 /out:%t.exe /entry:main %t.obj %p/Inputs/std64.lib # RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=NO %s Index: test/MinGW/driver.test =================================================================== --- test/MinGW/driver.test +++ test/MinGW/driver.test @@ -90,6 +90,11 @@ RUN: ld.lld -### -m i386pep foo.o --strip-all | FileCheck -check-prefix STRIP %s STRIP-NOT: -debug:dwarf +RUN: ld.lld -### -m i386pep foo.o -S | FileCheck -check-prefix STRIP-DEBUG %s +RUN: ld.lld -### -m i386pep foo.o --strip-debug | FileCheck -check-prefix STRIP-DEBUG %s +STRIP-DEBUG: -debug:symtab +STRIP-DEBUG-NOT: -debug:dwarf + RUN: ld.lld -### -m i386pep foo.o -pdb out.pdb | FileCheck -check-prefix PDB %s PDB: -debug -pdb:out.pdb PDB-NOT: -debug:dwarf