Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -1106,6 +1106,13 @@ for (InputSectionBase *S : F->getSections()) InputSections.push_back(cast(S)); + // We do not want to emit debug sections if --strip-all + // or -strip-debug are given. + if (Config->Strip != StripPolicy::None) + llvm::erase_if(InputSections, [](InputSectionBase *S) { + return S->Name.startswith(".debug") || S->Name.startswith(".zdebug"); + }); + Config->EFlags = Target->calcEFlags(); // This adds a .comment section containing a version string. We have to add it Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -537,10 +537,6 @@ return &InputSection::Discarded; } - if (Config->Strip != StripPolicy::None && - (Name.startswith(".debug") || Name.startswith(".zdebug"))) - return &InputSection::Discarded; - // The linkonce feature is a sort of proto-comdat. Some glibc i386 object // files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce // sections. Drop those sections to avoid duplicate symbol errors. Index: lld/trunk/test/ELF/conflict-debug-variable.s =================================================================== --- lld/trunk/test/ELF/conflict-debug-variable.s +++ lld/trunk/test/ELF/conflict-debug-variable.s @@ -30,6 +30,9 @@ # CHECK-NEXT: >>> defined at 1.c:1 # CHECK-NEXT: >>> {{.*}}:(.bss+0x0) +## Check that stripping debug sections does not break error reporting. +# RUN: not ld.lld --strip-debug %t.o %t.o -o %t 2>&1 | FileCheck %s + # Used reduced output from following code and gcc 7.1.0 # to produce this input file: # Source (1.c):