[lld] r241854 - COFF: Fix import symbol name mangling.

Rui Ueyama ruiu at google.com
Thu Jul 9 13:22:42 PDT 2015


Author: ruiu
Date: Thu Jul  9 15:22:41 2015
New Revision: 241854

URL: http://llvm.org/viewvc/llvm-project?rev=241854&view=rev
Log:
COFF: Fix import symbol name mangling.

For IMPORT_NAME_NOPREFIX symbols, we should remove only one prefix character.

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/test/COFF/Inputs/imports-mangle.lib
    lld/trunk/test/COFF/imports-mangle.test

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=241854&r1=241853&r2=241854&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Thu Jul  9 15:22:41 2015
@@ -249,6 +249,12 @@ MachineTypes ObjectFile::getMachineType(
   return IMAGE_FILE_MACHINE_UNKNOWN;
 }
 
+StringRef ltrim1(StringRef S, const char *Chars) {
+  if (!S.empty() && strchr(Chars, S[0]))
+    return S.substr(1);
+  return S;
+}
+
 std::error_code ImportFile::parse() {
   const char *Buf = MB.getBufferStart();
   const char *End = MB.getBufferEnd();
@@ -273,10 +279,10 @@ std::error_code ImportFile::parse() {
     ExtName = Name;
     break;
   case IMPORT_NAME_NOPREFIX:
-    ExtName = Name.ltrim("?@_");
+    ExtName = ltrim1(Name, "?@_");
     break;
   case IMPORT_NAME_UNDECORATE:
-    ExtName = Name.ltrim("?@_");
+    ExtName = ltrim1(Name, "?@_");
     ExtName = ExtName.substr(0, ExtName.find('@'));
     break;
   }

Modified: lld/trunk/test/COFF/Inputs/imports-mangle.lib
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/imports-mangle.lib?rev=241854&r1=241853&r2=241854&view=diff
==============================================================================
Binary files lld/trunk/test/COFF/Inputs/imports-mangle.lib (original) and lld/trunk/test/COFF/Inputs/imports-mangle.lib Thu Jul  9 15:22:41 2015 differ

Modified: lld/trunk/test/COFF/imports-mangle.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/imports-mangle.test?rev=241854&r1=241853&r2=241854&view=diff
==============================================================================
--- lld/trunk/test/COFF/imports-mangle.test (original)
+++ lld/trunk/test/COFF/imports-mangle.test Thu Jul  9 15:22:41 2015
@@ -5,7 +5,7 @@
 
 # CHECK: Import {
 # CHECK:   Symbol: sym4 (0)
-# CHECK:   Symbol: sym3 (1)
+# CHECK:   Symbol: _sym3 (1)
 # CHECK:   Symbol: sym1 (2)
 # CHECK:   Symbol:  (2)
 # CHECK: }
@@ -51,7 +51,7 @@ symbols:
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
-  - Name:            _sym3
+  - Name:            __sym3
     Value:           0
     SectionNumber:   0
     SimpleType:      IMAGE_SYM_TYPE_NULL





More information about the llvm-commits mailing list