diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1984,11 +1984,11 @@ if (config->strip == StripPolicy::None) return false; - if (isDebugSection(*s)) + if (s->isDebug) return true; if (auto *isec = dyn_cast(s)) if (InputSectionBase *rel = isec->getRelocatedSection()) - if (isDebugSection(*rel)) + if (rel->isDebug) return true; return false; diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -33,6 +33,10 @@ extern std::vector partitions; +inline bool isDebugSection(const StringRef &name) { + return name.startswith(".debug") || name.startswith(".zdebug"); +} + // This is the base class of all sections that lld handles. Some are sections in // input files, some are sections in the produced output file and some exist // just as a convenience for implementing special ways of combining some @@ -62,6 +66,9 @@ // Set for sections that should not be folded by ICF. unsigned keepUnique : 1; + // True if that section is a debug section. + unsigned isDebug : 1; + // The 1-indexed partition that this section is assigned to by the garbage // collector, or 0 if this section is dead. Normally there is only one // partition, so this will either be 0 or 1. @@ -96,8 +103,9 @@ uint64_t entsize, uint64_t alignment, uint32_t type, uint32_t info, uint32_t link) : name(name), repl(this), sectionKind(sectionKind), bss(false), - keepUnique(false), partition(0), alignment(alignment), flags(flags), - entsize(entsize), type(type), link(link), info(info) {} + keepUnique(false), isDebug(isDebugSection(name)), partition(0), + alignment(alignment), flags(flags), entsize(entsize), type(type), + link(link), info(info) {} }; // This corresponds to a section of an input file. @@ -390,10 +398,6 @@ template void copyShtGroup(uint8_t *buf); }; -inline bool isDebugSection(const InputSectionBase &sec) { - return sec.name.startswith(".debug") || sec.name.startswith(".zdebug"); -} - // The list of all input sections. extern std::vector inputSections; diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -441,7 +441,7 @@ // See the comment in maybeReportUndefined for PPC32 .got2 and PPC64 .toc auto *d = dyn_cast(&sym); if (!d) { - if (!isDebugSection(*sec) && sec->name != ".eh_frame" && + if (!sec->isDebug && sec->name != ".eh_frame" && sec->name != ".gcc_except_table" && sec->name != ".got2" && sec->name != ".toc") { uint32_t secIdx = cast(sym).discardedSecIdx;