Move SimpleDefinedAtom::addReference to DefinedAtom.

Most of the other methods to access Reference's were on DefinedAtom so
this just keeps them all together.

This will be used in a future patch in ObjCPass which needs to add
new references.  The method is virtual because we may add references to
different data structures depending on whether we parsed a macho file or
yaml.

llvm-svn: 259436
This commit is contained in:
Pete Cooper 2016-02-01 23:42:10 +00:00
parent 21923996f8
commit f91b22ce2c
7 changed files with 45 additions and 29 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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; }

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 &section,
}
}
// 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.

View File

@ -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;