[lld] r219246 - [PECOFF] Remove yet another use of _is64

Rui Ueyama ruiu at google.com
Tue Oct 7 15:20:22 PDT 2014


Author: ruiu
Date: Tue Oct  7 17:20:21 2014
New Revision: 219246

URL: http://llvm.org/viewvc/llvm-project?rev=219246&view=rev
Log:
[PECOFF] Remove yet another use of _is64

No functionality change intended.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
    lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/Pass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/Pass.h

Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp?rev=219246&r1=219245&r2=219246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Tue Oct  7 17:20:21 2014
@@ -93,7 +93,7 @@ EdataPass::createAddressTable(const std:
   for (const TableEntry &e : entries) {
     int index = e.ordinal - ordinalBase;
     size_t offset = index * sizeof(export_address_table_entry);
-    addDir32NBReloc(addressTable, e.atom, _is64, offset);
+    addDir32NBReloc(addressTable, e.atom, _ctx.getMachineType(), offset);
   }
   return addressTable;
 }
@@ -110,7 +110,7 @@ EdataPass::createNamePointerTable(const
     auto *stringAtom = new (_alloc) COFFStringAtom(
         _file, _stringOrdinal++, ".edata", ctx.undecorateSymbol(e.exportName));
     file->addAtom(*stringAtom);
-    addDir32NBReloc(table, stringAtom, _is64, offset);
+    addDir32NBReloc(table, stringAtom, _ctx.getMachineType(), offset);
     offset += sizeof(uint32_t);
   }
   return table;
