Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -756,15 +756,6 @@ if (Args.hasArg(OPT_force) || Args.hasArg(OPT_force_unresolved)) Config->Force = true; - // Handle /debug - if (Args.hasArg(OPT_debug)) { - Config->Debug = true; - Config->DebugTypes = - Args.hasArg(OPT_debugtype) - ? parseDebugType(Args.getLastArg(OPT_debugtype)->getValue()) - : getDefaultDebugType(Args); - } - // Create a dummy PDB file to satisfy build sytem rules. if (auto *Arg = Args.getLastArg(OPT_pdb)) Config->PDBPath = Arg->getValue(); @@ -842,6 +833,19 @@ if (auto *Arg = Args.getLastArg(OPT_implib)) Config->Implib = Arg->getValue(); + // Handle /debug + if (Args.hasArg(OPT_debug)) { + Config->Debug = true; + Config->DebugTypes = + Args.hasArg(OPT_debugtype) + ? parseDebugType(Args.getLastArg(OPT_debugtype)->getValue()) + : getDefaultDebugType(Args); + + // msvc linker uses /opt:noref by default in debug builds + Config->DoGC = false; + Config->DoICF = false; + } + // Handle /opt for (auto *Arg : Args.filtered(OPT_opt)) { std::string Str = StringRef(Arg->getValue()).lower(); Index: lld/test/COFF/icf-associative.test =================================================================== --- lld/test/COFF/icf-associative.test +++ lld/test/COFF/icf-associative.test @@ -1,6 +1,6 @@ # RUN: yaml2obj < %s > %t.obj # RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \ -# RUN: /debug /verbose %t.obj > %t.log 2>&1 +# RUN: /debug /opt:icf /verbose %t.obj > %t.log 2>&1 # RUN: FileCheck %s < %t.log # CHECK: Selected foo Index: lld/test/COFF/icf-simple.test =================================================================== --- lld/test/COFF/icf-simple.test +++ lld/test/COFF/icf-simple.test @@ -12,6 +12,9 @@ # RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \ # RUN: /verbose /opt:noref,noicf %t.obj > %t.log 2>&1 # RUN: FileCheck -check-prefix=NOICF %s < %t.log +# RUN: lld-link /entry:foo /out:%t.exe /subsystem:console /include:bar \ +# RUN: /verbose /debug %t.obj > %t.log 2>&1 +# RUN: FileCheck -check-prefix=NOICF %s < %t.log # NOICF-NOT: Removed foo # NOICF-NOT: Removed bar Index: lld/test/COFF/pdb-global-gc.yaml =================================================================== --- lld/test/COFF/pdb-global-gc.yaml +++ lld/test/COFF/pdb-global-gc.yaml @@ -1,7 +1,7 @@ # RUN: yaml2obj %s -o %t.obj # RUN: llvm-mc %S/Inputs/pdb-global-gc.s -triple x86_64-windows-msvc -filetype=obj -o %t2.obj -# RUN: lld-link %t.obj %t2.obj -debug -entry:main \ -# RUN: -nodefaultlib -debug -out:%t.exe -pdb:%t.pdb -verbose +# RUN: lld-link %t.obj %t2.obj -debug -opt:ref -entry:main \ +# RUN: -nodefaultlib -debug -opt:ref -out:%t.exe -pdb:%t.pdb -verbose # RUN: llvm-pdbutil dump -symbols -globals %t.pdb | FileCheck %s # This tests the case where an __imp_ chunk is discarded by linker GC. The debug