[lld] r218345 - [PECOFF] Keep unmangled name in the export table descriptor

Rui Ueyama ruiu at google.com
Tue Sep 23 17:55:15 PDT 2014


Author: ruiu
Date: Tue Sep 23 19:55:15 2014
New Revision: 218345

URL: http://llvm.org/viewvc/llvm-project?rev=218345&view=rev
Log:
[PECOFF] Keep unmangled name in the export table descriptor

The export table descriptor is a data structure to keep information
about the export table. It contains a symbol name, and the name may
or may not be mangled.

We need unmangled names for the export table, so we demangle them
before writing them to the export table.

Obviously this is not a correct round-trip conversion. That could
drop a leading underscore from a symbol because that's
indistinguishable from a mangled name.

What we need to do is to keep unmangled names. This patch does that.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkModuleDef.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=218345&r1=218344&r2=218345&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Tue Sep 23 19:55:15 2014
@@ -370,6 +370,7 @@ static bool parseExport(StringRef option
   if (name.empty())
     return false;
   ret.name = name;
+  ret.externalName = name;
 
   for (;;) {
     if (rest.empty())

Modified: lld/trunk/lib/Driver/WinLinkModuleDef.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkModuleDef.cpp?rev=218345&r1=218344&r2=218345&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkModuleDef.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkModuleDef.cpp Tue Sep 23 19:55:15 2014
@@ -197,13 +197,13 @@ bool Parser::parseExport(PECOFFLinkingCo
     return false;
   }
   result.name = _tok._range;
+  result.externalName = result.name;
 
   consumeToken();
   if (_tok._kind == Kind::equal) {
     consumeToken();
     if (_tok._kind != Kind::identifier)
       return false;
-    result.externalName = result.name;
     result.name = _tok._range;
   } else {
     ungetToken();

Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp?rev=218345&r1=218344&r2=218345&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.cpp Tue Sep 23 19:55:15 2014
@@ -55,12 +55,6 @@ static StringRef removeStdcallSuffix(Str
   return sym;
 }
 
-static StringRef removeLeadingUnderscore(StringRef sym) {
-  if (sym.startswith("_"))
-    return sym.substr(1);
-  return sym;
-}
-
 static bool getExportedAtoms(PECOFFLinkingContext &ctx, MutableFile *file,
                              std::vector<TableEntry> &ret) {
   std::map<StringRef, const DefinedAtom *> definedAtoms;
@@ -79,12 +73,7 @@ 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.
-    StringRef exportName =
-        desc.externalName.empty() ? desc.name : desc.externalName;
-    ret.push_back(TableEntry(exportName, desc.ordinal, atom, desc.noname));
-
-    if (desc.externalName.empty())
-      desc.externalName = removeLeadingUnderscore(atom->name());
+    ret.push_back(TableEntry(desc.externalName, desc.ordinal, atom, desc.noname));
   }
   std::sort(ret.begin(), ret.end(),
             [](const TableEntry &a, const TableEntry &b) {





More information about the llvm-commits mailing list