Index: include/lld/ReaderWriter/ELFLinkingContext.h =================================================================== --- include/lld/ReaderWriter/ELFLinkingContext.h +++ include/lld/ReaderWriter/ELFLinkingContext.h @@ -262,8 +262,8 @@ void setCreateSeparateROSegment() { _mergeRODataToTextSegment = false; } - bool hasCoalescedWeakPair(StringRef name) const { - return _weakCoalescedSymbols.count(name) != 0; + bool hasCoalescedSharedLibPair(StringRef name) const { + return _sharedLibCoalescedSymbols.count(name) != 0; } private: @@ -300,7 +300,7 @@ StringRefVector _rpathList; StringRefVector _rpathLinkList; std::map _absoluteSymbols; - llvm::StringSet<> _weakCoalescedSymbols; + llvm::StringSet<> _sharedLibCoalescedSymbols; }; } // end namespace lld Index: lib/ReaderWriter/ELF/ELFLinkingContext.cpp =================================================================== --- lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -241,11 +241,6 @@ 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) { @@ -259,11 +254,12 @@ ua = dyn_cast(existingAtom); } - 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. + 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. // Save its name. - _weakCoalescedSymbols.insert(ua->name()); + _sharedLibCoalescedSymbols.insert(ua->name()); } } // end namespace lld Index: lib/ReaderWriter/ELF/OutputELFWriter.h =================================================================== --- lib/ReaderWriter/ELF/OutputELFWriter.h +++ lib/ReaderWriter/ELF/OutputELFWriter.h @@ -183,7 +183,7 @@ for (const auto &atom : section->atoms()) { const DefinedAtom *da = dyn_cast(atom->_atom); if (da && (da->dynamicExport() == DefinedAtom::dynamicExportAlways || - _context.hasCoalescedWeakPair(da->name()))) + _context.hasCoalescedSharedLibPair(da->name()))) _dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(), atom->_virtualAddr, atom); } Index: test/elf/undef-from-dso-to-main.test =================================================================== --- /dev/null +++ test/elf/undef-from-dso-to-main.test @@ -0,0 +1,7 @@ +# 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