diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index 51727fb89c37..577b59866e9d 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -262,8 +262,8 @@ public: void setCreateSeparateROSegment() { _mergeRODataToTextSegment = false; } - bool hasCoalescedSharedLibPair(StringRef name) const { - return _sharedLibCoalescedSymbols.count(name) != 0; + bool hasCoalescedWeakPair(StringRef name) const { + return _weakCoalescedSymbols.count(name) != 0; } private: @@ -300,7 +300,7 @@ protected: StringRefVector _rpathList; StringRefVector _rpathLinkList; std::map _absoluteSymbols; - llvm::StringSet<> _sharedLibCoalescedSymbols; + llvm::StringSet<> _weakCoalescedSymbols; }; } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp index 003901abf7c6..08f2b8c8f482 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -241,6 +241,11 @@ std::unique_ptr ELFLinkingContext::createUndefinedSymbolFile() const { return std::move(undefinedSymFile); } +static bool isSharedWeakAtom(const UndefinedAtom *ua) { + return ua->canBeNull() != UndefinedAtom::canBeNullNever && + isa(ua->file()); +} + void ELFLinkingContext::notifySymbolTableCoalesce(const Atom *existingAtom, const Atom *newAtom, bool &useNew) { @@ -254,12 +259,11 @@ void ELFLinkingContext::notifySymbolTableCoalesce(const Atom *existingAtom, ua = dyn_cast(existingAtom); } - if (da && ua && da->scope() == Atom::scopeGlobal && - isa(ua->file())) - // If strong defined atom coalesces away an atom declared - // in the shared object the strong atom needs to be dynamically exported. + if (da && ua && da->scope() == Atom::scopeGlobal && isSharedWeakAtom(ua)) + // If strong defined atom coalesces away weak atom declared + // in the shared object the strong atom needs to be dynamicaly exported. // Save its name. - _sharedLibCoalescedSymbols.insert(ua->name()); + _weakCoalescedSymbols.insert(ua->name()); } } // end namespace lld diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h index 9ed766083bdb..bd0af9685982 100644 --- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h @@ -183,7 +183,7 @@ void OutputELFWriter::buildDynamicSymbolTable(const File &file) { for (const auto &atom : section->atoms()) { const DefinedAtom *da = dyn_cast(atom->_atom); if (da && (da->dynamicExport() == DefinedAtom::dynamicExportAlways || - _context.hasCoalescedSharedLibPair(da->name()))) + _context.hasCoalescedWeakPair(da->name()))) _dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(), atom->_virtualAddr, atom); } diff --git a/lld/test/elf/undef-from-dso-to-main.test b/lld/test/elf/undef-from-dso-to-main.test deleted file mode 100644 index 86f9f9b6a0c5..000000000000 --- a/lld/test/elf/undef-from-dso-to-main.test +++ /dev/null @@ -1,7 +0,0 @@ -# Tests that a reference from a DSO to a regular object -# forces the final executable to export the symbol. - -RUN: lld -flavor gnu -target x86_64 %p/Inputs/defobj.o -L%p/Inputs -lundef2 -o %t1 -RUN: llvm-readobj -dyn-symbols %t1 | FileCheck -check-prefix CHECKSYMS %s - -CHECKSYMS: myexportedsymbol