From b3f97ba815b8ccb794aa3836cfd135feb9d43da7 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 9 Oct 2014 00:05:55 +0000 Subject: [PATCH] Revert "[ELF] Only mark as DT_NEEDED libs that are strictly necessary" This reverts commit r219353 because that seems to break buildbots. llvm-svn: 219369 --- .../lld/ReaderWriter/ELFLinkingContext.h | 9 -------- .../ELF/AArch64/AArch64LinkingContext.h | 9 -------- .../ELF/AArch64/AArch64RelocationPass.cpp | 2 +- lld/lib/ReaderWriter/ELF/Atoms.h | 7 +------ lld/lib/ReaderWriter/ELF/DefaultLayout.h | 16 +------------- .../ELF/Mips/MipsDynamicLibraryWriter.h | 4 ++++ .../ReaderWriter/ELF/Mips/MipsELFWriters.h | 5 +++++ .../ELF/Mips/MipsExecutableWriter.h | 4 ++++ .../ELF/Mips/MipsLinkingContext.cpp | 9 -------- .../ELF/Mips/MipsLinkingContext.h | 1 - .../ELF/Mips/MipsRelocationPass.cpp | 2 +- .../ReaderWriter/ELF/Mips/MipsTargetHandler.h | 21 +++++++++++++++++++ lld/lib/ReaderWriter/ELF/OutputELFWriter.h | 7 ++----- .../ELF/X86_64/X86_64LinkingContext.h | 9 -------- .../ELF/X86_64/X86_64RelocationPass.cpp | 2 +- 15 files changed, 41 insertions(+), 66 deletions(-) diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index 582b345bc93b..1ace8b93a07d 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -90,15 +90,6 @@ public: const Reference &) const { return false; } - - /// \brief Is this a copy relocation? - /// - /// If this is a copy relocation, its target must be an ObjectAtom. We must - /// include in DT_NEEDED the name of the library where this object came from. - virtual bool isCopyRelocation(const Reference &) const { - return false; - } - bool validateImpl(raw_ostream &diagnostics) override; /// \brief Does the linker allow dynamic libraries to be linked with? diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h index 2ae5b3945568..07ec6c1a2b36 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h @@ -59,15 +59,6 @@ public: } } - bool isCopyRelocation(const Reference &r) const override { - if (r.kindNamespace() != Reference::KindNamespace::ELF) - return false; - assert(r.kindArch() == Reference::KindArch::AArch64); - if (r.kindValue() == llvm::ELF::R_AARCH64_COPY) - return true; - return false; - } - bool isPLTRelocation(const DefinedAtom &, const Reference &r) const override { if (r.kindNamespace() != Reference::KindNamespace::ELF) diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp b/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp index 8b97361fc5e3..3d0d5fe3a362 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp @@ -452,7 +452,7 @@ public: if (obj != _objectMap.end()) return obj->second; - auto oa = new (_file._alloc) ObjectAtom(_file, a); + auto oa = new (_file._alloc) ObjectAtom(_file); // This needs to point to the atom that we just created. oa->addReferenceELF_AArch64(R_AARCH64_COPY, 0, oa, 0); diff --git a/lld/lib/ReaderWriter/ELF/Atoms.h b/lld/lib/ReaderWriter/ELF/Atoms.h index 8be6ec54f4e6..cb050e0a3f4e 100644 --- a/lld/lib/ReaderWriter/ELF/Atoms.h +++ b/lld/lib/ReaderWriter/ELF/Atoms.h @@ -689,11 +689,8 @@ public: /// \brief Atom which represents an object for which a COPY relocation will be /// generated. class ObjectAtom : public SimpleELFDefinedAtom { - const SharedLibraryAtom *_sla; - public: - ObjectAtom(const File &f, const SharedLibraryAtom *sla) - : SimpleELFDefinedAtom(f), _sla(sla) {} + ObjectAtom(const File &f) : SimpleELFDefinedAtom(f) {} Scope scope() const override { return scopeGlobal; } @@ -716,8 +713,6 @@ public: StringRef name() const override { return _name; } - const SharedLibraryAtom *getOriginalOwner() const { return _sla; } - std::string _name; uint64_t _size; }; diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index f9a7324e79c1..d198c5abc6f7 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -10,7 +10,6 @@ #ifndef LLD_READER_WRITER_ELF_DEFAULT_LAYOUT_H #define LLD_READER_WRITER_ELF_DEFAULT_LAYOUT_H -#include "Atoms.h" #include "Chunk.h" #include "HeaderChunks.h" #include "Layout.h" @@ -172,7 +171,6 @@ public: typedef typename std::vector::iterator AbsoluteAtomIterT; typedef llvm::DenseSet AtomSetT; - typedef llvm::DenseSet SharedLibraryAtomSetT; DefaultLayout(const ELFLinkingContext &context) : _context(context) {} @@ -305,10 +303,6 @@ public: return _referencedDynAtoms.count(a); } - const SharedLibraryAtomSetT &getCopiedDynAtoms() const { - return _copiedDynAtoms; - } - protected: /// \brief Allocate a new section. virtual AtomSection *createSection( @@ -331,7 +325,6 @@ protected: LLD_UNIQUE_BUMP_PTR(RelocationTable) _pltRelocationTable; std::vector _absoluteAtoms; AtomSetT _referencedDynAtoms; - SharedLibraryAtomSetT _copiedDynAtoms; const ELFLinkingContext &_context; }; @@ -589,14 +582,7 @@ ErrorOr DefaultLayout::addAtom(const Atom *atom) if (isa(reloc->target()) && isLocalReloc) continue; - if (!_context.isCopyRelocation(*reloc)) { - _referencedDynAtoms.insert(reloc->target()); - continue; - } - - const ObjectAtom *oa = dyn_cast(reloc->target()); - assert (oa != nullptr && "Targets of copy relocs must be ObjectAtoms"); - _copiedDynAtoms.insert(oa->getOriginalOwner()); + _referencedDynAtoms.insert(reloc->target()); } return section->appendAtom(atom); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h index 819c0869e7a7..5d895d52bc5f 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h @@ -37,6 +37,10 @@ protected: return std::error_code(); } + bool isNeededTagRequired(const SharedLibraryAtom *sla) const override { + return _writeHelper.isNeededTagRequired(sla); + } + LLD_UNIQUE_BUMP_PTR(DynamicTable) createDynamicTable(); LLD_UNIQUE_BUMP_PTR(DynamicSymbolTable) createDynamicSymbolTable(); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h index 4f4f22662fb2..3b26816885a1 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h @@ -69,6 +69,11 @@ public: return file; } + bool isNeededTagRequired(const SharedLibraryAtom *sla) const { + return _targetLayout.isReferencedByDefinedAtom(sla) || + _targetLayout.isCopied(sla); + } + private: MipsLinkingContext &_ctx; MipsTargetLayout &_targetLayout; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h b/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h index 07b155e7f479..a220428582bd 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h @@ -38,6 +38,10 @@ protected: return std::error_code(); } + bool isNeededTagRequired(const SharedLibraryAtom *sla) const override { + return _writeHelper.isNeededTagRequired(sla); + } + LLD_UNIQUE_BUMP_PTR(DynamicTable) createDynamicTable(); LLD_UNIQUE_BUMP_PTR(DynamicSymbolTable) createDynamicSymbolTable(); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp index af3f8ad31cf2..946c96c7fa23 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp @@ -65,15 +65,6 @@ bool MipsLinkingContext::isDynamicRelocation(const DefinedAtom &, } } -bool MipsLinkingContext::isCopyRelocation(const Reference &r) const { - if (r.kindNamespace() != Reference::KindNamespace::ELF) - return false; - assert(r.kindArch() == Reference::KindArch::Mips); - if (r.kindValue() == llvm::ELF::R_MIPS_COPY) - return true; - return false; -} - bool MipsLinkingContext::isPLTRelocation(const DefinedAtom &, const Reference &r) const { if (r.kindNamespace() != Reference::KindNamespace::ELF) diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h index ef8ff42b6d79..d39e403ccfce 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h @@ -47,7 +47,6 @@ public: bool isRelaOutputFormat() const override { return false; } bool isDynamicRelocation(const DefinedAtom &, const Reference &r) const override; - bool isCopyRelocation(const Reference &r) const override; bool isPLTRelocation(const DefinedAtom &, const Reference &r) const override; }; diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp index 0486709e6c46..ea83929494d0 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp @@ -781,7 +781,7 @@ RelocationPass::getObjectEntry(const SharedLibraryAtom *a) { if (obj != _objectMap.end()) return obj->second; - auto oa = new (_file._alloc) ObjectAtom(_file, a); + auto oa = new (_file._alloc) ObjectAtom(_file); oa->addReferenceELF_Mips(R_MIPS_COPY, 0, oa, 0); oa->_name = a->name(); oa->_size = a->size(); diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h index 04cc076fe62d..1a3d6a3ebb3d 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h @@ -62,6 +62,26 @@ public: } } + ErrorOr addAtom(const Atom *atom) override { + // Maintain: + // 1. Set of shared library atoms referenced by regular defined atoms. + // 2. Set of shared library atoms have corresponding R_MIPS_COPY copies. + if (const auto *da = dyn_cast(atom)) + for (const Reference *ref : *da) { + if (ref->kindNamespace() == lld::Reference::KindNamespace::ELF) { + assert(ref->kindArch() == Reference::KindArch::Mips); + if (ref->kindValue() == llvm::ELF::R_MIPS_COPY) + _copiedDynSymNames.insert(atom->name()); + } + } + + return TargetLayout::addAtom(atom); + } + + bool isCopied(const SharedLibraryAtom *sla) const { + return _copiedDynSymNames.count(sla->name()); + } + /// \brief GP offset relative to .got section. uint64_t getGPOffset() const { return 0x7FF0; } @@ -89,6 +109,7 @@ private: MipsPLTSection *_pltSection; llvm::Optional _gpAtom; llvm::Optional _gpDispAtom; + llvm::StringSet<> _copiedDynSymNames; }; /// \brief Mips Runtime file. diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h index 16943e32e5a5..30b1e573a66e 100644 --- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h @@ -180,14 +180,11 @@ template void OutputELFWriter::buildDynamicSymbolTable(const File &file) { ScopedTask task(getDefaultDomain(), "buildDynamicSymbolTable"); for (const auto &sla : file.sharedLibrary()) { - if (!isDynSymEntryRequired(sla)) - continue; - _dynamicSymbolTable->addSymbol(sla, ELF::SHN_UNDEF); + if (isDynSymEntryRequired(sla)) + _dynamicSymbolTable->addSymbol(sla, ELF::SHN_UNDEF); if (isNeededTagRequired(sla)) _soNeeded.insert(sla->loadName()); } - for (const auto &sla : _layout.getCopiedDynAtoms()) - _soNeeded.insert(sla->loadName()); // Never mark the dynamic linker as DT_NEEDED _soNeeded.erase(sys::path::filename(_context.getInterpreter())); for (const auto &loadName : _soNeeded) { diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h index 4a40b33c00ac..a25c1eb4a593 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h @@ -58,15 +58,6 @@ public: } } - bool isCopyRelocation(const Reference &r) const override { - if (r.kindNamespace() != Reference::KindNamespace::ELF) - return false; - assert(r.kindArch() == Reference::KindArch::x86_64); - if (r.kindValue() == llvm::ELF::R_X86_64_COPY) - return true; - return false; - } - virtual bool isPLTRelocation(const DefinedAtom &, const Reference &r) const override { if (r.kindNamespace() != Reference::KindNamespace::ELF) diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp index ca4235983bb2..b7a606691cfa 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp @@ -430,7 +430,7 @@ public: if (obj != _objectMap.end()) return obj->second; - auto oa = new (_file._alloc) ObjectAtom(_file, a); + auto oa = new (_file._alloc) ObjectAtom(_file); // This needs to point to the atom that we just created. oa->addReferenceELF_x86_64(R_X86_64_COPY, 0, oa, 0);