[lld] r197306 - [PECOFF] Simplify EdataPass by sorting atoms from the beginning.

Rui Ueyama ruiu at google.com
Fri Dec 13 19:54:15 PST 2013


Author: ruiu
Date: Fri Dec 13 21:54:15 2013
New Revision: 197306

URL: http://llvm.org/viewvc/llvm-project?rev=197306&view=rev
Log:
[PECOFF] Simplify EdataPass by sorting atoms from the beginning.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h
    lld/trunk/test/pecoff/Inputs/export.obj.yaml
    lld/trunk/test/pecoff/export.test

Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp?rev=197306&r1=197305&r2=197306&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Fri Dec 13 21:54:15 2013
@@ -24,6 +24,10 @@ using llvm::object::export_directory_tab
 namespace lld {
 namespace pecoff {
 
+static bool compare(const DefinedAtom *a, const DefinedAtom *b) {
+  return a->name().compare(b->name()) < 0;
+}
+
 static bool getExportedAtoms(const PECOFFLinkingContext &ctx, MutableFile *file,
                              std::vector<const DefinedAtom *> &ret) {
   std::map<StringRef, const DefinedAtom *> definedAtoms;
@@ -40,13 +44,10 @@ static bool getExportedAtoms(const PECOF
     const DefinedAtom *atom = it->second;
     ret.push_back(atom);
   }
+  std::sort(ret.begin(), ret.end(), compare);
   return true;
 }
 
-static bool compare(const DefinedAtom *a, const DefinedAtom *b) {
-  return a->name().compare(b->name()) < 0;
-}
-
 edata::EdataAtom *
 EdataPass::createAddressTable(const std::vector<const DefinedAtom *> &atoms) {
   EdataAtom *addressTable = new (_alloc)
@@ -89,20 +90,12 @@ edata::EdataAtom *EdataPass::createExpor
 }
 
 edata::EdataAtom *EdataPass::createOrdinalTable(
-    const std::vector<const DefinedAtom *> &atoms,
-    const std::vector<const DefinedAtom *> &sortedAtoms) {
+    const std::vector<const DefinedAtom *> &atoms) {
   EdataAtom *ret =
       new (_alloc) EdataAtom(_file, sizeof(uint16_t) * atoms.size());
   uint16_t *data = ret->getContents<uint16_t>();
-
-  std::map<const DefinedAtom *, size_t> ordinals;
-  size_t ordinal = 0;
-  for (const DefinedAtom *atom : atoms)
-    ordinals[atom] = ordinal++;
-
-  size_t index = 0;
-  for (const DefinedAtom *atom : sortedAtoms)
-    data[index++] = ordinals[atom];
+  for (size_t i = 0, e = atoms.size(); i < e; ++i)
+    data[i] = i;
   return ret;
 }
 
@@ -128,14 +121,12 @@ void EdataPass::perform(std::unique_ptr<
   addDir32NBReloc(table, addressTable, offsetof(export_directory_table_entry,
                                                 ExportAddressTableRVA));
 
-  std::vector<const DefinedAtom *> sortedAtoms(atoms);
-  std::sort(sortedAtoms.begin(), sortedAtoms.end(), compare);
-  EdataAtom *namePointerTable = createNamePointerTable(sortedAtoms, file.get());
+  EdataAtom *namePointerTable = createNamePointerTable(atoms, file.get());
   file->addAtom(*namePointerTable);
   addDir32NBReloc(table, namePointerTable,
                   offsetof(export_directory_table_entry, NamePointerRVA));
 
-  EdataAtom *ordinalTable = createOrdinalTable(atoms, sortedAtoms);
+  EdataAtom *ordinalTable = createOrdinalTable(atoms);
   file->addAtom(*ordinalTable);
   addDir32NBReloc(table, ordinalTable,
                   offsetof(export_directory_table_entry, OrdinalTableRVA));

Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h?rev=197306&r1=197305&r2=197306&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h Fri Dec 13 21:54:15 2013
@@ -69,8 +69,7 @@ private:
   createNamePointerTable(const std::vector<const DefinedAtom *> &atoms,
                          MutableFile *file);
   edata::EdataAtom *
-  createOrdinalTable(const std::vector<const DefinedAtom *> &atoms,
-                     const std::vector<const DefinedAtom *> &sortedAtoms);
+  createOrdinalTable(const std::vector<const DefinedAtom *> &atoms);
 
   const PECOFFLinkingContext &_ctx;
   VirtualFile _file;

Modified: lld/trunk/test/pecoff/Inputs/export.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/export.obj.yaml?rev=197306&r1=197305&r2=197306&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/export.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/export.obj.yaml Fri Dec 13 21:54:15 2013
@@ -22,10 +22,16 @@ symbols:
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_NULL
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
-  - Name:            _exportfn
+  - Name:            _exportfn1
     Value:           8
     SectionNumber:   1
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            _exportfn2
+    Value:           16
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
 ...

Modified: lld/trunk/test/pecoff/export.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/export.test?rev=197306&r1=197305&r2=197306&view=diff
==============================================================================
--- lld/trunk/test/pecoff/export.test (original)
+++ lld/trunk/test/pecoff/export.test Fri Dec 13 21:54:15 2013
@@ -1,12 +1,14 @@
 # RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj
 #
 # RUN: lld -flavor link /out:%t.dll /dll /subsystem:console /entry:_init \
-# RUN:   /export:exportfn -- %t.obj
+# RUN:   /export:exportfn1 /export:exportfn2 -- %t.obj
 # RUN: llvm-objdump -s %t.dll | FileCheck %s
 
 CHECK:      Contents of section .edata:
-CHECK-NEXT:  1000 00000000 {{........}} 00000000 32100000
-CHECK-NEXT:  1010 01000000 01000000 01000000 28100000
-CHECK-NEXT:  1020 2c100000 30100000 08200000 46100000
-CHECK-NEXT:  1030 00006578 706f7274 2e746573 742e746d
-CHECK-NEXT:  1040 702e646c 6c005f65 78706f72 74666e00
+CHECK-NEXT:  1000 00000000 {{........}} 00000000 3c100000
+CHECK-NEXT:  1010 01000000 02000000 02000000 28100000
+CHECK-NEXT:  1020 30100000 38100000 08200000 10200000
+CHECK-NEXT:  1030 50100000 5b100000 00000100 6578706f
+CHECK-NEXT:  1040 72742e74 6573742e 746d702e 646c6c00
+CHECK-NEXT:  1050 5f657870 6f727466 6e31005f 6578706f
+CHECK-NEXT:  1060 7274666e 3200





More information about the llvm-commits mailing list