diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index d198ed29ff91..153c645c8f13 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -832,7 +832,24 @@ static bool shouldKeepInSymtab(InputSectionBase *Sec, StringRef SymName, return !(Sec->getSectionHdr()->sh_flags & SHF_MERGE); } -template static bool includeInSymtab(const SymbolBody &B); +template static bool includeInSymtab(const SymbolBody &B) { + if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj) + return false; + + if (auto *D = dyn_cast>(&B)) { + // Always include absolute symbols. + if (!D->Section) + return true; + // Exclude symbols pointing to garbage-collected sections. + if (!D->Section->Live) + return false; + if (auto *S = dyn_cast>(D->Section)) + if (S->getRangeAndSize(D->Value).first->second == + MergeInputSection::PieceDead) + return false; + } + return true; +} // Local symbols are not in the linker's symbol table. This function scans // each object file's symbol table to copy local symbols to the output. @@ -1104,25 +1121,6 @@ template void Writer::addRelIpltSymbols() { DefinedSynthetic::SectionEnd); } -template static bool includeInSymtab(const SymbolBody &B) { - if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj) - return false; - - if (auto *D = dyn_cast>(&B)) { - // Always include absolute symbols. - if (!D->Section) - return true; - // Exclude symbols pointing to garbage-collected sections. - if (!D->Section->Live) - return false; - if (auto *S = dyn_cast>(D->Section)) - if (S->getRangeAndSize(D->Value).first->second == - MergeInputSection::PieceDead) - return false; - } - return true; -} - // This class knows how to create an output section for a given // input section. Output section type is determined by various // factors, including input section's sh_flags, sh_type and