diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index b5510b3b27362..dcdd80d6a4ea9 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -1669,7 +1669,6 @@ createBitcodeSymbol(Symbol *&sym, const std::vector &keptComdats, uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL; uint8_t type = objSym.isTLS() ? STT_TLS : STT_NOTYPE; uint8_t visibility = mapVisibility(objSym.getVisibility()); - bool canOmitFromDynSym = objSym.canBeOmittedFromSymbolTable(); StringRef name; if (sym) { @@ -1682,8 +1681,6 @@ createBitcodeSymbol(Symbol *&sym, const std::vector &keptComdats, int c = objSym.getComdatIndex(); if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) { Undefined newSym(&f, name, binding, visibility, type); - if (canOmitFromDynSym) - newSym.exportDynamic = false; sym->resolve(newSym); sym->referenced = true; return; @@ -1695,7 +1692,7 @@ createBitcodeSymbol(Symbol *&sym, const std::vector &keptComdats, objSym.getCommonSize()}); } else { Defined newSym(&f, name, binding, visibility, type, 0, 0, nullptr); - if (canOmitFromDynSym) + if (objSym.canBeOmittedFromSymbolTable()) newSym.exportDynamic = false; sym->resolve(newSym); } diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 5c10df489d916..e409e86f9c348 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -254,7 +254,7 @@ void BitcodeCompiler::add(BitcodeFile &f) { // Identify symbols exported dynamically, and that therefore could be // referenced by a shared library not visible to the linker. r.ExportDynamic = sym->computeBinding() != STB_LOCAL && - (sym->isExportDynamic(sym->kind()) || + (config->shared || config->exportDynamic || sym->exportDynamic || sym->inDynamicList); const auto *dr = dyn_cast(sym); r.FinalDefinitionInLinkageUnit = diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 22d57e54d2f0e..a306cdd3a01fd 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -228,10 +228,6 @@ class Symbol { // non-lazy object causes a runtime error. void extract() const; - static bool isExportDynamic(Kind k) { - return k == SharedKind || config->shared || config->exportDynamic; - } - private: void resolveUndefined(const Undefined &other); void resolveCommon(const CommonSymbol &other); @@ -250,14 +246,14 @@ class Symbol { binding(binding), type(type), stOther(stOther), symbolKind(k), visibility(stOther & 3), isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind), - exportDynamic(isExportDynamic(k)), inDynamicList(false), - canInline(false), referenced(false), traced(false), - hasVersionSuffix(false), isInIplt(false), gotInIgot(false), - isPreemptible(false), used(!config->gcSections), folded(false), - needsTocRestore(false), scriptDefined(false), needsCopy(false), - needsGot(false), needsPlt(false), needsTlsDesc(false), - needsTlsGd(false), needsTlsGdToIe(false), needsTlsLd(false), - needsGotDtprel(false), needsTlsIe(false), hasDirectReloc(false) {} + exportDynamic(false), inDynamicList(false), canInline(false), + referenced(false), traced(false), hasVersionSuffix(false), + isInIplt(false), gotInIgot(false), isPreemptible(false), + used(!config->gcSections), folded(false), needsTocRestore(false), + scriptDefined(false), needsCopy(false), needsGot(false), + needsPlt(false), needsTlsDesc(false), needsTlsGd(false), + needsTlsGdToIe(false), needsTlsLd(false), needsGotDtprel(false), + needsTlsIe(false), hasDirectReloc(false) {} public: // True if this symbol is in the Iplt sub-section of the Plt and the Igot @@ -330,7 +326,9 @@ class Defined : public Symbol { Defined(InputFile *file, StringRef name, uint8_t binding, uint8_t stOther, uint8_t type, uint64_t value, uint64_t size, SectionBase *section) : Symbol(DefinedKind, file, name, binding, stOther, type), value(value), - size(size), section(section) {} + size(size), section(section) { + exportDynamic = config->shared || config->exportDynamic; + } static bool classof(const Symbol *s) { return s->isDefined(); } @@ -365,7 +363,9 @@ class CommonSymbol : public Symbol { CommonSymbol(InputFile *file, StringRef name, uint8_t binding, uint8_t stOther, uint8_t type, uint64_t alignment, uint64_t size) : Symbol(CommonKind, file, name, binding, stOther, type), - alignment(alignment), size(size) {} + alignment(alignment), size(size) { + exportDynamic = config->shared || config->exportDynamic; + } static bool classof(const Symbol *s) { return s->isCommon(); } @@ -396,6 +396,7 @@ class SharedSymbol : public Symbol { : Symbol(SharedKind, &file, name, binding, stOther, type), value(value), size(size), alignment(alignment) { this->verdefIndex = verdefIndex; + exportDynamic = true; // GNU ifunc is a mechanism to allow user-supplied functions to // resolve PLT slot values at load-time. This is contrary to the // regular symbol resolution scheme in which symbols are resolved just