[lld] r197371 - [PECOFF] Support export-only-by-ordinal exports.

Rui Ueyama ruiu at google.com
Mon Dec 16 01:02:44 PST 2013


Author: ruiu
Date: Mon Dec 16 03:02:43 2013
New Revision: 197371

URL: http://llvm.org/viewvc/llvm-project?rev=197371&view=rev
Log:
[PECOFF] Support export-only-by-ordinal exports.

If NONAME option is given for an export, that symbol will be exported only by
its ordinal. LLD will not emit the symbol name to the export table.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h
    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=197371&r1=197370&r2=197371&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Mon Dec 16 03:02:43 2013
@@ -46,7 +46,7 @@ static bool getExportedAtoms(const PECOF
       return false;
     }
     const DefinedAtom *atom = it->second;
-    ret.push_back(TableEntry(desc.name, desc.ordinal, atom));
+    ret.push_back(TableEntry(desc.name, desc.ordinal, atom, desc.noname));
   }
   std::sort(ret.begin(), ret.end(), compare);
   return true;
@@ -109,7 +109,7 @@ EdataPass::createNamePointerTable(const
 }
 
 edata::EdataAtom *EdataPass::createExportDirectoryTable(
-    const std::vector<edata::TableEntry> &entries, int ordinalBase,
+    const std::vector<edata::TableEntry> &namedEntries, int ordinalBase,
     int maxOrdinal) {
   EdataAtom *ret =
       new (_alloc) EdataAtom(_file, sizeof(export_directory_table_entry));
@@ -117,7 +117,7 @@ edata::EdataAtom *EdataPass::createExpor
   data->TimeDateStamp = time(nullptr);
   data->OrdinalBase = ordinalBase;
   data->AddressTableEntries = maxOrdinal - ordinalBase + 1;
-  data->NumberOfNamePointers = entries.size();
+  data->NumberOfNamePointers = namedEntries.size();
   return ret;
 }
 
@@ -143,8 +143,13 @@ void EdataPass::perform(std::unique_ptr<
   int ordinalBase, maxOrdinal;
   llvm::tie(ordinalBase, maxOrdinal) = assignOrdinals(entries);
 
+  std::vector<TableEntry> namedEntries;
+  for (TableEntry &e : entries)
+    if (!e.noname)
+      namedEntries.push_back(e);
+
   EdataAtom *table =
-      createExportDirectoryTable(entries, ordinalBase, maxOrdinal);
+      createExportDirectoryTable(namedEntries, ordinalBase, maxOrdinal);
   file->addAtom(*table);
 
   COFFStringAtom *dllName =
@@ -161,12 +166,12 @@ void EdataPass::perform(std::unique_ptr<
                                                 ExportAddressTableRVA));
 
   EdataAtom *namePointerTable =
-      createNamePointerTable(_ctx, entries, file.get());
+      createNamePointerTable(_ctx, namedEntries, file.get());
   file->addAtom(*namePointerTable);
   addDir32NBReloc(table, namePointerTable,
                   offsetof(export_directory_table_entry, NamePointerRVA));
 
-  EdataAtom *ordinalTable = createOrdinalTable(entries, ordinalBase);
+  EdataAtom *ordinalTable = createOrdinalTable(namedEntries, ordinalBase);
   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=197371&r1=197370&r2=197371&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h Mon Dec 16 03:02:43 2013
@@ -36,11 +36,13 @@ namespace pecoff {
 namespace edata {
 
 struct TableEntry {
-  TableEntry(StringRef exportName, int ordinal, const DefinedAtom *atom)
-      : exportName(exportName), ordinal(ordinal), atom(atom) {}
+  TableEntry(StringRef exportName, int ordinal, const DefinedAtom *atom,
+             bool noname)
+      : exportName(exportName), ordinal(ordinal), atom(atom), noname(noname) {}
   StringRef exportName;
   int ordinal;
   const DefinedAtom *atom;
+  bool noname;
 };
 
 /// The root class of all edata atoms.
@@ -71,7 +73,7 @@ public:
 
 private:
   edata::EdataAtom *
-  createExportDirectoryTable(const std::vector<edata::TableEntry> &entries,
+  createExportDirectoryTable(const std::vector<edata::TableEntry> &namedEntries,
                              int ordinalBase, int maxOrdinal);
 
   edata::EdataAtom *

Modified: lld/trunk/test/pecoff/export.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/export.test?rev=197371&r1=197370&r2=197371&view=diff
==============================================================================
--- lld/trunk/test/pecoff/export.test (original)
+++ lld/trunk/test/pecoff/export.test Mon Dec 16 03:02:43 2013
@@ -25,3 +25,15 @@ CHECK2-NEXT:  1030 51100000 5b100000 000
 CHECK2-NEXT:  1040 72742e74 6573742e 746d7032 2e646c6c
 CHECK2-NEXT:  1050 00657870 6f727466 6e310065 78706f72
 CHECK2-NEXT:  1060 74666e32 00
+
+# RUN: lld -flavor link /out:%t3.dll /dll /subsystem:console /entry:_init \
+# RUN:   /export:exportfn1, at 5,noname /export:exportfn2 -- %t.obj
+# RUN: llvm-objdump -s %t3.dll | FileCheck -check-prefix=CHECK3 %s
+
+CHECK3:      Contents of section .edata:
+CHECK3-NEXT:  1000 00000000 {{........}} 00000000 36100000
+CHECK3-NEXT:  1010 05000000 02000000 01000000 28100000
+CHECK3-NEXT:  1020 30100000 34100000 08200000 10200000
+CHECK3-NEXT:  1030 4b100000 01006578 706f7274 2e746573
+CHECK3-NEXT:  1040 742e746d 70332e64 6c6c0065 78706f72
+CHECK3-NEXT:  1050 74666e32 00





More information about the llvm-commits mailing list