diff options
-rw-r--r-- | lld/include/lld/Core/DefinedAtom.h | 11 | ||||
-rw-r--r-- | lld/include/lld/Core/Simple.h | 5 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/ELF/Atoms.h | 2 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp | 3 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/MachO/Atoms.h | 9 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | 34 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp | 10 |
7 files changed, 45 insertions, 29 deletions
diff --git a/lld/include/lld/Core/DefinedAtom.h b/lld/include/lld/Core/DefinedAtom.h index f0cf6089b5a..baca7ee395d 100644 --- a/lld/include/lld/Core/DefinedAtom.h +++ b/lld/include/lld/Core/DefinedAtom.h @@ -11,11 +11,12 @@ #define LLD_CORE_DEFINED_ATOM_H #include "lld/Core/Atom.h" +#include "lld/Core/Reference.h" #include "lld/Core/LLVM.h" +#include "llvm/Support/ErrorHandling.h" namespace lld { class File; -class Reference; /// \brief The fundamental unit of linking. /// @@ -331,6 +332,14 @@ public: /// \brief Returns an iterator to the end of this Atom's References. virtual reference_iterator end() const = 0; + /// Adds a reference to this atom. + virtual void addReference(Reference::KindNamespace ns, + Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t off, + const Atom *target, Reference::Addend a) { + llvm_unreachable("Subclass does not permit adding references"); + } + static bool classof(const Atom *a) { return a->definition() == definitionRegular; } diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h index 976b15c1fcf..44dd21cf040 100644 --- a/lld/include/lld/Core/Simple.h +++ b/lld/include/lld/Core/Simple.h @@ -257,9 +257,10 @@ public: it = reinterpret_cast<const void*>(next); } - void addReference(Reference::KindNamespace ns, Reference::KindArch arch, + void addReference(Reference::KindNamespace ns, + Reference::KindArch arch, Reference::KindValue kindValue, uint64_t off, - const Atom *target, Reference::Addend a) { + const Atom *target, Reference::Addend a) override { assert(target && "trying to create reference to nothing"); auto node = new (_file.allocator()) SimpleReference(ns, arch, kindValue, off, target, a); diff --git a/lld/lib/ReaderWriter/ELF/Atoms.h b/lld/lib/ReaderWriter/ELF/Atoms.h index 390c0e16baf..cc425631d82 100644 --- a/lld/lib/ReaderWriter/ELF/Atoms.h +++ b/lld/lib/ReaderWriter/ELF/Atoms.h @@ -170,6 +170,8 @@ public: DefinedAtom::reference_iterator end() const override; const Reference *derefIterator(const void *It) const override; void incrementIterator(const void *&It) const override; + + using DefinedAtom::addReference; void addReference(ELFReference<ELFT> *reference); virtual void setOrdinal(uint64_t ord) { _ordinal = ord; } diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp index 4e15a2d434c..38f36096539 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp @@ -1384,7 +1384,8 @@ void ArchHandler_arm::appendSectionRelocations( void ArchHandler_arm::addAdditionalReferences(MachODefinedAtom &atom) { if (atom.isThumb()) { - atom.addReference(0, modeThumbCode, &atom, 0, Reference::KindArch::ARM); + atom.addReference(Reference::KindNamespace::mach_o, + Reference::KindArch::ARM, modeThumbCode, 0, &atom, 0); } } diff --git a/lld/lib/ReaderWriter/MachO/Atoms.h b/lld/lib/ReaderWriter/MachO/Atoms.h index 9f2e5acad99..f50a6cffe18 100644 --- a/lld/lib/ReaderWriter/MachO/Atoms.h +++ b/lld/lib/ReaderWriter/MachO/Atoms.h @@ -61,15 +61,6 @@ public: bool isThumb() const { return _thumb; } - void addReference(uint32_t offsetInAtom, uint16_t relocType, - const Atom *target, Reference::Addend addend, - Reference::KindArch arch = Reference::KindArch::x86_64, - Reference::KindNamespace ns - = Reference::KindNamespace::mach_o) { - SimpleDefinedAtom::addReference(ns, arch, relocType, offsetInAtom, target, - addend); - } - private: const StringRef _name; const ArrayRef<uint8_t> _content; diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index c7f1e3555d6..80f2038d98b 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -364,9 +364,9 @@ std::error_code processSymboledSection(DefinedAtom::ContentType atomType, file.eachAtomInSection(section, [&](MachODefinedAtom *atom, uint64_t offset)->void { if (prevAtom) - prevAtom->addReference(0, Reference::kindLayoutAfter, atom, 0, + prevAtom->addReference(Reference::KindNamespace::all, Reference::KindArch::all, - Reference::KindNamespace::all); + Reference::kindLayoutAfter, 0, atom, 0); prevAtom = atom; }); } @@ -663,8 +663,9 @@ std::error_code convertRelocs(const Section §ion, } } // Instantiate an lld::Reference object and add to its atom. - inAtom->addReference(offsetInAtom, kind, target, addend, - handler.kindArch()); + inAtom->addReference(Reference::KindNamespace::mach_o, + handler.kindArch(), + kind, offsetInAtom, target, addend); } return std::error_code(); @@ -777,8 +778,8 @@ static std::error_code processFDE(const NormalizedFile &normalizedFile, Reference::Addend addend; const MachODefinedAtom *cie = findAtomCoveringAddress(normalizedFile, file, cieAddress, &addend); - atom->addReference(cieFieldInFDE, handler.unwindRefToCIEKind(), cie, - addend, handler.kindArch()); + atom->addReference(Reference::KindNamespace::mach_o, handler.kindArch(), + handler.unwindRefToCIEKind(), cieFieldInFDE, cie, addend); assert(cie && cie->contentType() == DefinedAtom::typeCFI && !addend && "FDE's CIE field does not point at the start of a CIE."); @@ -798,8 +799,9 @@ static std::error_code processFDE(const NormalizedFile &normalizedFile, const Atom *func = findAtomCoveringAddress(normalizedFile, file, rangeStart, &addend); - atom->addReference(rangeFieldInFDE, handler.unwindRefToFunctionKind(), - func, addend, handler.kindArch()); + atom->addReference(Reference::KindNamespace::mach_o, handler.kindArch(), + handler.unwindRefToFunctionKind(), rangeFieldInFDE, func, + addend); // Handle the augmentation data if there is any. if (cieInfo._augmentationDataPresent) { @@ -824,9 +826,9 @@ static std::error_code processFDE(const NormalizedFile &normalizedFile, lsdaFromFDE; const Atom *lsda = findAtomCoveringAddress(normalizedFile, file, lsdaStart, &addend); - atom->addReference(augmentationDataFieldInFDE, + atom->addReference(Reference::KindNamespace::mach_o, handler.kindArch(), handler.unwindRefToFunctionKind(), - lsda, addend, handler.kindArch()); + augmentationDataFieldInFDE, lsda, addend); } } @@ -1034,9 +1036,9 @@ normalizedObjectToAtoms(MachOFile *file, + ") crosses atom boundary.")); } // Add reference that marks start of data-in-code. - atom->addReference(offsetInAtom, - handler->dataInCodeTransitionStart(*atom), atom, - entry.kind, handler->kindArch()); + atom->addReference(Reference::KindNamespace::mach_o, handler->kindArch(), + handler->dataInCodeTransitionStart(*atom), + offsetInAtom, atom, entry.kind); // Peek at next entry, if it starts where this one ends, skip ending ref. if (nextIndex < normalizedFile.dataInCode.size()) { @@ -1050,9 +1052,9 @@ normalizedObjectToAtoms(MachOFile *file, continue; // Add reference that marks end of data-in-code. - atom->addReference(offsetInAtom+entry.length, - handler->dataInCodeTransitionEnd(*atom), atom, 0, - handler->kindArch()); + atom->addReference(Reference::KindNamespace::mach_o, handler->kindArch(), + handler->dataInCodeTransitionEnd(*atom), + offsetInAtom+entry.length, atom, 0); } // Cache some attributes on the file for use later. diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 3e4f51882c6..528e80c88cb 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -887,6 +887,16 @@ template <> struct MappingTraits<const lld::DefinedAtom *> { it = reinterpret_cast<const void *>(index); } + void addReference(Reference::KindNamespace ns, + Reference::KindArch arch, + Reference::KindValue kindValue, uint64_t off, + const Atom *target, Reference::Addend a) override { + assert(target && "trying to create reference to nothing"); + auto node = new (file().allocator()) SimpleReference(ns, arch, kindValue, + off, target, a); + _references.push_back(node); + } + const lld::File &_file; StringRef _name; StringRef _refName; |