[PATCH] Revert "[PECOFF] Add atoms to the PassManager file"

Rui Ueyama ruiu at google.com
Wed Oct 30 22:03:43 PDT 2013


  - Added an assertion to catch duplicate atom bug

Hi rnk, shankarke,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2069?vs=5273&id=5282#toc

BRANCH
  master

ARCANIST PROJECT
  lld

Files:
  lib/ReaderWriter/PECOFF/IdataPass.h
  lib/ReaderWriter/PECOFF/WriterPECOFF.cpp

Index: lib/ReaderWriter/PECOFF/IdataPass.h
===================================================================
--- lib/ReaderWriter/PECOFF/IdataPass.h
+++ lib/ReaderWriter/PECOFF/IdataPass.h
@@ -265,20 +265,13 @@
       createImportDirectory(context, loadName, atoms);
     }
 
-    auto nidatom = new (_alloc) NullImportDirectoryAtom(context);
-    context.file.addAtom(*nidatom);
+    // All atoms, including those of tyep NullImportDirectoryAtom, are added to
+    // context.file in the IdataAtom's constructor.
+    new (_alloc) NullImportDirectoryAtom(context);
 
     connectAtoms(context);
     createDataDirectoryAtoms(context);
     replaceSharedLibraryAtoms(context);
-    for (auto id : context.importDirectories)
-      context.file.addAtom(*id);
-    for (auto ilt : context.importLookupTables)
-      context.file.addAtom(*ilt);
-    for (auto iat : context.importAddressTables)
-      context.file.addAtom(*iat);
-    for (auto hna : context.hintNameAtoms)
-      context.file.addAtom(*hna);
   }
 
 private:
@@ -314,7 +307,6 @@
     appendAtoms(atoms, context.importAddressTables);
     appendAtoms(atoms, context.dllNameAtoms);
     appendAtoms(atoms, context.hintNameAtoms);
-
     coff::connectAtomsWithLayoutEdge(atoms);
   }
 
Index: lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
===================================================================
--- lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -802,6 +802,19 @@
       : _PECOFFLinkingContext(context), _numSections(0),
         _imageSizeInMemory(PAGE_SIZE), _imageSizeOnDisk(0) {}
 
+  // Make sure there are no duplicate atoms in the file. RoundTripYAMLPass also
+  // fails if there are duplicate atoms. This is a temporary measure until we
+  // enable the pass for PECOFF port.
+  void verifyFile(const File &linkedFile) {
+#ifndef NDEBUG
+    std::set<const DefinedAtom *> set;
+    for (const DefinedAtom *atom : linkedFile.defined()) {
+      assert(set.count(atom) == 0);
+      set.insert(atom);
+    }
+#endif
+  }
+
   // Create all chunks that consist of the output file.
   void build(const File &linkedFile) {
     // Create file chunks and add them to the list.
@@ -872,6 +885,7 @@
   }
 
   virtual error_code writeFile(const File &linkedFile, StringRef path) {
+    verifyFile(linkedFile);
     this->build(linkedFile);
 
     uint64_t totalSize = _chunks.back()->fileOffset() + _chunks.back()->size();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2069.2.patch
Type: text/x-patch
Size: 2436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131030/7b2e94da/attachment.bin>


More information about the llvm-commits mailing list