namespace pecoff {
class COFFDefinedAtom;
-/// A COFFReference represents relocation information for an atom. For
-/// example, if atom X has a reference to atom Y with offsetInAtom=8, that
-/// means that the address starting at 8th byte of the content of atom X needs
-/// to be fixed up so that the address points to atom Y's address.
-class COFFReference final : public Reference {
-public:
- COFFReference(const Atom *target, uint32_t offsetInAtom, uint16_t relocType,
- Reference::KindArch arch,
- Reference::KindNamespace ns = Reference::KindNamespace::COFF)
- : Reference(ns, arch, relocType), _target(target),
- _offsetInAtom(offsetInAtom) {}
-
- const Atom *target() const override { return _target; }
- void setTarget(const Atom *newAtom) override { _target = newAtom; }
-
- // Addend is a value to be added to the relocation target. For example, if
- // target=AtomX and addend=4, the relocation address will become the address
- // of AtomX + 4. COFF does not support that sort of relocation, thus addend
- // is always zero.
- Addend addend() const override { return 0; }
- void setAddend(Addend) override {}
- uint64_t offsetInAtom() const override { return _offsetInAtom; }
-
-private:
- const Atom *_target;
- uint32_t _offsetInAtom;
-};
-
class COFFAbsoluteAtom : public AbsoluteAtom {
public:
COFFAbsoluteAtom(const File &f, StringRef name, Scope scope, uint64_t value)
Kind getKind() const { return _kind; }
- void addReference(std::unique_ptr<COFFReference> reference) {
+ void addReference(std::unique_ptr<SimpleReference> reference) {
_references.push_back(std::move(reference));
}
const File &_file;
StringRef _name;
Kind _kind;
- std::vector<std::unique_ptr<COFFReference> > _references;
+ std::vector<std::unique_ptr<SimpleReference>> _references;
};
/// This is the root class of the atom read from a file. This class have two
Alignment alignment() const override { return _alignment; }
void addAssociate(const DefinedAtom *other) {
- auto *ref = new COFFReference(other, 0, lld::Reference::kindAssociate,
- Reference::KindArch::all,
- Reference::KindNamespace::all);
- addReference(std::unique_ptr<COFFReference>(ref));
+ auto *ref = new SimpleReference(Reference::KindNamespace::all,
+ Reference::KindArch::all,
+ lld::Reference::kindAssociate, 0, other, 0);
+ addReference(std::unique_ptr<SimpleReference>(ref));
}
private:
ContentPermissions _permissions;
uint64_t _ordinal;
Alignment _alignment;
- std::vector<std::unique_ptr<COFFReference> > _references;
+ std::vector<std::unique_ptr<SimpleReference>> _references;
};
// A COFFDefinedAtom represents an atom read from a file and has contents.
template <typename T, typename U>
void addLayoutEdge(T *a, U *b, uint32_t which) {
- auto ref = new COFFReference(nullptr, 0, which, Reference::KindArch::all,
- Reference::KindNamespace::all);
- ref->setTarget(b);
- a->addReference(std::unique_ptr<COFFReference>(ref));
+ auto ref = new SimpleReference(Reference::KindNamespace::all,
+ Reference::KindArch::all,
+ which, 0, b, 0);
+ a->addReference(std::unique_ptr<SimpleReference>(ref));
}
} // namespace pecoff
bool is64)
: SimpleFile(defsym), _undefined(*this, undefsym),
_defined(*this, defsym, ordinal) {
- auto *ref = is64 ? new COFFReference(&_undefined, 0,
- llvm::COFF::IMAGE_REL_AMD64_ADDR32,
- Reference::KindArch::x86_64)
- : new COFFReference(&_undefined, 0,
- llvm::COFF::IMAGE_REL_I386_DIR32,
- Reference::KindArch::x86);
- _defined.addReference(std::unique_ptr<COFFReference>(ref));
+ SimpleReference *ref;
+ if (is64) {
+ ref = new SimpleReference(Reference::KindNamespace::COFF,
+ Reference::KindArch::x86_64,
+ llvm::COFF::IMAGE_REL_AMD64_ADDR32,
+ 0, &_undefined, 0);
+ } else {
+ ref = new SimpleReference(Reference::KindNamespace::COFF,
+ Reference::KindArch::x86,
+ llvm::COFF::IMAGE_REL_I386_DIR32,
+ 0, &_undefined, 0);
+ }
+ _defined.addReference(std::unique_ptr<SimpleReference>(ref));
addAtom(_defined);
addAtom(_undefined);
};
static void addReloc(COFFBaseDefinedAtom *atom, const Atom *target,
size_t offsetInAtom, Reference::KindArch arch,
Reference::KindValue relType) {
- atom->addReference(llvm::make_unique<COFFReference>(
- target, offsetInAtom, relType, arch));
+ atom->addReference(llvm::make_unique<SimpleReference>(
+ Reference::KindNamespace::COFF, arch, relType, offsetInAtom, target, 0));
}
void addDir64Reloc(COFFBaseDefinedAtom *atom, const Atom *target,
#include "lld/Driver/Driver.h"
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Casting.h"
using lld::pecoff::COFFBSSAtom;
using lld::pecoff::COFFDefinedAtom;
using lld::pecoff::COFFDefinedFileAtom;
-using lld::pecoff::COFFReference;
using lld::pecoff::COFFUndefinedAtom;
using llvm::object::coff_aux_section_definition;
using llvm::object::coff_aux_weak_external;
uint32_t offsetInAtom;
if (std::error_code ec = findAtomAt(section, itemAddress, atom, offsetInAtom))
return ec;
- atom->addReference(std::unique_ptr<COFFReference>(
- new COFFReference(targetAtom, offsetInAtom, rel->Type, _referenceArch)));
+ atom->addReference(llvm::make_unique<SimpleReference>(
+ Reference::KindNamespace::COFF, _referenceArch, rel->Type, offsetInAtom,
+ targetAtom, 0));
return std::error_code();
}
llvm_unreachable("unsupported machine type");
}
- atom->addReference(std::unique_ptr<COFFReference>(new COFFReference(
- handlerFunc, offsetInAtom, rtype, _referenceArch)));
+ atom->addReference(llvm::make_unique<SimpleReference>(
+ Reference::KindNamespace::COFF, _referenceArch, rtype, offsetInAtom,
+ handlerFunc, 0));
}
_definedAtoms._atoms.push_back(atom);
static void setJumpInstTarget(COFFLinkerInternalAtom *src, const Atom *dst,
int off, MachineTypes machine) {
- COFFReference *ref;
+ SimpleReference *ref;
switch (machine) {
default: llvm::report_fatal_error("unsupported machine type");
case llvm::COFF::IMAGE_FILE_MACHINE_I386:
- ref = new COFFReference(dst, off, llvm::COFF::IMAGE_REL_I386_DIR32,
- Reference::KindArch::x86);
+ ref = new SimpleReference(Reference::KindNamespace::COFF,
+ Reference::KindArch::x86,
+ llvm::COFF::IMAGE_REL_I386_DIR32,
+ off, dst, 0);
break;
case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
- ref = new COFFReference(dst, off, llvm::COFF::IMAGE_REL_AMD64_REL32,
- Reference::KindArch::x86_64);
+ ref = new SimpleReference(Reference::KindNamespace::COFF,
+ Reference::KindArch::x86_64,
+ llvm::COFF::IMAGE_REL_AMD64_REL32,
+ off, dst, 0);
break;
case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
- ref = new COFFReference(dst, off, llvm::COFF::IMAGE_REL_ARM_MOV32T,
- Reference::KindArch::ARM);
+ ref = new SimpleReference(Reference::KindNamespace::COFF,
+ Reference::KindArch::ARM,
+ llvm::COFF::IMAGE_REL_ARM_MOV32T,
+ off, dst, 0);
break;
}
-
- src->addReference(std::unique_ptr<COFFReference>(ref));
+ src->addReference(std::unique_ptr<SimpleReference>(ref));
}
/// The defined atom for jump table.