@@ -166,25 +166,25 @@ void EdataPass::perform(std::unique_ptr<
       new (_alloc) COFFStringAtom(_file, _stringOrdinal++, ".edata",
                                   llvm::sys::path::filename(_ctx.outputPath()));
   file->addAtom(*dllName);
-  addDir32NBReloc(table, dllName, _is64,
+  addDir32NBReloc(table, dllName, _ctx.getMachineType(),
                   offsetof(export_directory_table_entry, NameRVA));
 
   EdataAtom *addressTable =
       createAddressTable(entries, ordinalBase, maxOrdinal);
   file->addAtom(*addressTable);
   addDir32NBReloc(
-      table, addressTable, _is64,
+      table, addressTable, _ctx.getMachineType(),
       offsetof(export_directory_table_entry, ExportAddressTableRVA));
 
   EdataAtom *namePointerTable =
       createNamePointerTable(_ctx, namedEntries, file.get());
   file->addAtom(*namePointerTable);
-  addDir32NBReloc(table, namePointerTable, _is64,
+  addDir32NBReloc(table, namePointerTable, _ctx.getMachineType(),
                   offsetof(export_directory_table_entry, NamePointerRVA));
 
   EdataAtom *ordinalTable = createOrdinalTable(namedEntries, ordinalBase);
   file->addAtom(*ordinalTable);
-  addDir32NBReloc(table, ordinalTable, _is64,
+  addDir32NBReloc(table, ordinalTable, _ctx.getMachineType(),
                   offsetof(export_directory_table_entry, OrdinalTableRVA));
 }
 

Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp?rev=219246&r1=219245&r2=219246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp Tue Oct  7 17:20:21 2014
@@ -26,14 +26,13 @@ namespace lld {
 namespace pecoff {
 namespace idata {
 
-IdataAtom::IdataAtom(Context &context, std::vector<uint8_t> data)
+IdataAtom::IdataAtom(IdataContext &context, std::vector<uint8_t> data)
     : COFFLinkerInternalAtom(context.dummyFile,
-                             context.dummyFile.getNextOrdinal(), data),
-      _is64(context.is64) {
+                             context.dummyFile.getNextOrdinal(), data) {
   context.file.addAtom(*this);
 }
 
-HintNameAtom::HintNameAtom(Context &context, uint16_t hint,
+HintNameAtom::HintNameAtom(IdataContext &context, uint16_t hint,
                            StringRef importName)
     : IdataAtom(context, assembleRawContent(hint, importName)),
       _importName(importName) {}
@@ -68,7 +67,7 @@ ImportTableEntryAtom::assembleRawContent
 // array of pointers to hint/name atoms. The array needs to be terminated with
 // the NULL entry.
 void ImportDirectoryAtom::addRelocations(
-    Context &context, StringRef loadName,
+    IdataContext &context, StringRef loadName,
     const std::vector<COFFSharedLibraryAtom *> &sharedAtoms) {
   // Create parallel arrays. The contents of the two are initially the
   // same. The PE/COFF loader overwrites the import address tables with the
@@ -79,20 +78,21 @@ void ImportDirectoryAtom::addRelocations
   std::vector<ImportTableEntryAtom *> importAddressTables =
       createImportTableAtoms(context, sharedAtoms, true, ".idata.a");
 
-  addDir32NBReloc(this, importLookupTables[0], _is64,
+  addDir32NBReloc(this, importLookupTables[0], context.ctx.getMachineType(),
                   offsetof(ImportDirectoryTableEntry, ImportLookupTableRVA));
-  addDir32NBReloc(this, importAddressTables[0], _is64,
+  addDir32NBReloc(this, importAddressTables[0], context.ctx.getMachineType(),
                   offsetof(ImportDirectoryTableEntry, ImportAddressTableRVA));
   auto *atom = new (_alloc)
       COFFStringAtom(context.dummyFile, context.dummyFile.getNextOrdinal(),
                      ".idata", loadName);
   context.file.addAtom(*atom);
-  addDir32NBReloc(this, atom, _is64,
+  addDir32NBReloc(this, atom, context.ctx.getMachineType(),
                   offsetof(ImportDirectoryTableEntry, NameRVA));
 }
 
 std::vector<ImportTableEntryAtom *> ImportDirectoryAtom::createImportTableAtoms(
-    Context &context, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms,
+    IdataContext &context,
+    const std::vector<COFFSharedLibraryAtom *> &sharedAtoms,
     bool shouldAddReference, StringRef sectionName) const {
   std::vector<ImportTableEntryAtom *> ret;
   for (COFFSharedLibraryAtom *atom : sharedAtoms) {
@@ -100,14 +100,14 @@ std::vector<ImportTableEntryAtom *> Impo
     if (atom->importName().empty()) {
       // Import by ordinal
       uint64_t hint = atom->hint();
-      hint |= _is64 ? (uint64_t(1) << 63) : (uint64_t(1) << 31);
+      hint |= context.ctx.is64Bit() ? (uint64_t(1) << 63) : (uint64_t(1) << 31);
       entry = new (_alloc) ImportTableEntryAtom(context, hint, sectionName);
     } else {
       // Import by name
       entry = new (_alloc) ImportTableEntryAtom(context, 0, sectionName);
       HintNameAtom *hintName =
           new (_alloc) HintNameAtom(context, atom->hint(), atom->importName());
-      addDir32NBReloc(entry, hintName, _is64, 0);
+      addDir32NBReloc(entry, hintName, context.ctx.getMachineType(), 0);
     }
     ret.push_back(entry);
     if (shouldAddReference)
@@ -124,8 +124,8 @@ void IdataPass::perform(std::unique_ptr<
   if (file->sharedLibrary().empty())
     return;
 
-  idata::Context context(*file, _dummyFile, _is64);
-  std::map<StringRef, std::vector<COFFSharedLibraryAtom *> > sharedAtoms =
+  idata::IdataContext context(*file, _dummyFile, _ctx);
+  std::map<StringRef, std::vector<COFFSharedLibraryAtom *>> sharedAtoms =
       groupByLoadName(*file);
   for (auto i : sharedAtoms) {
     StringRef loadName = i.first;
@@ -155,7 +155,7 @@ IdataPass::groupByLoadName(MutableFile &
 }
 
 /// Transforms a reference to a COFFSharedLibraryAtom to a real reference.
-void IdataPass::replaceSharedLibraryAtoms(idata::Context &context) {
+void IdataPass::replaceSharedLibraryAtoms(idata::IdataContext &context) {
   for (const DefinedAtom *atom : context.file.defined()) {
     for (const Reference *ref : *atom) {
       const Atom *target = ref->target();

Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h?rev=219246&r1=219245&r2=219246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h Tue Oct  7 17:20:21 2014
@@ -41,12 +41,12 @@ class HintNameAtom;
 class ImportTableEntryAtom;
 
 // A state object of this pass.
-struct Context {
-  Context(MutableFile &f, VirtualFile &g, bool peplus)
-      : file(f), dummyFile(g), is64(peplus) {}
+struct IdataContext {
+  IdataContext(MutableFile &f, VirtualFile &g, const PECOFFLinkingContext &c)
+      : file(f), dummyFile(g), ctx(c) {}
   MutableFile &file;
   VirtualFile &dummyFile;
-  bool is64;
+  const PECOFFLinkingContext &ctx;
 };
 
 /// The root class of all idata atoms.
@@ -58,8 +58,7 @@ public:
   ContentPermissions permissions() const override { return permR__; }
 
 protected:
-  IdataAtom(Context &context, std::vector<uint8_t> data);
-  bool _is64;
+  IdataAtom(IdataContext &context, std::vector<uint8_t> data);
 };
 
 /// A HintNameAtom represents a symbol that will be imported from a DLL at
@@ -72,7 +71,7 @@ protected:
 /// loader can find the symbol quickly.
 class HintNameAtom : public IdataAtom {
 public:
-  HintNameAtom(Context &context, uint16_t hint, StringRef importName);
+  HintNameAtom(IdataContext &context, uint16_t hint, StringRef importName);
 
   StringRef getContentString() { return _importName; }
 
@@ -83,8 +82,9 @@ private:
 
 class ImportTableEntryAtom : public IdataAtom {
 public:
-  ImportTableEntryAtom(Context &ctx, uint64_t contents, StringRef sectionName)
-      : IdataAtom(ctx, assembleRawContent(contents, ctx.is64)),
+  ImportTableEntryAtom(IdataContext &ctx, uint64_t contents,
+                       StringRef sectionName)
+      : IdataAtom(ctx, assembleRawContent(contents, ctx.ctx.is64Bit())),
         _sectionName(sectionName) {}
 
   StringRef customSectionName() const override {
@@ -102,7 +102,7 @@ private:
 /// items. The executable has one ImportDirectoryAtom per one imported DLL.
 class ImportDirectoryAtom : public IdataAtom {
 public:
-  ImportDirectoryAtom(Context &context, StringRef loadName,
+  ImportDirectoryAtom(IdataContext &context, StringRef loadName,
                       const std::vector<COFFSharedLibraryAtom *> &sharedAtoms)
       : IdataAtom(context, std::vector<uint8_t>(20, 0)) {
     addRelocations(context, loadName, sharedAtoms);
@@ -111,11 +111,12 @@ public:
   StringRef customSectionName() const override { return ".idata.d"; }
 
 private:
-  void addRelocations(Context &context, StringRef loadName,
+  void addRelocations(IdataContext &context, StringRef loadName,
                       const std::vector<COFFSharedLibraryAtom *> &sharedAtoms);
 
   std::vector<ImportTableEntryAtom *> createImportTableAtoms(
-      Context &context, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms,
+      IdataContext &context,
+      const std::vector<COFFSharedLibraryAtom *> &sharedAtoms,
       bool shouldAddReference, StringRef sectionName) const;
 
   mutable llvm::BumpPtrAllocator _alloc;
@@ -124,7 +125,7 @@ private:
 /// The last NULL entry in the import directory.
 class NullImportDirectoryAtom : public IdataAtom {
 public:
-  explicit NullImportDirectoryAtom(Context &context)
+  explicit NullImportDirectoryAtom(IdataContext &context)
       : IdataAtom(context, std::vector<uint8_t>(20, 0)) {}
 
   StringRef customSectionName() const override { return ".idata.d"; }
@@ -134,8 +135,7 @@ public:
 
 class IdataPass : public lld::Pass {
 public:
-  IdataPass(const PECOFFLinkingContext &ctx)
-      : _dummyFile(ctx), _is64(ctx.is64Bit()) {}
+  IdataPass(const PECOFFLinkingContext &ctx) : _dummyFile(ctx), _ctx(ctx) {}
 
   void perform(std::unique_ptr<MutableFile> &file) override;
 
@@ -143,14 +143,14 @@ private:
   std::map<StringRef, std::vector<COFFSharedLibraryAtom *> >
   groupByLoadName(MutableFile &file);
 
-  void replaceSharedLibraryAtoms(idata::Context &context);
+  void replaceSharedLibraryAtoms(idata::IdataContext &context);
 
   // A dummy file with which all the atoms created in the pass will be
   // associated. Atoms need to be associated to an input file even if it's not
   // read from a file, so we use this object.
   VirtualFile _dummyFile;
 
-  bool _is64;
+  const PECOFFLinkingContext &_ctx;
   llvm::BumpPtrAllocator _alloc;
 };
 

Modified: lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp?rev=219246&r1=219245&r2=219246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp Tue Oct  7 17:20:21 2014
@@ -43,7 +43,7 @@ LoadConfigAtom::LoadConfigAtom(VirtualFi
           file, file.getNextOrdinal(),
           std::vector<uint8_t>(sizeof(coff_load_configuration32))) {
   addDir32Reloc(
-      this, sxdata, false,
+      this, sxdata, llvm::COFF::IMAGE_FILE_MACHINE_I386,
       offsetof(llvm::object::coff_load_configuration32, SEHandlerTable));
   auto *data = getContents<llvm::object::coff_load_configuration32>();
   data->SEHandlerCount = count;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Pass.cpp?rev=219246&r1=219245&r2=219246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Pass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Pass.cpp Tue Oct  7 17:20:21 2014
@@ -23,25 +23,35 @@ static void addReloc(COFFBaseDefinedAtom
   atom->addReference(std::unique_ptr<COFFReference>(ref));
 }
 
-void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64,
-                   size_t offsetInAtom) {
-  if (is64) {
-    addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64,
-             llvm::COFF::IMAGE_REL_AMD64_ADDR32);
-  } else {
+void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target,
+                   llvm::COFF::MachineTypes machine, size_t offsetInAtom) {
+  switch (machine) {
+  case llvm::COFF::IMAGE_FILE_MACHINE_I386:
     addReloc(atom, target, offsetInAtom, Reference::KindArch::x86,
              llvm::COFF::IMAGE_REL_I386_DIR32);
+    return;
+  case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+    addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64,
+             llvm::COFF::IMAGE_REL_AMD64_ADDR32);
+    return;
+  default:
+    llvm_unreachable("unsupported machine type");
   }
 }
 
-void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64,
-                     size_t offsetInAtom) {
-  if (is64) {
-    addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64,
-             llvm::COFF::IMAGE_REL_AMD64_ADDR32NB);
-  } else {
+void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target,
+                     llvm::COFF::MachineTypes machine, size_t offsetInAtom) {
+  switch (machine) {
+  case llvm::COFF::IMAGE_FILE_MACHINE_I386:
     addReloc(atom, target, offsetInAtom, Reference::KindArch::x86,
              llvm::COFF::IMAGE_REL_I386_DIR32NB);
+    return;
+  case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+    addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64,
+             llvm::COFF::IMAGE_REL_AMD64_ADDR32NB);
+    return;
+  default:
+    llvm_unreachable("unsupported machine type");
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/PECOFF/Pass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Pass.h?rev=219246&r1=219245&r2=219246&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Pass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Pass.h Tue Oct  7 17:20:21 2014
@@ -11,15 +11,16 @@
 #define LLD_READER_WRITER_PE_COFF_PASS_H
 
 #include "Atoms.h"
+#include "llvm/Support/COFF.h"
 
 namespace lld {
 namespace pecoff {
 
-void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64,
-                   size_t offsetInAtom);
+void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target,
+                   llvm::COFF::MachineTypes machine, size_t offsetInAtom);
 
-void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64,
-                     size_t offsetInAtom);
+void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target,
+                     llvm::COFF::MachineTypes machine, size_t offsetInAtom);
 
 } // namespace pecoff
 } // namespace lld





More information about the llvm-commits mailing list