Remove COFFReference and use SimpleReference instead.
authorRui Ueyama <ruiu@google.com>
Mon, 9 Mar 2015 22:18:51 +0000 (22:18 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 9 Mar 2015 22:18:51 +0000 (22:18 +0000)
SimpleReference, which is defined in Core, provides the same functionality
as COFFReference does, so we don't need a custom class.

llvm-svn: 231715

lld/lib/ReaderWriter/PECOFF/Atoms.h
lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
lld/lib/ReaderWriter/PECOFF/Pass.cpp
lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp

index af7e60a..6fd2653 100644 (file)
@@ -20,34 +20,6 @@ namespace lld {
 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)
@@ -103,7 +75,7 @@ public:
 
   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));
   }
 
@@ -134,7 +106,7 @@ private:
   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
@@ -164,10 +136,10 @@ public:
   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:
@@ -178,7 +150,7 @@ 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.
@@ -345,10 +317,10 @@ private:
 
 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
index caffc3e..5a9c829 100644 (file)
@@ -49,13 +49,19 @@ public:
                 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);
   };
index 89b63e9..ed73198 100644 (file)
@@ -19,8 +19,8 @@ namespace pecoff {
 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,
index b044b45..40b4cbd 100644 (file)
@@ -14,6 +14,7 @@
 #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"
@@ -42,7 +43,6 @@ using lld::pecoff::COFFAbsoluteAtom;
 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;
@@ -834,8 +834,9 @@ std::error_code FileCOFF::addRelocationReference(
   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();
 }
 
@@ -1003,8 +1004,9 @@ std::error_code FileCOFF::maybeCreateSXDataAtoms() {
       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);
index b2c9b96..8c96413 100644 (file)
@@ -164,25 +164,30 @@ const uint8_t FuncAtomContentARMNT[] = {
 
 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.