Index: lld/ELF/InputFiles.cpp =================================================================== --- lld/ELF/InputFiles.cpp +++ lld/ELF/InputFiles.cpp @@ -729,6 +729,13 @@ if (Name.startswith(".gnu.linkonce.")) return &InputSection::Discarded; + // We create a .gdb_index section from .debug_gnu_pub{names,types}. + // If --gdb-index is not given, they are useless. So eliminate them early. + if (!Config->GdbIndex && + (Name == ".debug_gnu_pubnames" || Name == ".zdebug_gnu_pubnames" || + Name == ".debug_gnu_pubtypes" || Name == ".zdebug_gnu_pubtypes")) + return &InputSection::Discarded; + // If we are creating a new .build-id section, strip existing .build-id // sections so that the output won't have more than one .build-id. // This is not usually a problem because input object files normally don't Index: lld/test/ELF/debug-gnu-pubnames.s =================================================================== --- lld/test/ELF/debug-gnu-pubnames.s +++ lld/test/ELF/debug-gnu-pubnames.s @@ -3,13 +3,12 @@ # RUN: ld.lld %t.o -o %t1.exe # RUN: llvm-readobj -sections %t1.exe | FileCheck %s -# CHECK: .debug_gnu_pubnames -# CHECK: .debug_gnu_pubtypes # RUN: ld.lld -gdb-index %t.o -o %t2.exe -# RUN: llvm-readobj -sections %t2.exe | FileCheck %s --check-prefix=GDB -# GDB-NOT: .debug_gnu_pubnames -# GDB-NOT: .debug_gnu_pubtypes +# RUN: llvm-readobj -sections %t2.exe | FileCheck %s + +# CHECK-NOT: .debug_gnu_pubnames +# CHECK-NOT: .debug_gnu_pubtypes .section .debug_gnu_pubnames,"",@progbits .long 0