[lld] r259436 - Move SimpleDefinedAtom::addReference to DefinedAtom.
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 15:42:10 PST 2016
Author: pete
Date: Mon Feb 1 17:42:10 2016
New Revision: 259436
URL: http://llvm.org/viewvc/llvm-project?rev=259436&view=rev
Log:
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.
Modified:
lld/trunk/include/lld/Core/DefinedAtom.h
lld/trunk/include/lld/Core/Simple.h
lld/trunk/lib/ReaderWriter/ELF/Atoms.h
lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
lld/trunk/lib/ReaderWriter/MachO/Atoms.h
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Mon Feb 1 17:42:10 2016
@@ -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;
}
Modified: lld/trunk/include/lld/Core/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Simple.h?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Simple.h (original)
+++ lld/trunk/include/lld/Core/Simple.h Mon Feb 1 17:42:10 2016
@@ -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);
Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Mon Feb 1 17:42:10 2016
@@ -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; }
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Mon Feb 1 17:42:10 2016
@@ -1384,7 +1384,8 @@ void ArchHandler_arm::appendSectionReloc
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);
}
}
Modified: lld/trunk/lib/ReaderWriter/MachO/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/Atoms.h?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/Atoms.h Mon Feb 1 17:42:10 2016
@@ -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;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Mon Feb 1 17:42:10 2016
@@ -364,9 +364,9 @@ std::error_code processSymboledSection(D
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 Sect
}
}
// 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
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
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
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.
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=259436&r1=259435&r2=259436&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Mon Feb 1 17:42:10 2016
@@ -887,6 +887,16 @@ template <> struct MappingTraits<const l
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;
More information about the llvm-commits
mailing list