[lld] r222452 - [PECOFF] Sort export table properly.

Rui Ueyama ruiu at google.com
Thu Nov 20 13:05:05 PST 2014


Author: ruiu
Date: Thu Nov 20 15:05:05 2014
New Revision: 222452

URL: http://llvm.org/viewvc/llvm-project?rev=222452&view=rev
Log:
[PECOFF] Sort export table properly.

Export table entries need to be sorted in ASCII-betical order,
so that the loader can find an entry for a function by binary search.

We sorted the entries by its mangled names. That can be different
from their exported names. As a result, LLD produces incorrect export
table, from which the loader complains that a function that actually
exists in a DLL cannot be found.

This patch fixes that issue.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
    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=222452&r1=222451&r2=222452&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Thu Nov 20 15:05:05 2014
@@ -35,7 +35,7 @@ static void assignOrdinals(PECOFFLinking
   std::sort(exports.begin(), exports.end(),
             [](const PECOFFLinkingContext::ExportDesc &a,
                const PECOFFLinkingContext::ExportDesc &b) {
-    return a.name.compare(b.name) < 0;
+    return a.getExternalName().compare(b.getExternalName()) < 0;
   });
 
   int nextOrdinal = (maxOrdinal == -1) ? 1 : (maxOrdinal + 1);
@@ -62,13 +62,14 @@ static bool getExportedAtoms(PECOFFLinki
     // One can export a symbol with a different name than the symbol
     // name used in DLL. If such name is specified, use it in the
     // .edata section.
-    ret.push_back(TableEntry(desc.getExternalName(), desc.ordinal, atom,
-                             desc.noname));
+    ret.push_back(TableEntry(ctx.undecorateSymbol(desc.getExternalName()),
+                             desc.ordinal, atom, desc.noname));
   }
   std::sort(ret.begin(), ret.end(),
             [](const TableEntry &a, const TableEntry &b) {
     return a.exportName.compare(b.exportName) < 0;
   });
+
   return true;
 }
 
@@ -107,7 +108,7 @@ EdataPass::createNamePointerTable(const
   size_t offset = 0;
   for (const TableEntry &e : entries) {
     auto *stringAtom = new (_alloc) COFFStringAtom(
-        _file, _stringOrdinal++, ".edata", ctx.undecorateSymbol(e.exportName));
+        _file, _stringOrdinal++, ".edata", e.exportName);
     file->addAtom(*stringAtom);
     addDir32NBReloc(table, stringAtom, _ctx.getMachineType(), offset);
     offset += sizeof(uint32_t);

Modified: lld/trunk/test/pecoff/export.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/export.test?rev=222452&r1=222451&r2=222452&view=diff
==============================================================================
--- lld/trunk/test/pecoff/export.test (original)
+++ lld/trunk/test/pecoff/export.test Thu Nov 20 15:05:05 2014
@@ -82,5 +82,6 @@ DUP-NOT:  exportfn3 at 256
 EQUAL:      Export Table:
 EQUAL:      DLL name: export.test.tmp1.dll
 EQUAL:       Ordinal      RVA  Name
-EQUAL-NEXT:       1   0x2008  f1
-EQUAL-NEXT:       2   0x2010  f2
+EQUAL-NEXT:       1   0x2010  exportfn3 at 256
+EQUAL-NEXT:       2   0x2008  f1
+EQUAL-NEXT:       3   0x2010  f2





More information about the llvm-commits mailing list