diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index ec63d2ef4d6f99..3b991e8d347064 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -461,8 +461,9 @@ template void ICF::run() { // Compute isPreemptible early. We may add more symbols later, so this loop // cannot be merged with the later computeIsPreemptible() pass which is used // by scanRelocations(). - for (Symbol *sym : symtab->symbols()) - sym->isPreemptible = computeIsPreemptible(*sym); + if (config->hasDynSymTab) + for (Symbol *sym : symtab->symbols()) + sym->isPreemptible = computeIsPreemptible(*sym); // Two text sections may have identical content and relocations but different // LSDA, e.g. the two functions may have catch blocks of different types. If a diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index f3bd67b8587378..2be5e8d9510c13 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -279,8 +279,6 @@ uint8_t Symbol::computeBinding() const { } bool Symbol::includeInDynsym() const { - if (!config->hasDynSymTab) - return false; if (computeBinding() == STB_LOCAL) return false; if (!isDefined() && !isCommon()) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 7249368fe91267..b87123a216bc40 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1912,8 +1912,9 @@ template void Writer::finalizeSections() { finalizeSynthetic(part.ehFrame.get()); } - for (Symbol *sym : symtab->symbols()) - sym->isPreemptible = computeIsPreemptible(*sym); + if (config->hasDynSymTab) + for (Symbol *sym : symtab->symbols()) + sym->isPreemptible = computeIsPreemptible(*sym); // Change values of linker-script-defined symbols from placeholders (assigned // by declareSymbols) to actual definitions.