Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -501,15 +501,6 @@ if (Config->Strip != StripPolicy::None && Name.startswith(".debug")) return &InputSection::Discarded; - // If -gdb-index is given, LLD creates .gdb_index section, and that - // section serves the same purpose as .debug_gnu_pub{names,types} sections. - // If that's the case, we want to eliminate .debug_gnu_pub{names,types} - // because they are redundant and can waste large amount of disk space - // (for example, they are about 400 MiB in total for a clang debug build.) - if (Config->GdbIndex && - (Name == ".debug_gnu_pubnames" || Name == ".debug_gnu_pubtypes")) - 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: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -1760,12 +1760,24 @@ return Ret; } -static std::vector getDebugInfoSections() { +static std::vector filterForGdbIndex() { std::vector Ret; - for (InputSectionBase *S : InputSections) - if (InputSection *IS = dyn_cast(S)) - if (IS->Name == ".debug_info") - Ret.push_back(IS); + for (InputSectionBase *S : InputSections) { + InputSection *IS = dyn_cast(S); + if (!IS) + continue; + StringRef Name = IS->Name; + if (Name == ".debug_info") + Ret.push_back(IS); + + // If -gdb-index is given, LLD creates .gdb_index section, and that + // section serves the same purpose as .debug_gnu_pub{names,types} sections. + // If that's the case, we want to eliminate .debug_gnu_pub{names,types} + // because they are redundant and can waste large amount of disk space + // (for example, they are about 400 MiB in total for a clang debug build.) + if (Name == ".debug_gnu_pubnames" || Name == ".debug_gnu_pubtypes") + Script->discard({S}); + } return Ret; } @@ -1809,7 +1821,7 @@ template GdbIndexSection *elf::createGdbIndex() { std::vector Chunks; - for (InputSection *Sec : getDebugInfoSections()) { + for (InputSection *Sec : filterForGdbIndex()) { InputFile *F = Sec->File; std::error_code EC; ELFObjectFile Obj(F->MB, EC);