[PATCH] [PECOFF] Fill size field of IMAGE_DATA_DIRECTORY

Ron Ofir ron.ofir at gmail.com
Fri Jul 26 12:34:01 PDT 2013


  Changed assembleRawContent parameter to uint32_t

Hi LegalizeAdulthood, ruiu,

http://llvm-reviews.chandlerc.com/D1228

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1228?vs=3031&id=3037#toc

Files:
  Atoms.h
  IdataPass.h

Index: Atoms.h
===================================================================
--- Atoms.h
+++ Atoms.h
@@ -241,8 +241,8 @@
 // COFF header.
 class COFFDataDirectoryAtom : public COFFLinkerInternalAtom {
 public:
-  COFFDataDirectoryAtom(const File &file, uint64_t ordinal)
-      : COFFLinkerInternalAtom(file, std::vector<uint8_t>(8)),
+  COFFDataDirectoryAtom(const File &file, uint64_t ordinal, uint32_t entrySize)
+      : COFFLinkerInternalAtom(file, assembleRawContent(entrySize)),
         _ordinal(ordinal) {}
 
   virtual uint64_t ordinal() const { return _ordinal; }
@@ -250,6 +250,13 @@
   virtual ContentPermissions permissions() const { return permR__; }
 
 private:
+
+  std::vector<uint8_t> assembleRawContent(uint32_t entrySize) {
+    std::vector<uint8_t> data = std::vector<uint8_t>(8, 0);
+    *(reinterpret_cast<uint32_t *>(&data[4])) = entrySize;
+    return data;
+  }
+
   uint64_t _ordinal;
 };
 
Index: IdataPass.h
===================================================================
--- IdataPass.h
+++ IdataPass.h
@@ -281,12 +281,14 @@
   /// will be set by the writer.
   void createDataDirectoryAtoms(Context &ctx) {
     auto *dir = new (_alloc) coff::COFFDataDirectoryAtom(
-        ctx.file, llvm::COFF::DataDirectoryIndex::IMPORT_TABLE);
+        ctx.file, llvm::COFF::DataDirectoryIndex::IMPORT_TABLE,
+        ctx.importDirectories.size() * ctx.importDirectories[0]->size());
     addDir32NBReloc(dir, ctx.importDirectories[0]);
     ctx.file.addAtom(*dir);
 
     auto *iat = new (_alloc) coff::COFFDataDirectoryAtom(
-        ctx.file, llvm::COFF::DataDirectoryIndex::IAT);
+        ctx.file, llvm::COFF::DataDirectoryIndex::IAT,
+        ctx.importAddressTables.size() * ctx.importAddressTables[0]->size());
     addDir32NBReloc(iat, ctx.importAddressTables[0]);
     ctx.file.addAtom(*iat);
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1228.2.patch
Type: text/x-patch
Size: 1838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130726/015fe3e6/attachment.bin>


More information about the llvm-commits mailing list